Best Python code snippet using avocado_python
test_package.py
Source:test_package.py
...138 self.assertIsNotNone(check_atom_obj_for_keywording(139 get_atom_obj_from_str('dev-libs/libffi:=')))140 self.assertIsNotNone(check_atom_obj_for_keywording(141 get_atom_obj_from_str('media-sound/sox[ogg]')))142 def test_get_best_version(self):143 """144 Test if the 'get_best_version' function returns a matching version for145 atoms that have a match in the specified ebuild repository and 'None'146 otherwise.147 """148 _, empty = nattka.package.find_repository(149 Path('tests/ebuild-repos/empty'))150 _, single_pkg_multi_vers = nattka.package.find_repository(151 Path('tests/ebuild-repos/single-pkg-multi-vers'))152 self.assertIsNone(get_best_version(153 get_atom_obj_from_str('foo-bar/baz'), empty))154 self.assertIsNone(get_best_version(155 get_atom_obj_from_str('foo-bar/qux'), empty))156 self.assertIsNone(get_best_version(157 get_atom_obj_from_str('foo-bar/qux'), single_pkg_multi_vers))158 self.assertIsNone(get_best_version(159 get_atom_obj_from_str('>=foo-bar/baz-1.1'), single_pkg_multi_vers))160 self.assertIsNone(get_best_version(161 get_atom_obj_from_str('foo-bar/baz:2'), single_pkg_multi_vers))162 self.assertEqual('1.0.3', get_best_version(163 get_atom_obj_from_str('foo-bar/baz'), single_pkg_multi_vers164 ).version)165 self.assertEqual('1.0.2', get_best_version(166 get_atom_obj_from_str('=foo-bar/baz-1.0.2'), single_pkg_multi_vers167 ).version)168 def test_get_best_version_pkg_filter(self):169 """170 Test if the 'get_best_version' function respects any specified package171 filter.172 """173 _, single_pkg_multi_vers = nattka.package.find_repository(174 Path('tests/ebuild-repos/single-pkg-multi-vers'))175 self.assertEqual('1.0.2', get_best_version(176 get_atom_obj_from_str('foo-bar/baz'), single_pkg_multi_vers,177 lambda ps: filter(lambda p: p.version == '1.0.2', ps)178 ).version)179 self.assertIsNone(get_best_version(180 get_atom_obj_from_str('>foo-bar/baz-1.0.2'), single_pkg_multi_vers,181 lambda ps: filter(lambda p: p.version == '1.0.2', ps)))182 def test_get_packages_to_process(self):183 """184 Run a basic test for the 'get_packages_to_process' function.185 """186 _, etr_simplified = nattka.package.find_repository(187 Path('tests/ebuild-repos/etr-simplified'))188 etr = get_best_version(189 get_atom_obj_from_str('games-action/extreme-tuxracer'),190 etr_simplified191 )192 etr_pkgs = get_packages_to_process(etr, '~riscv', etr_simplified)193 self.assertEqual(2, len(etr_pkgs))194 etr_pkgs_strs = [pkg.cpvstr for pkg in etr_pkgs]195 self.assertTrue(196 'games-action/extreme-tuxracer-0.8.1_p1' in etr_pkgs_strs)197 self.assertTrue('media-sound/modplugtools-0.5.3' in etr_pkgs_strs)198 def test_get_packages_to_process_pkg_filter(self):199 """200 Test if the 'get_packages_to_process' function respects version201 preference specified with the 'pkg_filter' parameter.202 """203 _, java = nattka.package.find_repository(204 Path('tests/ebuild-repos/java'))205 ant_core = get_best_version(206 get_atom_obj_from_str('dev-java/ant-core'), java)207 target_keyword = '~riscv'208 ant_core_pkgs = get_packages_to_process(209 ant_core, target_keyword, java,210 lambda pkgs: filter(211 lambda pkg:212 target_keyword in pkg.keywords or 'amd64' in pkg.keywords,213 pkgs)214 )215 self.assertEqual(4, len(ant_core_pkgs))216 ant_core_pkgs_strs = [pkg.cpvstr for pkg in ant_core_pkgs]217 self.assertTrue('dev-java/ant-core-1.10.9-r3' in ant_core_pkgs_strs)218 self.assertTrue('virtual/jdk-11-r2' in ant_core_pkgs_strs)219 self.assertTrue('dev-java/openjdk-bin-11.0.14_p9-r1'220 in ant_core_pkgs_strs)221 self.assertTrue('sec-policy/selinux-java-2.20210908-r1'222 in ant_core_pkgs_strs)223 def test_get_packages_to_process_profile(self):224 """225 Test if the 'get_packages_to_process' function respects USE flag226 restrictions in the profile specified with the 'profile' parameter.227 """228 java_path = 'tests/ebuild-repos/java'229 _, java = nattka.package.find_repository(Path(java_path))230 ant_core = get_best_version(231 get_atom_obj_from_str('dev-java/ant-core'), java)232 # This profile masks the 'selinux' USE flag, so no SELinux-related233 # dependency should be included in the result234 profile = OnDiskProfile(os.path.join(java_path, 'profiles'), 'base')235 target_keyword = '~riscv'236 ant_core_pkgs = get_packages_to_process(237 ant_core, target_keyword, java,238 lambda pkgs: filter(239 lambda pkg:240 target_keyword in pkg.keywords or 'amd64' in pkg.keywords,241 pkgs),242 profile243 )244 self.assertEqual(3, len(ant_core_pkgs))245 ant_core_pkgs_strs = [pkg.cpvstr for pkg in ant_core_pkgs]246 self.assertTrue('dev-java/ant-core-1.10.9-r3' in ant_core_pkgs_strs)247 self.assertTrue('virtual/jdk-11-r2' in ant_core_pkgs_strs)248 self.assertTrue('dev-java/openjdk-bin-11.0.14_p9-r1'249 in ant_core_pkgs_strs)250 def test_get_packages_to_process_profile_stable(self):251 """252 Test if the 'get_packages_to_process' function respects USE flag253 restrictions exclusively for stable packages in the profile specified254 with the 'profile' parameter when a package is stabilized.255 """256 use_restrictions_path = 'tests/ebuild-repos/use-restrictions'257 _, use_restrictions = nattka.package.find_repository(258 Path(use_restrictions_path))259 restricted = get_best_version(260 get_atom_obj_from_str('=app-misc/restricted-1.0.1'),261 use_restrictions262 )263 profile = OnDiskProfile(264 os.path.join(use_restrictions_path, 'profiles'), 'default')265 target_keyword = 'x86'266 restricted_pkgs = get_packages_to_process(267 restricted, target_keyword, use_restrictions, None, profile)268 self.assertEqual(6, len(restricted_pkgs))269 restricted_pkgs_strs = [pkg.cpvstr for pkg in restricted_pkgs]270 # Neither dev-libs/stable-mask nor dev-libs/pkg-stable-mask is expected271 self.assertTrue('app-misc/restricted-1.0.1' in restricted_pkgs_strs)272 self.assertTrue('dev-libs/force-0' in restricted_pkgs_strs)273 self.assertTrue('dev-libs/normal-0' in restricted_pkgs_strs)274 self.assertTrue('dev-libs/pkg-force-0' in restricted_pkgs_strs)275 self.assertTrue('dev-libs/pkg-stable-force-0' in restricted_pkgs_strs)276 self.assertTrue('dev-libs/stable-force-0' in restricted_pkgs_strs)277 def test_get_packages_to_process_ignores_blocker(self):278 """279 Test if the 'get_packages_to_process' function does not return280 dependencies specified as a block.281 """282 _, etr_simplified = nattka.package.find_repository(283 Path('tests/ebuild-repos/etr-simplified'))284 pkgconf = get_best_version(285 get_atom_obj_from_str('dev-util/pkgconf'), etr_simplified)286 pkgconf_pkgs = get_packages_to_process(287 pkgconf, 'riscv', etr_simplified)288 self.assertEqual(1, len(pkgconf_pkgs))289 pkgconf_pkgs_strs = [pkg.cpvstr for pkg in pkgconf_pkgs]290 self.assertTrue('dev-util/pkgconf-1.8.0-r1' in pkgconf_pkgs_strs)291 def test_get_packages_to_process_treats_stable_as_keyworded(self):292 """293 Test if the 'get_packages_to_process' function does not add a294 dependency that has already been stabilized in a keywording process.295 There is no need to keyword a stable package; stable packages should296 obviously be considered keyworded.297 """298 _, java = nattka.package.find_repository(299 Path('tests/ebuild-repos/java'))300 c3p0 = get_best_version(get_atom_obj_from_str('dev-java/c3p0'), java)301 c3p0_pkgs = get_packages_to_process(302 c3p0, '~arm64', java,303 lambda pkgs: filter(lambda pkg: 'arm64' in pkg.keywords, pkgs))304 self.assertEqual(1, len(c3p0_pkgs))305 c3p0_pkgs_strs = [pkg.cpvstr for pkg in c3p0_pkgs]306 self.assertTrue('dev-java/c3p0-0.9.5.5-r1' in c3p0_pkgs_strs)307 def test_get_keyword_matching_pkg_filter(self):308 """309 Test if the filter returned by the 'get_keyword_matching_pkg_filter'310 function filters out packages that are not visible on any specified311 keyword in the arguments.312 """313 _, java = nattka.package.find_repository(314 Path('tests/ebuild-repos/java'))315 pkg_filter_uriscv = get_keyword_matching_pkg_filter(316 '~riscv')317 pkg_filter_uriscv_uamd64 = get_keyword_matching_pkg_filter(318 '~riscv', '~amd64')319 pkg_filter_uriscv_amd64 = get_keyword_matching_pkg_filter(320 '~riscv', 'amd64')321 pkg_filter_uamd64 = get_keyword_matching_pkg_filter(322 '~amd64')323 pkg_filter_uamd64_amd64 = get_keyword_matching_pkg_filter(324 '~amd64', 'amd64')325 pkg_filter_amd64 = get_keyword_matching_pkg_filter(326 'amd64')327 musl_atom = get_atom_obj_from_str('sys-libs/musl')328 jdk_atom = get_atom_obj_from_str('virtual/jdk')329 glibc_atom = get_atom_obj_from_str('sys-libs/glibc')330 self.assertEqual('1.2.2-r8', get_best_version(331 musl_atom, java, pkg_filter_uriscv).PVR)332 self.assertEqual('1.2.2-r8', get_best_version(333 musl_atom, java, pkg_filter_uriscv_uamd64).PVR)334 self.assertEqual('1.2.2-r8', get_best_version(335 musl_atom, java, pkg_filter_uriscv_amd64).PVR)336 self.assertIsNone(get_best_version(337 jdk_atom, java, pkg_filter_uriscv))338 self.assertEqual('17', get_best_version(339 jdk_atom, java, pkg_filter_uriscv_uamd64).PVR)340 self.assertEqual('11-r2', get_best_version(341 jdk_atom, java, pkg_filter_uriscv_amd64).PVR)342 self.assertEqual('2.34-r10', get_best_version(343 glibc_atom, java, pkg_filter_uamd64).PVR)344 self.assertEqual('2.34-r10', get_best_version(345 glibc_atom, java, pkg_filter_uamd64_amd64).PVR)346 self.assertEqual('2.33-r13', get_best_version(347 glibc_atom, java, pkg_filter_amd64).PVR)348 def test_get_keyword_matching_pkg_filter_unstable_older_than_stable(self):349 """350 Test if the filter returned by the 'get_keyword_matching_pkg_filter'351 function returns the latest stable version of a package when the352 package has an older unstable version.353 """354 _, java = nattka.package.find_repository(355 Path('tests/ebuild-repos/java'))356 pkg_filter_uriscv_uarm64 = get_keyword_matching_pkg_filter(357 '~riscv', '~arm64')358 pkg_filter_uriscv_arm64 = get_keyword_matching_pkg_filter(359 '~riscv', 'arm64')360 pkg_filter_arm_uarm64 = get_keyword_matching_pkg_filter(361 'arm', '~arm64')362 pkg_filter_arm_arm64 = get_keyword_matching_pkg_filter(363 'arm', 'arm64')364 antlr4_atom = get_atom_obj_from_str('dev-java/antlr:4')365 self.assertEqual('4.9.3', get_best_version(366 antlr4_atom, java, pkg_filter_uriscv_uarm64).PVR)367 self.assertEqual('4.9.3', get_best_version(368 antlr4_atom, java, pkg_filter_uriscv_arm64).PVR)369 self.assertEqual('4.9.3', get_best_version(370 antlr4_atom, java, pkg_filter_arm_uarm64).PVR)371 self.assertEqual('4.9.3', get_best_version(372 antlr4_atom, java, pkg_filter_arm_arm64).PVR)373if __name__ == '__main__':...
test_list.py
Source:test_list.py
...44 self.assertFalse(os.path.sep in file_name)45 # Cannot be a hidden file46 self.assertFalse(file_name.startswith('.'))47 packages = list()48 packages.append(get_best_version(49 get_atom_obj_from_str('dev-java/c3p0'), self.java))50 packages.append(get_best_version(51 get_atom_obj_from_str('virtual/jdk:11'), self.java))52 packages.append(get_best_version(53 get_atom_obj_from_str('=dev-java/antlr-4.9.3'), self.java))54 packages.append(get_best_version(55 get_atom_obj_from_str('>=sys-libs/glibc-2.35'), self.java))56 for main_package in packages:57 result = get_package_list_file_name_from_package(main_package)58 check_spec(result)59 def test_generate_package_lists_empty_packages(self):60 """61 Test the 'generate_package_lists' function when no packages are62 specified for keywording or stabilization.63 """64 keyword_dict = get_package_lists(self.java, [], self.profile, '~amd64')65 stable_dict = get_package_lists(self.java, [], self.profile, 'amd64')66 self.assertEqual(0, len(keyword_dict))67 self.assertEqual(0, len(stable_dict))68 def test_generate_package_lists_simple_keyword(self):69 """70 Test the 'generate_package_lists' function for a simple keywording71 task involving only a single package.72 """73 openjdk_bin11 = get_best_version(74 get_atom_obj_from_str('dev-java/openjdk-bin:11'), self.java)75 pkg_to_list_dict = get_package_lists(76 self.java, [openjdk_bin11], self.profile, '~riscv')77 self.assertEqual(1, len(pkg_to_list_dict))78 openjdk_bin11_pkgs = pkg_to_list_dict[openjdk_bin11]79 self.assertEqual(1, len(openjdk_bin11_pkgs))80 self.assertEqual(openjdk_bin11, openjdk_bin11_pkgs[0])81 def test_generate_package_lists_simple_stable(self):82 """83 Test the 'generate_package_lists' function for a simple stabilization84 task involving only a single package.85 """86 musl = get_best_version(87 get_atom_obj_from_str('sys-libs/musl'), self.java)88 pkg_to_list_dict = get_package_lists(89 self.java, [musl], self.profile, 'amd64')90 self.assertEqual(1, len(pkg_to_list_dict))91 musl_pkgs = pkg_to_list_dict[musl]92 self.assertEqual(1, len(musl_pkgs))93 self.assertEqual(musl, musl_pkgs[0])94 def test_generate_package_lists_multiple_stable(self):95 """96 Test the 'generate_package_lists' function for a stabilization task97 involving multiple packages.98 """99 ant_core = get_best_version(100 get_atom_obj_from_str('dev-java/ant-core'), self.java)101 c3p0 = get_best_version(102 get_atom_obj_from_str('dev-java/c3p0'), self.java)103 pkg_to_list_dict = get_package_lists(104 self.java, [ant_core, c3p0], self.profile, 'amd64')105 self.assertEqual(2, len(pkg_to_list_dict))106 ant_core_pkgs = pkg_to_list_dict[ant_core]107 self.assertEqual(1, len(ant_core_pkgs))108 self.assertEqual(ant_core, ant_core_pkgs[0])109 c3p0_pkgs = pkg_to_list_dict[c3p0]110 self.assertEqual(1, len(c3p0_pkgs))...
updates.py
Source:updates.py
...34 The atom to search for35 Return the installed version.36 '''37 return portage.db['/']['vartree'].dbapi.match(atom)38def get_best_version(atom):39 '''40 Get the best available version accounting for keywords and masking.41 atom42 The atom to search for43 Return the best availalbe version.44 '''45 available = portage.db['/']['porttree'].dbapi.match(atom)46 return portage.best(available)47def main():48 '''49 Main func.50 '''51 updatable = set()52 for atom in get_world_entries():53 if get_best_version(atom) not in get_installed_versions(atom):54 updatable.add(atom)55 if '-v' in sys.argv:56 for atom in updatable:57 print('{0}'.format(atom))58 num_updates = len(updatable)59 if num_updates > 0:60 print('{0}'.format(len(updatable)))61if __name__ == "__main__":...
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!!