Best Python code snippet using autotest_python
test_packages.py
Source:test_packages.py
...822 with PackageFetcher([]) as fetcher:823 tempdir = fetcher.cache.tempdir824 self.assertTrue(os.path.isdir(tempdir))825 self.assertFalse(os.path.exists(tempdir))826 def get_fetcher(self, sources, architecture=None, prefer_label=None):827 fetcher = PackageFetcher(828 [s.sources_entry for s in sources], architecture=architecture,829 prefer_label=prefer_label)830 self.addCleanup(fetcher.cleanup)831 fetcher.prepare()832 return fetcher833 def test_fetch_packages_not_found_because_no_sources(self):834 fetcher = self.get_fetcher([])835 self.assertRaises(KeyError, fetcher.fetch_packages, ["nothere"])836 def test_fetch_packages_not_found_because_not_in_sources(self):837 available_package = DummyFetchedPackage("foo", "1.0")838 source = self.useFixture(AptSourceFixture([available_package]))839 fetcher = self.get_fetcher([source])840 self.assertRaises(KeyError, fetcher.fetch_packages, ["nothere"])841 def test_fetch_packages_not_found_one_of_two_missing(self):842 available_package = DummyFetchedPackage("foo", "1.0")843 source = self.useFixture(AptSourceFixture([available_package]))844 fetcher = self.get_fetcher([source])845 self.assertRaises(846 KeyError, fetcher.fetch_packages, ["foo", "nothere"])847 def test_fetch_packages_fetches_no_packages(self):848 available_package = DummyFetchedPackage("foo", "1.0")849 source = self.useFixture(AptSourceFixture([available_package]))850 fetcher = self.get_fetcher([source])851 self.assertEqual(0, len(fetcher.fetch_packages([])))852 def test_fetch_packages_fetches_single_package(self):853 available_package = DummyFetchedPackage("foo", "1.0")854 source = self.useFixture(AptSourceFixture([available_package]))855 fetcher = self.get_fetcher([source])856 self.assertEqual(1, len(fetcher.fetch_packages(["foo"])))857 def test_fetch_packages_fetches_correct_package(self):858 available_package = DummyFetchedPackage("foo", "1.0")859 source = self.useFixture(AptSourceFixture([available_package]))860 fetcher = self.get_fetcher([source])861 self.assertEqual(862 available_package, fetcher.fetch_packages(["foo"])[0])863 def test_fetch_packages_fetches_preferred_label(self):864 lower_package = DummyFetchedPackage("foo", "1.0")865 higher_package = DummyFetchedPackage("foo", "2.0")866 label_text = 'random-label'867 source1 = self.useFixture(AptSourceFixture([higher_package]))868 source2 = self.useFixture(869 AptSourceFixture([lower_package], label=label_text))870 fetcher = self.get_fetcher(871 [source1, source2], prefer_label=label_text)872 self.assertEqual(873 lower_package, fetcher.fetch_packages(["foo"])[0])874 def test_fetch_packages_fetches_multiple_packages(self):875 available_packages = [876 DummyFetchedPackage("bar", "1.0"),877 DummyFetchedPackage("foo", "1.0"),878 ]879 source = self.useFixture(AptSourceFixture(available_packages))880 fetcher = self.get_fetcher([source])881 self.assertEqual(2, len(fetcher.fetch_packages(["foo", "bar"])))882 def test_fetch_packages_fetches_multiple_packages_correctly(self):883 available_packages = [884 DummyFetchedPackage("foo", "1.0"),885 DummyFetchedPackage("bar", "1.0"),886 ]887 source = self.useFixture(AptSourceFixture(available_packages))888 fetcher = self.get_fetcher([source])889 fetched = fetcher.fetch_packages(["foo", "bar"])890 self.assertEqual(available_packages[0], fetched[0])891 self.assertEqual(available_packages[1], fetched[1])892 def test_fetch_packages_fetches_newest(self):893 available_packages = [894 DummyFetchedPackage("bar", "1.0"),895 DummyFetchedPackage("bar", "1.1"),896 ]897 source = self.useFixture(AptSourceFixture(available_packages))898 fetcher = self.get_fetcher([source])899 fetched = fetcher.fetch_packages(["bar"])900 self.assertEqual(available_packages[1], fetched[0])901 def test_fetch_packages_fetches_newest_from_multiple_sources(self):902 old_source_packages = [DummyFetchedPackage("bar", "1.0")]903 new_source_packages = [DummyFetchedPackage("bar", "1.1")]904 old_source = self.useFixture(AptSourceFixture(old_source_packages))905 new_source = self.useFixture(AptSourceFixture(new_source_packages))906 fetcher = self.get_fetcher([old_source, new_source])907 fetched = fetcher.fetch_packages(["bar"])908 self.assertEqual(new_source_packages[0], fetched[0])909 def test_fetch_packages_records_correct_architecture(self):910 available_package = DummyFetchedPackage(911 "foo", "1.0", architecture="nonexistant")912 source = self.useFixture(AptSourceFixture([available_package]))913 fetcher = self.get_fetcher([source], architecture="nonexistant")914 self.assertEqual(915 "nonexistant", fetcher.fetch_packages(["foo"])[0].architecture)916 def test_fetch_packages_fetches_from_correct_architecture(self):917 wanted_package = DummyFetchedPackage(918 "foo", "1.0", architecture="arch1")919 unwanted_package = DummyFetchedPackage(920 "foo", "1.1", architecture="arch2")921 source = self.useFixture(922 AptSourceFixture([wanted_package, unwanted_package]))923 fetcher = self.get_fetcher([source], architecture="arch1")924 self.assertEqual(925 wanted_package, fetcher.fetch_packages(["foo"])[0])926 def test_fetch_packages_fetches_with_relationships(self):927 depends = "foo"928 pre_depends = "bar (>= 1.0)"929 conflicts = "baz | zap"930 recommends = "zing, zang"931 dependency_packages = [932 DummyFetchedPackage("foo", "1.0"),933 DummyFetchedPackage("bar", "1.0"),934 DummyFetchedPackage("baz", "1.0"),935 DummyFetchedPackage("zap", "1.0"),936 DummyFetchedPackage("zing", "1.0"),937 DummyFetchedPackage("zang", "1.0"),938 ]939 wanted_package = DummyFetchedPackage(940 "top", "1.0", depends=depends, pre_depends=pre_depends,941 conflicts=conflicts, recommends=recommends)942 source = self.useFixture(943 AptSourceFixture([wanted_package] + dependency_packages))944 fetcher = self.get_fetcher([source])945 self.assertIn(946 wanted_package, fetcher.fetch_packages(["top"]))947 def test_fetch_packages_download_content_False_doesnt_set_content(self):948 available_package = DummyFetchedPackage("foo", "1.0")949 source = self.useFixture(AptSourceFixture([available_package]))950 fetcher = self.get_fetcher([source])951 fetched_package = fetcher.fetch_packages(952 ["foo"], download_content=False)[0]953 self.assertIs(None, fetched_package.content)954 def test_fetches_dependencies(self):955 wanted_package1 = DummyFetchedPackage("foo", "1.0", depends="bar")956 wanted_package2 = DummyFetchedPackage("bar", "1.0")957 source = self.useFixture(958 AptSourceFixture([wanted_package1, wanted_package2]))959 fetcher = self.get_fetcher([source])960 self.assertEqual(961 [wanted_package1, wanted_package2],962 fetcher.fetch_packages(["foo"]))963 def test_fetches_recommends(self):964 wanted_package1 = DummyFetchedPackage("foo", "1.0", recommends="bar")965 wanted_package2 = DummyFetchedPackage("bar", "1.0")966 source = self.useFixture(967 AptSourceFixture([wanted_package1, wanted_package2]))968 fetcher = self.get_fetcher([source])969 self.assertEqual(970 [wanted_package1, wanted_package2],971 fetcher.fetch_packages(["foo"]))972 def test_broken_dependencies(self):973 wanted_package = DummyFetchedPackage("foo", "1.0", depends="bar")974 source = self.useFixture(AptSourceFixture([wanted_package]))975 fetcher = self.get_fetcher([source])976 e = self.assertRaises(977 DependencyNotSatisfied, fetcher.fetch_packages, ["foo"])978 self.assertEqual(979 "Unable to satisfy dependencies of foo", str(e))980 def test_fetch_packages_leaves_no_marked_changes(self):981 wanted_package = DummyFetchedPackage("foo", "1.0")982 source = self.useFixture(AptSourceFixture([wanted_package]))983 fetcher = self.get_fetcher([source])984 fetcher.fetch_packages(["foo"])985 self.assertEqual([], list(fetcher.cache.cache.get_changes()))986 def test_fetch_packages_without_content_leaves_no_marked_changes(self):987 wanted_package = DummyFetchedPackage("foo", "1.0")988 source = self.useFixture(AptSourceFixture([wanted_package]))989 fetcher = self.get_fetcher([source])990 fetcher.fetch_packages(["foo"], download_content=False)991 self.assertEqual([], list(fetcher.cache.cache.get_changes()))992 def test_fetch_packages_can_remove_package(self):993 """Check that removed packages aren't included in the hwpack994 When installing the hwpack would cause an "assume-installed" package995 to be removed the hwpack shouldn't contain that package.996 """997 wanted_package = DummyFetchedPackage(998 "foo", "1.0", conflicts="provided", provides="provided",999 depends="zoo", replaces="provided")1000 top_package = DummyFetchedPackage(1001 "top", "1.0", recommends="bar, baz")1002 dep_package = DummyFetchedPackage(1003 "bar", "1.0", depends="baz")1004 conflict_package = DummyFetchedPackage(1005 "baz", "1.0", recommends="bar", provides="provided",1006 conflicts="provided", replaces="provided")1007 extra_package = DummyFetchedPackage("zoo", "1.0")1008 source = self.useFixture(AptSourceFixture(1009 [wanted_package, dep_package, conflict_package, extra_package,1010 top_package]))1011 fetcher = self.get_fetcher([source])1012 fetcher.ignore_packages(["top"])1013 fetched = fetcher.fetch_packages(["foo"])1014 self.assertEqual([wanted_package, extra_package], fetched)1015 def test_ignore_with_provides(self):1016 ignored_package = DummyFetchedPackage(1017 "ubuntu-minimal", "1.0", depends="apt-utils")1018 middle_package = DummyFetchedPackage(1019 "apt-utils", "1.0", depends="libapt-pkg")1020 provides_package = DummyFetchedPackage(1021 "apt", "1.0", provides="libapt-pkg", replaces="someotherpackage")1022 source = self.useFixture(1023 AptSourceFixture(1024 [ignored_package, middle_package, provides_package]))1025 fetcher = self.get_fetcher([source])1026 fetcher.ignore_packages(["ubuntu-minimal"])1027 def test_download_content_False_fetches_no_dependencies(self):1028 wanted_package1 = DummyFetchedPackage("foo", "1.0", depends="bar")1029 wanted_package2 = DummyFetchedPackage("bar", "1.0")1030 source = self.useFixture(1031 AptSourceFixture([wanted_package1, wanted_package2]))1032 fetcher = self.get_fetcher([source])1033 self.assertEqual(1034 1, len(fetcher.fetch_packages(["foo"], download_content=False)))1035 def test_ignore_packages(self):1036 wanted_package = DummyFetchedPackage("foo", "1.0", depends="bar")1037 ignored_package = DummyFetchedPackage("bar", "1.0")1038 source = self.useFixture(1039 AptSourceFixture([wanted_package, ignored_package]))1040 fetcher = self.get_fetcher([source])1041 fetcher.ignore_packages(["bar"])1042 self.assertEqual(1043 [wanted_package], fetcher.fetch_packages(["foo"]))1044 def test_ignore_dependency_of_ignored(self):1045 wanted_package = DummyFetchedPackage("foo", "1.0", depends="baz")1046 ignored_package = DummyFetchedPackage("bar", "1.0", depends="baz")1047 dependency = DummyFetchedPackage("baz", "1.0")1048 source = self.useFixture(1049 AptSourceFixture([wanted_package, ignored_package, dependency]))1050 fetcher = self.get_fetcher([source])1051 fetcher.ignore_packages(["bar"])1052 self.assertEqual(1053 [wanted_package], fetcher.fetch_packages(["foo"]))1054 def test_ignore_unknown_package(self):1055 source = self.useFixture(AptSourceFixture([]))1056 fetcher = self.get_fetcher([source])1057 self.assertRaises(KeyError, fetcher.ignore_packages, ["unknown"])1058 def test_ignore_cant_satisfy_depenencies(self):1059 wanted_package = DummyFetchedPackage("foo", "1.0", depends="bar")1060 source = self.useFixture(AptSourceFixture([wanted_package]))1061 fetcher = self.get_fetcher([source])1062 e = self.assertRaises(1063 DependencyNotSatisfied, fetcher.ignore_packages, ["foo"])1064 self.assertEqual(1065 "Unable to satisfy dependencies of foo", str(e))1066 def test_ignored_arent_fetched_even_if_explicitly_requested(self):1067 wanted_package = DummyFetchedPackage("foo", "1.0")1068 source = self.useFixture(1069 AptSourceFixture([wanted_package]))1070 fetcher = self.get_fetcher([source])1071 fetcher.ignore_packages(["foo"])1072 self.assertEqual(1073 [], fetcher.fetch_packages(["foo"]))1074 def test_no_metadata_for_ignored_even_if_explicitly_requested(self):1075 wanted_package = DummyFetchedPackage("foo", "1.0")1076 source = self.useFixture(1077 AptSourceFixture([wanted_package]))1078 fetcher = self.get_fetcher([source])1079 fetcher.ignore_packages(["foo"])1080 self.assertEqual(1081 [], fetcher.fetch_packages(["foo"], download_content=False))1082 def test_ignore_is_cumulative(self):1083 package1 = DummyFetchedPackage("foo", "1.0")1084 package2 = DummyFetchedPackage("bar", "1.0")1085 source = self.useFixture(1086 AptSourceFixture([package1, package2]))1087 fetcher = self.get_fetcher([source])1088 fetcher.ignore_packages(["foo"])1089 fetcher.ignore_packages(["bar"])1090 self.assertEqual(1091 [],1092 fetcher.fetch_packages(["foo", "bar"], download_content=False))1093 def test_ignore_leaves_no_marked_changes(self):1094 package1 = DummyFetchedPackage("foo", "1.0")1095 source = self.useFixture(AptSourceFixture([package1]))1096 fetcher = self.get_fetcher([source])1097 fetcher.ignore_packages(["foo"])1098 self.assertEqual(1099 [],...
Migrator.py
Source:Migrator.py
...8 config = None9 fetcher = None10 def __init__(self, config):11 self.config = config12 self.get_fetcher()13 def fetch_data(self, endpoint):14 response = self.get_fetcher().fetch('_'.join((endpoint, self.get_fetcher().list_action)))15 return response16 def get_fetcher(self):17 if self.fetcher is None:18 self.fetcher = Fetcher.Fetcher(self.config)19 return self.fetcher20 def migrate(self):21 migration_dir = self.migration_dir_prefix+"_"+datetime.datetime.now().strftime("%Y-%m-%d")22 if os.path.exists(migration_dir) is False:23 os.mkdir(migration_dir)24 for datatype in self.get_fetcher().datatypes:25 # maybe write handler for unfinished migrations..26 f = self.init_file(migration_dir+"/"+datatype+"_"+self.fetcher.list_action)27 f.write(json.dumps(self.get_fetcher().get_request('_'.join((datatype, self.get_fetcher().list_action)))))28 f.close()29 mapper = getattr(mappers, self.fetcher.datatypes[datatype]['class'])(self.config, datatype)30 mapper.set_migration_dir(migration_dir)31 mapper.set_endpoint(datatype)32 mapper.process_data(self.get_fetcher().list_action)33 def init_file(self, path):34 if os.path.exists(path):35 os.remove(path)36 f = open(path, "w")...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!