How to use parse_cli method in tox

Best Python code snippet using tox_python

test_cli.py

Source:test_cli.py Github

copy

Full Screen

...46def test_parse_cli_inline(argv):47 """48 Test the correctness of parse_cli49 """50 args = parse_cli(argv)51 assert args['do_recovery_mode'] is False52 assert args['load | inline'] == 'inline'53 assert args['log_level'] == 'DEBUG'54 assert args['no_scrape'] is False55 assert args['master_csv_file'] == 'TEST_search'56 assert args['log_file'] == 'TEST_log_file'57 assert args['cache_folder'] == 'TEST_cache'58 assert args['block_list_file'] == 'TEST_block_list'59 assert args['duplicates_list_file'] == 'TEST_duplicates_list'60 assert args['search.keywords'] == ['I', 'Am', 'Testing']61 assert args['search.locale'] == 'CANADA_ENGLISH'62 assert args['search.province_or_state'] == 'TESTPS'63 assert args['search.city'] == 'TestCity'64 assert args['search.company_block_list'] == ['Blocked Company', 'Blocked Company 2']65 assert args['search.radius'] == 4266 assert args['search.remoteness'] == 'ANY'67 assert args['search.max_listing_days'] == 4468 assert args['search.similar_results'] is True69 assert args['proxy.protocol'] is None70 assert args['proxy.ip'] is None71 assert args['proxy.port'] is None72 assert args['delay.random'] is True73 assert args['delay.converging'] is True74 assert args['delay.max_duration'] == 8.075 assert args['delay.min_duration'] == 2.076 assert args['delay.algorithm'] == 'LINEAR'77@pytest.mark.parametrize('argv', load_args)78def test_parse_cli_load(argv):79 args = parse_cli(argv)80 # FIXME: This test should only be testing the correctness of parse_cli81 # Assertions82 assert args['settings_yaml_file'] == TEST_YAML83 if '-log-level' in argv and argv[4] == 'DEBUG':84 # NOTE: need to always pass log level in same place for this cdtn85 assert args['log_level'] == 'DEBUG'86 if '--no-scrape' in argv:87 assert args['no_scrape'] is True88 else:89 assert args['no_scrape'] is False90@pytest.mark.parametrize('argv, exception', invalid_args)91def test_parse_cli_invalid_args(argv, exception):92 with pytest.raises(exception) as e:93 args = parse_cli(argv)94 assert str(e.value) == '2'95@pytest.mark.parametrize('argv, exception', load_args_invalid_settings)96def test_build_config_dict_invalid_settings(argv, exception):97 args = parse_cli(argv)98 with pytest.raises(exception) as e:99 cfg_dict = build_config_dict(args)100 assert str(e.value) == "Invalid Config settings yaml:\n" \101 "{'search': [{'radius': ['must be of integer type']}]}"102@pytest.mark.parametrize('argv', load_args)103def test_build_config_dict_load_args(argv):104 args = parse_cli(argv)105 cfg_dict = build_config_dict(args)106 assert cfg_dict['master_csv_file'] == 'TEST_search'107 assert cfg_dict['cache_folder'] == 'TEST_cache'108 assert cfg_dict['block_list_file'] == 'TEST_block_list'109 assert cfg_dict['duplicates_list_file'] == 'TEST_duplicates_list'110 assert cfg_dict['log_file'] == 'TEST_log_file'111 assert cfg_dict['search'] == {'locale': 'CANADA_ENGLISH', 'providers': ['INDEED', 'MONSTER'],112 'province_or_state': 'TESTPS', 'city': 'TestCity', 'radius': 42, 'keywords':113 ['I', 'Am', 'Testing'], 'max_listing_days': 44, 'company_block_list':114 ['Blocked Company', 'Blocked Company 2'],115 'similar_results': False, 'remoteness': 'ANY'}116 if '-log-level' in argv:117 assert cfg_dict['log_level'] == 'DEBUG'118 else:119 assert cfg_dict['log_level'] == 'INFO'120 assert cfg_dict['delay'] == {'algorithm': 'LINEAR', 'max_duration': 8, 'min_duration': 2,121 'random': True, 'converging': True}122 if '--no-scrape' in argv:123 assert cfg_dict['no_scrape'] is True124 else:125 assert cfg_dict['no_scrape'] is False126@pytest.mark.parametrize('argv', inline_args)127def test_build_config_dict_inline_args(argv):128 args = parse_cli(argv)129 cfg_dict = build_config_dict(args)130 assert cfg_dict['master_csv_file'] == 'TEST_search'131 assert cfg_dict['cache_folder'] == 'TEST_cache'132 assert cfg_dict['block_list_file'] == 'TEST_block_list'133 assert cfg_dict['duplicates_list_file'] == 'TEST_duplicates_list'134 assert cfg_dict['log_file'] == 'TEST_log_file'135 assert cfg_dict['search'] == {'locale': 'CANADA_ENGLISH', 'providers': ['INDEED', 'MONSTER'],136 'province_or_state': 'TESTPS', 'city': 'TestCity', 'radius': 42, 'keywords':137 ['I', 'Am', 'Testing'], 'max_listing_days': 44, 'company_block_list':138 ['Blocked Company', 'Blocked Company 2'],139 'similar_results': True, 'remoteness': 'ANY'}140 assert cfg_dict['delay'] == {'random': True, 'converging': True, 'max_duration': 8.0, 'min_duration': 2.0,141 'algorithm': 'LINEAR'}142 assert cfg_dict['log_level'] == 'DEBUG'...

