Best Python code snippet using lisa_python
testsolver.py
Source:testsolver.py
...111 self.import_feed(foo.uri, 'MultiArch.xml')112 lib = iface_cache.get_interface('http://foo/MultiArchLib.xml')113 self.import_feed(lib.uri, 'MultiArchLib.xml')114 # On an i686 system we can only use the i486 implementation115 binary_arch = arch.get_architecture('Linux', 'i686')116 s.solve('http://foo/MultiArch.xml', binary_arch)117 assert s.ready118 assert s.selections[foo].machine == 'i486'119 assert s.selections[lib].machine == 'i486'120 # On an 64 bit system we could use either, but we prefer the 64121 # bit implementation. The i486 version of the library is newer,122 # but we must pick one that is compatible with the main binary.123 binary_arch = arch.get_architecture('Linux', 'x86_64')124 s.solve('http://foo/MultiArch.xml', binary_arch)125 assert s.ready126 assert s.selections[foo].machine == 'x86_64'127 assert s.selections[lib].machine == 'x86_64'128 def testArch(self):129 host_arch = arch.get_host_architecture()130 host_arch2 = arch.get_architecture(None, None)131 self.assertEqual(host_arch.os_ranks, host_arch2.os_ranks)132 self.assertEqual(host_arch.machine_ranks, host_arch2.machine_ranks)133 other = arch.get_architecture('FooBar', 'i486')134 self.assertEqual(3, len(other.os_ranks))135 assert 'POSIX' in other.os_ranks136 assert 'FooBar' in other.os_ranks137 assert None in other.os_ranks138 assert 'i486' in other.machine_ranks139 assert 'ppc' not in other.machine_ranks140 win = arch.get_architecture('Windows', 'i486')141 self.assertEqual(2, len(win.os_ranks))142 assert 'POSIX' not in win.os_ranks143 144 def testRanking(self):145 iface_cache = self.config.iface_cache146 s = solver.DefaultSolver(self.config)147 ranking = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'Ranking.xml')148 iface = iface_cache.get_interface(ranking)149 binary_arch = arch.get_architecture('Linux', 'x86_64')150 selected = []151 while True:152 s.solve(ranking, binary_arch)153 if not s.ready:154 break155 impl = s.selections[iface]156 selected.append(impl.get_version() + ' ' + impl.arch)157 impl.arch = 'Foo-odd' # prevent reselection158 self.assertEqual([159 '0.2 Linux-i386', # poor arch, but newest version160 '0.1 Linux-x86_64', # 64-bit is best match for host arch161 '0.1 Linux-i686', '0.1 Linux-i586', '0.1 Linux-i486'], # ordering of x86 versions162 selected)163 def testLangs(self):164 iface_cache = self.config.iface_cache165 try:166 locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')167 s = solver.DefaultSolver(self.config)168 iface = iface_cache.get_interface('http://foo/Langs.xml')169 self.import_feed(iface.uri, 'Langs.xml')170 # 1 is the oldest, but the only one in our language171 binary_arch = arch.get_architecture(None, 'arch_1')172 s.solve('http://foo/Langs.xml', binary_arch)173 assert s.ready174 self.assertEqual('sha1=1', s.selections[iface].id)175 # 6 is the newest, and close enough, even though not176 # quite the right locale177 binary_arch = arch.get_architecture(None, 'arch_2')178 s.solve('http://foo/Langs.xml', binary_arch)179 assert s.ready180 self.assertEqual('sha1=6', s.selections[iface].id)181 # 9 is the newest, although 7 is a closer match182 binary_arch = arch.get_architecture(None, 'arch_3')183 s.solve('http://foo/Langs.xml', binary_arch)184 assert s.ready185 self.assertEqual('sha1=9', s.selections[iface].id)186 # 11 is the newest we understand187 binary_arch = arch.get_architecture(None, 'arch_4')188 s.solve('http://foo/Langs.xml', binary_arch)189 assert s.ready190 self.assertEqual('sha1=11', s.selections[iface].id)191 # 13 is the newest we understand192 binary_arch = arch.get_architecture(None, 'arch_5')193 s.solve('http://foo/Langs.xml', binary_arch)194 assert s.ready195 self.assertEqual('sha1=13', s.selections[iface].id)196 def check(target_arch, langs, expected):197 s.langs = langs198 binary_arch = arch.get_architecture(None, target_arch)199 s.solve('http://foo/Langs.xml', binary_arch)200 assert s.ready201 self.assertEqual(expected, s.selections[iface].id)202 # We don't understand any, so pick the newest203 check('arch_2', ['es_ES'], 'sha1=6')204 # These two have the same version number. Choose the205 # one most appropriate to our country206 check('arch_6', ['zh_CN'], 'sha1=15')207 check('arch_6', ['zh_TW'], 'sha1=16')208 # Same, but one doesn't have a country code209 check('arch_7', ['bn'], 'sha1=17')210 check('arch_7', ['bn_IN'], 'sha1=18')211 finally:212 locale.setlocale(locale.LC_ALL, '')213 def testDecideBug(self):214 s = solver.DefaultSolver(self.config)215 watch_xml = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'watchdog.xml')216 s.solve(watch_xml, arch.get_architecture(None, None), command_name = 'test')217 def testRecommendBug(self):218 s = solver.DefaultSolver(self.config)219 optional_missing_xml = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'OptionalMissing.xml')220 s.solve(optional_missing_xml, arch.get_architecture(None, None), command_name = None)221if __name__ == '__main__':...
unvm.py
Source:unvm.py
...7import platform8import zipfile9root_dir = os.path.join(os.environ['LOCALAPPDATA'], 'unvm')10installed_dir = os.path.join(root_dir, 'installed')11def get_architecture():12 is_arm64 = platform.machine() == 'ARM64' or platform.processor().startswith('ARMv8')13 if is_arm64:14 return 'arm64'15 return 'x64'16def get_source():17 if get_architecture() == 'arm64':18 return 'https://unofficial-builds.nodejs.org'19 return 'https://builds.nodejs.org'20def get_manifest():21 response = requests.get(get_source() + '/download/release/index.json')22 if not response.ok:23 print('Could not load build manifest')24 exit(-1)25 return json.loads(response.content)26def filter_entries(manifest):27 return [item for item in manifest if 'win-' + get_architecture() + '-zip' in item['files']]28def installed():29 if (os.path.exists(installed_dir)):30 return [folder.removeprefix('node-').removesuffix('-win-' + get_architecture()) for folder in os.listdir(installed_dir)]31 return []32def install(version, manifest):33 if version == 'lts':34 version = next(filter(lambda item: item['lts'], manifest))['version']35 target = get_source() + '/download/release/' + version + '/node-' + version + '-win-' + get_architecture() + '.zip'36 file_response = requests.get(target)37 if not file_response.ok:38 print('Failed to download nodejs')39 exit(-1)40 file = io.BytesIO(file_response.content)41 os.makedirs(installed_dir, exist_ok=True)42 with zipfile.ZipFile(file, 'r') as archive:43 archive.extractall(installed_dir)44 os.chdir(root_dir)45 link_path = os.path.join('.', 'node')46 if os.path.exists(link_path):47 print(version + ' installed')48 print('To use:')49 print('unvm --use ' + version)50 else:51 use(version)52def use(version):53 os.chdir(root_dir)54 link_path = os.path.join('.', 'node')55 if os.path.exists(link_path):56 os.unlink(link_path)57 os.symlink(os.path.join('.', 'installed', 'node-' + version + '-win-' + get_architecture()), os.path.join('.', 'node'))58 print('Now using node ' + version)59manifest = filter_entries(get_manifest())60available = ['lts'] + [item['version'] for item in manifest]61parser = argparse.ArgumentParser(description='Manage node installs on Windows')62parser.add_argument('--install', choices=available, help='Install a specific version of node')63parser.add_argument('--available', default=False, action='store_true', help='List available node versions to install')64parser.add_argument('--use', type=str, choices=installed(), help='Switch to an installed node version')65parser.add_argument('--installed', default=False, action='store_true', help='List installed versions of node')66args = parser.parse_args()67if args.available:68 print(available)69if args.installed:70 print(installed())71if args.install:...
test_arch.py
Source:test_arch.py
...14 @patch("apt_pkg.get_architectures")15 def test_get_architecture_from_deb(self, mock_get_architectures):16 arch = random.choice(["i386", "amd64", "arm64", "ppc64el"])17 mock_get_architectures.return_value = [arch, "otherarch"]18 ret_arch = get_architecture()19 self.assertEqual(arch, ret_arch)20 @patch("apt_pkg.get_architectures")21 def test_get_architecture_from_snap_env(self, mock_get_architectures):22 arch = factory.make_name("arch")23 self.patch(os, "environ", {"SNAP_ARCH": arch})24 ret_arch = get_architecture()25 self.assertEqual(arch, ret_arch)...
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!!