def test_merge_color_configs_mixed(): second = config.get_default_color_config() first = config.ColorConfig(pound='pound_color', heading=None, code='code_color', backticks=None, prompt=None, pound_reset=None, heading_reset=None, code_reset=None, backticks_reset=None, prompt_reset=None) merged = config.merge_color_configs(first, second) target = config.ColorConfig(pound=first.pound, heading=second.heading, code=first.code, backticks=second.backticks, prompt=second.prompt, pound_reset=second.pound_reset, heading_reset=second.heading_reset, code_reset=second.code_reset, backticks_reset=second.backticks_reset, prompt_reset=second.prompt_reset) assert_equal(merged, target)
def test_merge_color_configs_mixed(): second = config.get_default_color_config() first = config.ColorConfig( pound='pound_color', heading=None, code='code_color', backticks=None, prompt=None, pound_reset=None, heading_reset=None, code_reset=None, backticks_reset=None, prompt_reset=None ) merged = config.merge_color_configs(first, second) target = config.ColorConfig( pound=first.pound, heading=second.heading, code=first.code, backticks=second.backticks, prompt=second.prompt, pound_reset=second.pound_reset, heading_reset=second.heading_reset, code_reset=second.code_reset, backticks_reset=second.backticks_reset, prompt_reset=second.prompt_reset ) assert_equal(merged, target)
def test_config_returns_values_passed_at_command_line(): """ Options passed in at the command line should override those in the egrc. """ with patch('os.path.isfile', return_value=True): command_line_examples_dir = 'test_eg_dir_user_defined' command_line_custom_dir = 'test_custom_dir_user_defined' command_line_use_color = 'we_should_use_color' command_line_pager_cmd = 'command_line_says_pager_with_cat' egrc_examples_dir = 'egrc_examples_dir' egrc_custom_dir = 'egrc_custom_dir' egrc_use_color = 'the_egrc_says_yes_color' egrc_pager_cmd = 'the_egrc_pages_with_more' egrc_config = config.Config( examples_dir=egrc_examples_dir, custom_dir=egrc_custom_dir, color_config=config.get_default_color_config(), use_color=egrc_use_color, pager_cmd=egrc_pager_cmd) with patch('eg.config.get_config_tuple_from_egrc', return_value=egrc_config): actual = config.get_resolved_config_items( None, command_line_examples_dir, command_line_custom_dir, command_line_use_color, command_line_pager_cmd, debug=False) assert_equal(actual.examples_dir, command_line_examples_dir) assert_equal(actual.custom_dir, command_line_custom_dir) assert_equal(actual.use_color, command_line_use_color) assert_equal(actual.pager_cmd, command_line_pager_cmd)
def test_does_not_call_colorize_if_use_color_false(): """We should not call colorize if use_color = False.""" default_file = 'def_path' default_contents = 'def contents' custom_path = 'custom_path', custom_contents = 'custom contents' combined_contents = custom_contents + default_contents colorized_contents = 'colorized: ' + combined_contents _helper_assert_open_pager_for_file(default_file, default_contents, custom_path, custom_contents, False, config.get_default_color_config(), 'pager command whoop', combined_contents, colorized_contents, combined_contents)
def test_default_color_config(): """Make sure the default color config is set to the right values.""" actual = config.get_default_color_config() assert actual.pound == config.DEFAULT_COLOR_POUND assert actual.heading == config.DEFAULT_COLOR_HEADING assert actual.code == config.DEFAULT_COLOR_CODE assert actual.backticks == config.DEFAULT_COLOR_BACKTICKS assert actual.prompt == config.DEFAULT_COLOR_PROMPT assert actual.pound_reset == config.DEFAULT_COLOR_POUND_RESET assert actual.heading_reset == config.DEFAULT_COLOR_HEADING_RESET assert actual.code_reset == config.DEFAULT_COLOR_CODE_RESET assert actual.backticks_reset == config.DEFAULT_COLOR_BACKTICKS_RESET assert actual.prompt_reset == config.DEFAULT_COLOR_PROMPT_RESET
def test_default_color_config(): """Make sure the default color config is set to the right values.""" actual = config.get_default_color_config() assert_equal(actual.pound, config.DEFAULT_COLOR_POUND) assert_equal(actual.heading, config.DEFAULT_COLOR_HEADING) assert_equal(actual.code, config.DEFAULT_COLOR_CODE) assert_equal(actual.backticks, config.DEFAULT_COLOR_BACKTICKS) assert_equal(actual.prompt, config.DEFAULT_COLOR_PROMPT) assert_equal(actual.pound_reset, config.DEFAULT_COLOR_POUND_RESET) assert_equal(actual.heading_reset, config.DEFAULT_COLOR_HEADING_RESET) assert_equal(actual.code_reset, config.DEFAULT_COLOR_CODE_RESET) assert_equal(actual.backticks_reset, config.DEFAULT_COLOR_BACKTICKS_RESET) assert_equal(actual.prompt_reset, config.DEFAULT_COLOR_PROMPT_RESET)
def test_calls_colorize_is_use_color_set(): """We should call the colorize function if use_color = True.""" default_file = 'def_path' default_contents = 'def contents' custom_path = 'custom_path', custom_contents = 'custom contents' combined_contents = custom_contents + default_contents colorized_contents = 'colorized: ' + combined_contents _helper_assert_open_pager_for_file(default_file, default_contents, custom_path, custom_contents, True, config.get_default_color_config(), 'pager cmd for use color', combined_contents, colorized_contents, colorized_contents)
def test_config_returns_defaults_if_all_none_and_no_egrc(): with patch('os.path.isfile', return_value=False): resolved_config = config.get_resolved_config_items(None, None, None, None, None, debug=False) default_color_config = config.get_default_color_config() assert_equal(resolved_config.examples_dir, config.DEFAULT_EXAMPLES_DIR) assert_equal(resolved_config.custom_dir, None) assert_equal(resolved_config.color_config, default_color_config) assert_equal(resolved_config.use_color, config.DEFAULT_USE_COLOR) assert_equal(resolved_config.pager_cmd, config.DEFAULT_PAGER_CMD)
def test_merge_color_configs_first_all_none(): second = config.get_default_color_config() first = config.ColorConfig(pound=None, heading=None, code=None, backticks=None, prompt=None, pound_reset=None, heading_reset=None, code_reset=None, backticks_reset=None, prompt_reset=None) merged = config.merge_color_configs(first, second) assert_equal(merged, second)
def test_merge_color_configs_take_all_first(): second = config.get_default_color_config() first = config.ColorConfig(pound='pound_color', heading='heading_color', code='code_color', backticks='backticks_color', prompt='prompt_color', pound_reset='p_reset', heading_reset='h_reset', code_reset='c_reset', backticks_reset='b_reset', prompt_reset='prmpt_reset') merged = config.merge_color_configs(first, second) assert_equal(merged, first)
def test_config_returns_defaults_if_all_none_and_no_egrc(): with patch('os.path.isfile', return_value=False): resolved_config = config.get_resolved_config_items( None, None, None, None, None, debug=False ) default_color_config = config.get_default_color_config() assert_equal(resolved_config.examples_dir, config.DEFAULT_EXAMPLES_DIR) assert_equal(resolved_config.custom_dir, None) assert_equal(resolved_config.color_config, default_color_config) assert_equal(resolved_config.use_color, config.DEFAULT_USE_COLOR) assert_equal(resolved_config.pager_cmd, config.DEFAULT_PAGER_CMD)
def test_default_color_config(): """Make sure the default color config is set to the right values.""" actual = config.get_default_color_config() assert_equal(actual.pound, config.DEFAULT_COLOR_POUND) assert_equal(actual.heading, config.DEFAULT_COLOR_HEADING) assert_equal(actual.code, config.DEFAULT_COLOR_CODE) assert_equal(actual.backticks, config.DEFAULT_COLOR_BACKTICKS) assert_equal(actual.prompt, config.DEFAULT_COLOR_PROMPT) assert_equal(actual.pound_reset, config.DEFAULT_COLOR_POUND_RESET) assert_equal(actual.heading_reset, config.DEFAULT_COLOR_HEADING_RESET) assert_equal(actual.code_reset, config.DEFAULT_COLOR_CODE_RESET) assert_equal( actual.backticks_reset, config.DEFAULT_COLOR_BACKTICKS_RESET ) assert_equal(actual.prompt_reset, config.DEFAULT_COLOR_PROMPT_RESET)
def test_config_returns_values_passed_at_command_line(): """ Options passed in at the command line should override those in the egrc. """ with patch('os.path.isfile', return_value=True): command_line_examples_dir = 'test_eg_dir_user_defined' command_line_custom_dir = 'test_custom_dir_user_defined' command_line_use_color = 'we_should_use_color' command_line_pager_cmd = 'command_line_says_pager_with_cat' command_line_squeeze = 'command_line_wants_to_squeeze' egrc_examples_dir = 'egrc_examples_dir' egrc_custom_dir = 'egrc_custom_dir' egrc_use_color = 'the_egrc_says_yes_color' egrc_pager_cmd = 'the_egrc_pages_with_more' egrc_squeeze = 'egrc_says_squeeze' egrc_subs = ['sub1', 'sub2'] egrc_config = config.Config( examples_dir=egrc_examples_dir, custom_dir=egrc_custom_dir, color_config=config.get_default_color_config(), use_color=egrc_use_color, pager_cmd=egrc_pager_cmd, squeeze=egrc_squeeze, subs=egrc_subs ) with patch( 'eg.config.get_config_tuple_from_egrc', return_value=egrc_config ): actual = config.get_resolved_config_items( None, command_line_examples_dir, command_line_custom_dir, command_line_use_color, command_line_pager_cmd, command_line_squeeze, debug=False ) assert_equal(actual.examples_dir, command_line_examples_dir) assert_equal(actual.custom_dir, command_line_custom_dir) assert_equal(actual.use_color, command_line_use_color) assert_equal(actual.pager_cmd, command_line_pager_cmd) assert_equal(actual.squeeze, command_line_squeeze)
def test_merge_color_configs_first_all_none(): second = config.get_default_color_config() first = config.ColorConfig( pound=None, heading=None, code=None, backticks=None, prompt=None, pound_reset=None, heading_reset=None, code_reset=None, backticks_reset=None, prompt_reset=None ) merged = config.merge_color_configs(first, second) assert_equal(merged, second)
def test_merge_color_configs_take_all_first(): second = config.get_default_color_config() first = config.ColorConfig( pound='pound_color', heading='heading_color', code='code_color', backticks='backticks_color', prompt='prompt_color', pound_reset='p_reset', heading_reset='h_reset', code_reset='c_reset', backticks_reset='b_reset', prompt_reset='prmpt_reset' ) merged = config.merge_color_configs(first, second) assert_equal(merged, first)
def test_config_returns_defaults_if_all_none_and_no_egrc(): """No config file and no egrc should return default values.""" with patch('os.path.isfile', return_value=False): resolved_config = config.get_resolved_config_items(None, None, None, None, None, None, debug=False) default_color_config = config.get_default_color_config() assert_equal(resolved_config.examples_dir, config.DEFAULT_EXAMPLES_DIR) assert_equal(resolved_config.custom_dir, None) assert_equal(resolved_config.color_config, default_color_config) assert_equal(resolved_config.use_color, config.DEFAULT_USE_COLOR) assert_equal(resolved_config.pager_cmd, config.DEFAULT_PAGER_CMD) assert_equal(resolved_config.squeeze, config.DEFAULT_SQUEEZE) assert_equal(resolved_config.subs, config.get_default_subs())
def test_get_resolved_config_falls_back_to_defaults(): """ When no cli arguments or egrc arguments are present, we should use the raw defaults. """ empty_config = config.get_empty_config() expected = config.Config( examples_dir=config.DEFAULT_EXAMPLES_DIR, custom_dir=config.DEFAULT_CUSTOM_DIR, use_color=config.DEFAULT_USE_COLOR, color_config=config.get_default_color_config(), pager_cmd=config.DEFAULT_PAGER_CMD, squeeze=config.DEFAULT_SQUEEZE, subs=config.get_default_subs(), editor_cmd=config.DEFAULT_EDITOR_CMD, ) _assert_about_get_resolved_config(egrc_config=empty_config, environment_editor_cmd=None, expected_config=expected)
def test_config_returns_defaults_if_all_none_and_no_egrc(): """No config file and no egrc should return default values.""" with patch('os.path.isfile', return_value=False): resolved_config = config.get_resolved_config_items( None, None, None, None, None, None, debug=False ) default_color_config = config.get_default_color_config() assert_equal(resolved_config.examples_dir, config.DEFAULT_EXAMPLES_DIR) assert_equal(resolved_config.custom_dir, None) assert_equal(resolved_config.color_config, default_color_config) assert_equal(resolved_config.use_color, config.DEFAULT_USE_COLOR) assert_equal(resolved_config.pager_cmd, config.DEFAULT_PAGER_CMD) assert_equal(resolved_config.squeeze, config.DEFAULT_SQUEEZE) assert_equal(resolved_config.subs, config.get_default_subs())
def test_get_resolved_config_falls_back_to_defaults(): """ When no cli arguments or egrc arguments are present, we should use the raw defaults. """ empty_config = config.get_empty_config() expected = config.Config( examples_dir=config.DEFAULT_EXAMPLES_DIR, custom_dir=config.DEFAULT_CUSTOM_DIR, use_color=config.DEFAULT_USE_COLOR, color_config=config.get_default_color_config(), pager_cmd=config.DEFAULT_PAGER_CMD, squeeze=config.DEFAULT_SQUEEZE, subs=config.get_default_subs(), editor_cmd=config.DEFAULT_EDITOR_CMD, ) _assert_about_get_resolved_config( egrc_config=empty_config, environment_editor_cmd=None, expected_config=expected )
def _create_dummy_egrc_config(): """ Return a dummy Config object as if constructed from an egrc. """ egrc_examples_dir = 'egrc_examples_dir' egrc_custom_dir = 'egrc_custom_dir' egrc_use_color = 'the_egrc_says_yes_color' egrc_pager_cmd = 'the_egrc_pages_with_more' egrc_squeeze = 'egrc_says_squeeze' egrc_subs = ['sub1', 'sub2'] egrc_editor_cmd = 'vim from egrc' result = config.Config( examples_dir=egrc_examples_dir, custom_dir=egrc_custom_dir, color_config=config.get_default_color_config(), use_color=egrc_use_color, pager_cmd=egrc_pager_cmd, squeeze=egrc_squeeze, subs=egrc_subs, editor_cmd=egrc_editor_cmd, ) return result