Full Screen

Full Screen

test_commandline.py

Source:test_commandline.py Github

copy

Full Screen

...67 assert cmd.redact_payload(b"payload") == b"payload"68@Options.mock()69def test_update_site_url(cmd):70 argv = ["console", "--update-site-url", "DEBUG_TEST"]71 options = cmd.parse_cli([])72 assert options.update_site_url == Options.update_site_url73 # Normal arg74 options = cmd.parse_cli(argv)75 assert options.update_site_url == "DEBUG_TEST"76@Options.mock()77@pytest.mark.parametrize("encoding", ["utf-16", "utf-8-sig"])78def test_bad_encoding_utf_16(encoding, cmd, config):79 config(encoding=encoding)80 cmd.parse_cli([])81@Options.mock()82def test_defaults(cmd):83 argv = ["console", "--log-level-console", "WARNING"]84 # Default value85 options = cmd.parse_cli([])86 assert options.log_level_console == "WARNING"87 # Normal arg88 options = cmd.parse_cli(argv)89 assert options.log_level_console == "WARNING"90def get_conf(_):91 return {"log_level_console": "DEBUG"}92@Options.mock()93@windows_only94def test_system_default_windows(cmd):95 from nxdrive.osi.windows.windows import WindowsIntegration96 with patch.object(WindowsIntegration, "get_system_configuration", new=get_conf):97 options = cmd.parse_cli([])98 assert options.log_level_console == "DEBUG"99@Options.mock()100@mac_only101def test_system_default_mac(cmd):102 from nxdrive.osi.darwin.darwin import DarwinIntegration103 with patch.object(DarwinIntegration, "get_system_configuration", new=get_conf):104 options = cmd.parse_cli([])105 assert options.log_level_console == "DEBUG"106@Options.mock()107def test_default_override(cmd, config):108 argv = ["console", "--log-level-console=INFO"]109 # Default value110 options = cmd.parse_cli([])111 assert options.log_level_console == "WARNING"112 assert not options.debug113 # Normal arg114 options = cmd.parse_cli(argv)115 assert options.log_level_console == "INFO"116 assert not options.debug117 # config.ini override118 config()119 options = cmd.parse_cli([])120 assert options.log_level_console == "DEBUG"121 assert not options.debug122 # config.ini override, but arg specified123 options = cmd.parse_cli(argv)124 assert options.log_level_console == "INFO"125 assert not options.debug126 # other usage section127 config(env="DEV")128 options = cmd.parse_cli([])129 assert options.log_level_console == "ERROR"130 assert options.debug131 assert options.delay == 3132 assert options.tmp_file_limit == 0.0105133@Options.mock()134def test_default_override_from_alternate_nxdrive_home(cmd, config):135 expected_nxdrive_home = str(Options.nxdrive_home / "drive_home")136 config(env="Inception")137 args = cmd.load_config()138 assert args["nxdrive_home"] == expected_nxdrive_home139 assert args["force_locale"] == "fr"140def test_confg_file_no_default_section(cmd, config):141 config(default_section="default")142 args = cmd.load_config()143 assert not args144@Options.mock()145def test_malformatted_line(cmd, config):146 config(env="BAD")147 cmd.parse_cli([])148 # The malformed line will display a warning:149 # Unknown logging level ('=', 'DEBUG', 'False', 'debug'), need to be one of ...150 # Callback check for 'log_level_console' denied modification. Value is still 'WARNING'....

Full Screen

Full Screen

parse_cli.py

Source:parse_cli.py Github

copy

Full Screen

...9def debug(s):10 if DEBUG:11 print('DEBUG: %s' % s)1213def parse_cli(values, defaults=None):14 """ Simple option/argument parsing.1516 Args:17 values: sequence of str giving command-line, i.e. usually sys.argv[1:]18 defaults: dict defining options - any element of `values` which is not a key in `defaults` is assumed to be an argument.19 If a value in `defaults` is a bool, the option takes no argument, otherwise it does.2021 Returns (options, arguments) where the former is a dict giving options and the latter is a sequence giving arguments.2223 Examples:24 >>> parse_cli('-v --option foo arg1 arg2'.split(), {'-v':False, '--option':'bar'})25 ({'-v': True, '--option': 'foo'}, ['arg1', 'arg2'])26 >>> parse_cli('--option foo arg1'.split(), {'-v':True, '--option':'bar'})27 ({'-v': True, '--option': 'foo'}, ['arg1'])28 >>> parse_cli('--option foo'.split(), {'-v':True, '--option':'bar'})29 ({'-v': True, '--option': 'foo'}, [])30 >>> parse_cli(''.split(), {'-v':True, '--option':'bar'})31 ({'-v': True, '--option': 'bar'}, [])32 >>> parse_cli('-v'.split(), {'-v':False, '--option':'bar'})33 ({'-v': True, '--option': 'bar'}, [])34 >>> parse_cli('argX'.split(), {})35 ({}, ['argX'])3637 """3839 options = {} if defaults is None else defaults.copy()40 args = []41 idx = 042 while idx < len(values):43 v = values[idx]44 if v in options: # is option45 if isinstance(defaults[v], bool): # is flag46 options[v] = True47 else:48 options[v] = values[idx + 1] # TODO: length check, check doesn't start with '-'? ...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tox automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful