Best Python code snippet using autotest_python
test_importer.py
Source:test_importer.py
...342 f = open(whitelist_path, 'r')343 whitelist_set = set([line.strip() for line in f])344 f.close()345 return whitelist_set346def update_from_whitelist(whitelist_set, add_experimental, add_noncompliant,347 autotest_dir):348 """349 Scans through all tests in the whitelist and add them to the database.350 This function invoked when -w supplied.351 :param whitelist_set: set of tests in full-path form from a whitelist.352 :param add_experimental: add tests with experimental attribute set.353 :param add_noncompliant: attempt adding test with invalid control files.354 :param autotest_dir: prepended to path strings355 (see global_config.ini, COMMON, autotest_top_path).356 """357 tests = {}358 profilers = {}359 for file_path in whitelist_set:360 if file_path.find('client/profilers') == -1:361 try:362 found_test = control_data.parse_control(file_path,363 raise_warnings=True)364 tests[file_path] = found_test365 except control_data.ControlVariableException, e:366 logging.warn("Skipping %s\n%s", file, e)367 else:368 profilers[file_path] = compiler.parseFile(file_path).doc369 if len(tests) > 0:370 update_tests_in_db(tests, add_experimental=add_experimental,371 add_noncompliant=add_noncompliant,372 autotest_dir=autotest_dir)373 if len(profilers) > 0:374 update_profilers_in_db(profilers, add_noncompliant=add_noncompliant,375 description='NA')376def main(argv):377 """Main function"""378 global DRY_RUN379 parser = optparse.OptionParser()380 parser.add_option('-c', '--db-clean-tests',381 dest='clean_tests', action='store_true',382 default=False,383 help='Clean client and server tests with invalid control files')384 parser.add_option('-C', '--db-clear-all-tests',385 dest='clear_all_tests', action='store_true',386 default=False,387 help='Clear ALL client and server tests')388 parser.add_option('-d', '--dry-run',389 dest='dry_run', action='store_true', default=False,390 help='Dry run for operation')391 parser.add_option('-A', '--add-all',392 dest='add_all', action='store_true',393 default=False,394 help='Add site_tests, tests, and test_suites')395 parser.add_option('-S', '--add-samples',396 dest='add_samples', action='store_true',397 default=False,398 help='Add samples.')399 parser.add_option('-E', '--add-experimental',400 dest='add_experimental', action='store_true',401 default=True,402 help='Add experimental tests to frontend')403 parser.add_option('-N', '--add-noncompliant',404 dest='add_noncompliant', action='store_true',405 default=False,406 help='Add non-compliant tests (i.e. tests that do not '407 'define all required control variables)')408 parser.add_option('-p', '--profile-dir', dest='profile_dir',409 help='Directory to recursively check for profiles')410 parser.add_option('-t', '--tests-dir', dest='tests_dir',411 help='Directory to recursively check for control.*')412 parser.add_option('-r', '--control-pattern', dest='control_pattern',413 default='^control.*',414 help='The pattern to look for in directories for control files')415 parser.add_option('-v', '--verbose',416 dest='verbose', action='store_true', default=False,417 help='Run in verbose mode')418 parser.add_option('-w', '--whitelist-file', dest='whitelist_file',419 help='Filename for list of test names that must match')420 parser.add_option('-z', '--autotest-dir', dest='autotest_dir',421 default=os.path.join(os.path.dirname(__file__), '..'),422 help='Autotest directory root, or base test directory')423 options, args = parser.parse_args()424 logging_manager.configure_logging(TestImporterLoggingConfig(),425 verbose=options.verbose)426 DRY_RUN = options.dry_run427 if DRY_RUN:428 logging.getLogger().setLevel(logging.WARN)429 # Make sure autotest_dir is the absolute path430 options.autotest_dir = os.path.abspath(options.autotest_dir)431 if len(args) > 0:432 logging.error("Invalid option(s) provided: %s", args)433 parser.print_help()434 return 1435 if options.verbose:436 logging.getLogger().setLevel(logging.DEBUG)437 if len(argv) == 1 or (len(argv) == 2 and options.verbose):438 update_all(options.autotest_dir, options.add_noncompliant,439 options.add_experimental)440 db_clean_broken(options.autotest_dir)441 return 0442 if options.clear_all_tests:443 if (options.clean_tests or options.add_all or options.add_samples or444 options.add_noncompliant):445 logging.error(446 "Can only pass --autotest-dir, --dry-run and --verbose with "447 "--db-clear-all-tests")448 return 1449 db_clean_all(options.autotest_dir)450 whitelist_set = None451 if options.whitelist_file:452 if options.add_all:453 logging.error("Cannot pass both --add-all and --whitelist-file")454 return 1455 whitelist_path = os.path.abspath(options.whitelist_file)456 if not os.path.isfile(whitelist_path):457 logging.error("--whitelist-file (%s) not found", whitelist_path)458 return 1459 logging.info("Using whitelist file %s", whitelist_path)460 whitelist_set = _create_whitelist_set(whitelist_path)461 update_from_whitelist(whitelist_set,462 add_experimental=options.add_experimental,463 add_noncompliant=options.add_noncompliant,464 autotest_dir=options.autotest_dir)465 if options.add_all:466 update_all(options.autotest_dir, options.add_noncompliant,467 options.add_experimental)468 if options.add_samples:469 update_samples(options.autotest_dir, options.add_noncompliant,470 options.add_experimental)471 if options.tests_dir:472 options.tests_dir = os.path.abspath(options.tests_dir)473 tests = get_tests_from_fs(options.tests_dir, options.control_pattern,474 add_noncompliant=options.add_noncompliant)475 update_tests_in_db(tests, add_experimental=options.add_experimental,...
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!!