Best Python code snippet using lisa_python
install-build-deps.py
Source:install-build-deps.py
...220 'xvfb',221)222def is_userland_64_bit():223 return platform.architecture()[0] == '64bit'224def package_exists(pkg):225 return pkg in subprocess.check_output(['apt-cache', 'pkgnames']).splitlines()226def lsb_release_short_codename():227 return subprocess.check_output(228 ['lsb_release', '--codename', '--short']).strip()229def write_error(message):230 sys.stderr.write('ERROR: %s\n' % message)231 sys.stderr.flush()232def nonfatal_get_output(*popenargs, **kwargs):233 process = subprocess.Popen(234 stdout=subprocess.PIPE, stderr=subprocess.PIPE, *popenargs, **kwargs)235 stdout, stderr = process.communicate()236 retcode = process.poll()237 return retcode, stdout, stderr238def compute_dynamic_package_lists():239 global _packages_arm240 global _packages_dbg241 global _packages_dev242 global _packages_lib243 global _packages_lib32244 global _packages_nacl245 if is_userland_64_bit():246 # 64-bit systems need a minimum set of 32-bit compat packages247 # for the pre-built NaCl binaries.248 _packages_dev += (249 'lib32gcc1',250 'lib32stdc++6',251 'libc6-i386',252 )253 # When cross building for arm/Android on 64-bit systems the host binaries254 # that are part of v8 need to be compiled with -m32 which means255 # that basic multilib support is needed.256 # gcc-multilib conflicts with the arm cross compiler (at least in trusty)257 # but g++-X.Y-multilib gives us the 32-bit support that we need. Find out258 # the appropriate value of X and Y by seeing what version the current259 # distribution's g++-multilib package depends on.260 output = subprocess.check_output(['apt-cache', 'depends', 'g++-multilib'])261 multilib_package = re.search(r'g\+\+-[0-9.]+-multilib', output).group()262 _packages_lib32 += (multilib_package,)263 lsb_codename = lsb_release_short_codename()264 # Find the proper version of libstdc++6-4.x-dbg.265 if lsb_codename == 'precise':266 _packages_dbg += ('libstdc++6-4.6-dbg',)267 elif lsb_codename == 'trusty':268 _packages_dbg += ('libstdc++6-4.8-dbg',)269 else:270 _packages_dbg += ('libstdc++6-4.9-dbg',)271 # Work around for dependency issue Ubuntu/Trusty: http://crbug.com/435056 .272 if lsb_codename == 'trusty':273 _packages_arm += (274 'g++-4.8-multilib-arm-linux-gnueabihf',275 'gcc-4.8-multilib-arm-linux-gnueabihf',276 )277 # Find the proper version of libgbm-dev. We can't just install libgbm-dev as278 # it depends on mesa, and only one version of mesa can exists on the system.279 # Hence we must match the same version or this entire script will fail.280 mesa_variant = ''281 for variant in ('-lts-trusty', '-lts-utopic'):282 rc, stdout, stderr = nonfatal_get_output(283 ['dpkg-query', '-Wf\'{Status}\'', 'libgl1-mesa-glx' + variant])284 if 'ok installed' in output:285 mesa_variant = variant286 _packages_dev += (287 'libgbm-dev' + mesa_variant,288 'libgl1-mesa-dev' + mesa_variant,289 'libgles2-mesa-dev' + mesa_variant,290 'mesa-common-dev' + mesa_variant,291 )292 if package_exists('ttf-mscorefonts-installer'):293 _packages_dev += ('ttf-mscorefonts-installer',)294 else:295 _packages_dev += ('msttcorefonts',)296 if package_exists('libnspr4-dbg'):297 _packages_dbg += ('libnspr4-dbg', 'libnss3-dbg')298 _packages_lib += ('libnspr4', 'libnss3')299 else:300 _packages_dbg += ('libnspr4-0d-dbg', 'libnss3-1d-dbg')301 _packages_lib += ('libnspr4-0d', 'libnss3-1d')302 if package_exists('libjpeg-dev'):303 _packages_dev += ('libjpeg-dev',)304 else:305 _packages_dev += ('libjpeg62-dev',)306 if package_exists('libudev1'):307 _packages_dev += ('libudev1',)308 _packages_nacl += ('libudev1:i386',)309 else:310 _packages_dev += ('libudev0',)311 _packages_nacl += ('libudev0:i386',)312 if package_exists('libbrlapi0.6'):313 _packages_dev += ('libbrlapi0.6',)314 else:315 _packages_dev += ('libbrlapi0.5',)316 if package_exists('apache2-bin'):317 _packages_dev += ('apache2-bin',)318 else:319 _packages_dev += ('apache2.2-bin',)320 if package_exists('xfonts-mathml'):321 _packages_dev += ('xfonts-mathml',)322 # Some packages are only needed if the distribution actually supports323 # installing them.324 if package_exists('appmenu-gtk'):325 _packages_lib += ('appmenu-gtk',)326 _packages_dev += _packages_chromeos_dev327 _packages_lib += _packages_chromeos_lib328 _packages_nacl += _packages_naclports329def quick_check(packages):330 rc, stdout, stderr = nonfatal_get_output([331 'dpkg-query', '-W', '-f', '${PackageSpec}:${Status}\n'] + list(packages))332 if rc == 0 and not stderr:333 return 0334 print stderr335 return 1336def main(argv):337 parser = argparse.ArgumentParser()338 parser.add_argument('--quick-check', action='store_true',...
schema.py
Source:schema.py
1from ckan.plugins import toolkit2from ckanext.issues.logic.validators import (3 as_package_id,4 as_org_id,5 is_valid_sort,6 is_valid_status,7 is_valid_abuse_status,8 issue_exists,9 issue_comment_exists,10 issue_number_exists_for_dataset,11)12not_missing = toolkit.get_validator('not_missing')13ignore_missing = toolkit.get_validator('ignore_missing')14package_exists = toolkit.get_validator('package_id_or_name_exists')15resource_id_exists = toolkit.get_validator('resource_id_exists')16user_exists = toolkit.get_validator('user_id_or_name_exists')17organization_exists = toolkit.get_validator('group_id_or_name_exists')18is_natural_number = toolkit.get_validator('natural_number_validator')19is_positive_integer = toolkit.get_validator('is_positive_integer')20boolean_validator = toolkit.get_validator('boolean_validator')21def issue_show_schema():22 return {23 'dataset_id': [not_missing, unicode, package_exists, as_package_id],24 'include_reports': [ignore_missing, bool],25 'issue_number': [not_missing, is_positive_integer],26 '__after': [issue_number_exists_for_dataset],27 }28def issue_create_schema():29 return {30 'title': [not_missing, unicode],31 'description': [ignore_missing, unicode],32 'dataset_id': [not_missing, unicode, package_exists, as_package_id],33 }34def issue_update_schema():35 return {36 'assignee_id': [ignore_missing, unicode, user_exists],37 'dataset_id': [not_missing, unicode, package_exists, as_package_id],38 'description': [ignore_missing, unicode],39 'issue_number': [not_missing, is_positive_integer],40 'resource_id': [ignore_missing, unicode, resource_id_exists],41 'status': [ignore_missing, unicode],42 'title': [ignore_missing, unicode],43 '__after': [issue_number_exists_for_dataset],44 }45def issue_delete_schema():46 return {47 'issue_number': [not_missing, is_positive_integer],48 'dataset_id': [not_missing, unicode, package_exists, as_package_id],49 '__after': [issue_number_exists_for_dataset],50 }51def issue_search_schema():52 return {53 'dataset_id': [ignore_missing, unicode, as_package_id],54 'organization_id': [ignore_missing, unicode, as_org_id],55 'status': [ignore_missing, unicode, is_valid_status],56 'sort': [ignore_missing, unicode, is_valid_sort],57 'limit': [ignore_missing, is_natural_number],58 'offset': [ignore_missing, is_natural_number],59 'q': [ignore_missing, unicode],60 'visibility': [ignore_missing, unicode],61 'include_count': [ignore_missing, bool],62 'include_datasets': [ignore_missing, bool],63 'include_reports': [ignore_missing, bool],64 'include_results': [ignore_missing, bool],65 'include_sub_organizations': [ignore_missing, bool],66 'abuse_status': [ignore_missing, unicode, is_valid_abuse_status],67 }68def issue_comment_schema():69 return {70 'comment': [not_missing, unicode],71 'dataset_id': [not_missing, unicode, package_exists, as_package_id],72 'issue_number': [not_missing, is_positive_integer],73 '__after': [issue_number_exists_for_dataset],74 }75def issue_report_schema():76 return {77 'dataset_id': [not_missing, unicode, package_exists, as_package_id],78 'issue_number': [not_missing, is_positive_integer],79 '__after': [issue_number_exists_for_dataset],80 }81def issue_report_clear_schema():82 schema = issue_report_schema()83 schema.update({'clear_abuse_status': [ignore_missing, bool]})84 return schema85def issue_comment_report_schema():86 return {87 'dataset_id': [not_missing, unicode, package_exists, as_package_id],88 'issue_number': [not_missing, is_positive_integer],89 '__after': [issue_number_exists_for_dataset],90 'comment_id': [not_missing, unicode, issue_comment_exists],91 }92def issue_comment_report_clear_schema():93 schema = issue_report_schema()94 schema.update({'clear_abuse_status': [ignore_missing, bool]})95 return schema96def issue_dataset_controller_schema():97 return {98 'status': [ignore_missing, unicode],99 'sort': [ignore_missing, unicode],100 'page': [ignore_missing, is_positive_integer],101 'per_page': [ignore_missing, is_positive_integer],102 'q': [ignore_missing, unicode],103 'visibility': [ignore_missing, unicode],104 'abuse_status': [ignore_missing, unicode],105 }106def issue_show_controller_schema():107 return {108 'dataset_id': [not_missing, unicode, package_exists, as_package_id],109 'issue_number': [not_missing, is_positive_integer],110 '__after': [issue_number_exists_for_dataset],111 }112def organization_users_autocomplete_schema():113 return {114 'q': [not_missing, unicode],115 'organization_id': [not_missing, unicode],116 'limit': [ignore_missing, is_positive_integer],...
test_run.py
Source:test_run.py
...4def test_run(session):5 run_commander('run test_script')6 try:7 assert entity_type_exists(session, 'scripttest_testAutoId')8 assert package_exists(session, 'otherpackage')9 finally:10 session.delete('sys_md_Package', 'scripttest')11 session.delete('sys_md_Package', 'otherpackage')12@pytest.mark.integration13def test_run_from_path(session):14 run_commander('run --from-path {}'.format(get_test_context().get_scripts_folder().joinpath('test_script')))15 try:16 assert entity_type_exists(session, 'scripttest_testAutoId')17 assert package_exists(session, 'otherpackage')18 finally:19 session.delete('sys_md_Package', 'scripttest')20 session.delete('sys_md_Package', 'otherpackage')21@pytest.mark.integration22def test_run_from_line(session):23 run_commander('run test_script --from-line 3')24 try:25 assert not package_exists(session, 'scripttest')26 assert package_exists(session, 'otherpackage')27 finally:28 session.delete('sys_md_Package', 'otherpackage')29@pytest.mark.integration30def test_run_error(session):31 with pytest.raises(SystemExit):32 run_commander('run test_script_error')33 try:34 assert package_exists(session, 'scripttest')35 assert not package_exists(session, 'package_after_error')36 finally:37 session.delete('sys_md_Package', 'scripttest')38@pytest.mark.integration39def test_run_ignore_error(session):40 run_commander('run test_script_error --ignore-errors')41 try:42 assert package_exists(session, 'scripttest')43 assert package_exists(session, 'package_after_error')44 finally:45 session.delete('sys_md_Package', 'scripttest')46 session.delete('sys_md_Package', 'package_after_error')47@pytest.mark.integration48def test_run_nested_fails(session):49 with pytest.raises(SystemExit):50 run_commander('run test_script_nested')51 assert not package_exists(session, 'scripttest')52 assert not package_exists(session, 'package_after_error')53@pytest.mark.integration54def test_run_quotes(session):55 run_commander('run test_script_quotes')56 settings = session.get('sys_set_app')[0]57 assert settings['title'] == 'value between quotes'58@pytest.mark.integration59def test_run_comments(session, caplog):60 run_commander('run test_script_comments')61 settings = session.get('sys_set_app')[0]62 assert settings['title'] == 'test'63 expected_messages = [64 "Let's change the app title",65 'Finished'66 ]...
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!!