def __test_has_cmdline_string(cfg, cmdline, key): value = generate_random_string() cmdline = ['ctt', cmdline, value] with mock.patch('sys.argv', cmdline): ctt = CTTConfig(cfg, CTTCmdline, boards, False) assert_true(ctt.__contains__(key))
def __test_set_cmdline_string_single(cfg, cmdline, key): value = generate_random_string() argv = ['ctt', cmdline, value] with mock.patch('sys.argv', argv): ctt = CTTConfig(cfg, CTTCmdline, boards, False) assert_equal(value, ctt[key])
def test_cfg_board_all(): cfg, cmdline, values = generate_config() with mock.patch('sys.argv', [ 'ctt', '-t' 'boot', '-b', 'all', '--kernel', 'zImage', '--dtb', 'board.dtb' ]): ctt = CTTConfig(cfg, CTTCmdline, boards) assert_equal(ctt['boards'], list(boards.keys()))
def __test_get_config_value(key, multiple=False): cfg, cmdline, values = generate_config() with mock.patch('sys.argv', cmdline): ctt = CTTConfig(cfg, CTTCmdline, boards, False) if multiple: assert_equal(ctt[key], [values[key]]) else: assert_equal(ctt[key], values[key])
def __test_get_cmdline_missing(cfg, key, default=None): with mock.patch('sys.argv', ['ctt']): ctt = CTTConfig(cfg, CTTCmdline, boards, False) if default is not None: assert_equal(default, ctt[key]) else: try: ctt[key] assert False except KeyError: assert True
def __test_cfg_board_valid(board): cfg, cmdline, values = generate_config() with mock.patch('sys.argv', [ 'ctt', '-t', generate_random_string(), '-b', board, '--kernel', generate_random_string(), '--dtb', generate_random_string() ]): ctt = CTTConfig(cfg, CTTCmdline, boards) assert True
def __test_set_cmdline_string_multiple(cfg, cmdline, key): argv = ['ctt', cmdline] value = [] for i in range(random.randint(2, 16)): value.append(generate_random_string()) argv.extend(value) with mock.patch('sys.argv', argv): ctt = CTTConfig(cfg, CTTCmdline, boards, False) assert_equal(value, ctt[key])
def test_cfg_board_all_multiple(): cfg, cmdline, values = generate_config() with mock.patch('sys.argv', [ 'ctt', '-t' 'boot', '-b', 'all', '--kernel', generate_random_string(), '--dtb', generate_random_string() ]): ctt = CTTConfig(cfg, CTTCmdline, boards) assert_equal(ctt['boards'], list(boards.keys()))
def __test_cfg_cmdline_missing_option(cfg, cmdline): argv = ['ctt'] cfg, _, _ = generate_config() for option in config_dict: if ('cmdline' in option and option['cmdline'] and option['cmdline'] is not cmdline and not option['cmdline'] == '--list'): argv.append(option['cmdline']) if 'boolean' not in option or not option['boolean']: argv.append(generate_random_string()) with mock.patch('sys.argv', argv): ctt = CTTConfig(cfg, CTTCmdline, boards)
def __test_override_value(key, cmdoption, multiple): cfg, cmdline, values = generate_config() new_value = generate_random_string() # If our value has multiple options, our parser will return a # list with a single element, instead of just the element if (multiple): test_value = list() test_value.append(new_value) else: test_value = new_value cmdline.extend([cmdoption, new_value]) with mock.patch('sys.argv', cmdline): ctt = CTTConfig(cfg, CTTCmdline, boards, False) assert_equal(ctt[key], test_value)
def __test_set_cmdline_bool(cfg, cmdline, key): argv = ['ctt', cmdline] with mock.patch('sys.argv', argv): ctt = CTTConfig(cfg, CTTCmdline, boards, False) assert_true(ctt[key])
def __test_has_config_value(key): cfg, cmdline, values = generate_config() with mock.patch('sys.argv', cmdline): ctt = CTTConfig(cfg, CTTCmdline, boards, False) assert_true(ctt.__contains__(key))
def __test_has_cmdline_missing(cfg, key): with mock.patch('sys.argv', ['ctt']): ctt = CTTConfig(cfg, CTTCmdline, boards, False) assert_false(ctt.__contains__(key))
def test_cfg_board_invalid(): cfg, cmdline, values = generate_config() with mock.patch('sys.argv', cmdline): ctt = CTTConfig(cfg, CTTCmdline, boards)
def test_config_missing_test_board(): cfg, cmdline, values = generate_config() with mock.patch('sys.argv', ['ctt', '-b', generate_random_string()]): ctt = CTTConfig(cfg, CTTCmdline, boards)
def test_cfg_config_missing_cmdline_only(): cfg, cmdline, values = generate_config() with mock.patch('sys.argv', ['ctt']): ctt = CTTConfig(cfg, CTTCmdline, boards)
def test_cfg_config_missing_section(): config = generate_config(section='test')[0] ctt = CTTConfig(config, CTTCmdline, boards)
def __test_cfg_config_missing_option(key): config = generate_config(ignore_key=key)[0] with mock.patch('sys.argv', ['ctt']): ctt = CTTConfig(config, CTTCmdline, boards)