From 86da39543df0defc2a9512368ab243eb1ecc5e14 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Fri, 7 Apr 2017 17:13:24 +0200 Subject: [PATCH] Testing --- pp_lib/differ.py | 3 ++ test/files/base.ini | 62 ++++++++++++++++++++++++++++++++++ test/files/blanklines.ini | 71 +++++++++++++++++++++++++++++++++++++++ test/files/clone.ini | 62 ++++++++++++++++++++++++++++++++++ test/files/comments.ini | 62 ++++++++++++++++++++++++++++++++++ test/files/ignorecase.ini | 62 ++++++++++++++++++++++++++++++++++ test/files/withespace.ini | 62 ++++++++++++++++++++++++++++++++++ test/general.py | 2 ++ test/test_differ.py | 39 +++++++++++++++++++++ 9 files changed, 425 insertions(+) create mode 100644 test/files/base.ini create mode 100644 test/files/blanklines.ini create mode 100644 test/files/clone.ini create mode 100644 test/files/comments.ini create mode 100644 test/files/ignorecase.ini create mode 100644 test/files/withespace.ini diff --git a/pp_lib/differ.py b/pp_lib/differ.py index 98609e8..085e22a 100644 --- a/pp_lib/differ.py +++ b/pp_lib/differ.py @@ -64,6 +64,9 @@ class ConfigDiffer(Differ): self.ignore_comment = ignore_comment self.case_insensitive = case_insensitive + if self.ignore_comment: + self.ignore_empty = True + if comment_chars: if isinstance(comment_chars, (list, set, tuple)): for char in comment_chars: diff --git a/test/files/base.ini b/test/files/base.ini new file mode 100644 index 0000000..f0096f0 --- /dev/null +++ b/test/files/base.ini @@ -0,0 +1,62 @@ +[core] +; some core components +s0_active_plugins = core;composite;opengl;compiztoolbox;copytex;decor;imgpng;cube;gnomecompat;regex;rotate;move;resize;grid;commands;staticswitcher;animation;expo;wobbly; +s0_hsize = 4 +s0_focus_prevention_level = 1 +s0_focus_prevention_match = !(class=Polkit-gnome-authentication-agent-1) & !(class=MintMenu.py) + +[gnomecompat] +# Gnome compatibility +s0_command_screenshot = mate-screenshot +s0_command_window_screenshot = mate-screenshot --window +s0_command_terminal = mate-terminal + +[crashhandler] +s0_wm_cmd = marco --replace + +[grid] +s0_top_left_corner_action = 7 +s0_top_right_corner_action = 9 +s0_bottom_left_corner_action = 1 +s0_bottom_right_corner_action = 3 +s0_bottom_edge_action = 2 +s0_top_edge_action = 8 +s0_outline_color = #84fb009f +s0_fill_color = #74fb004f + +[resize] +# Colors on resizing +s0_border_color = #7dfb009f +s0_fill_color = #8afb0019 + +[expo] +s0_selected_color = #000000ff +s0_reflection = true +s0_expo_key = Up + +[wall] +s0_up_key = Disabled +s0_down_key = Disabled + +[animation] +; Animation effects +s0_unminimize_effects = +s0_unminimize_durations = +s0_unminimize_matches = +s0_unminimize_options = +s0_unminimize_random_effects = + +[cube] +s0_top_color = #3c3c3cff +s0_bottom_color = #3c3c3cff +s0_skydome = true +s0_skydome_gradient_start_color = #000000ff +s0_skydome_gradient_end_color = #727272ff + +[staticswitcher] +s0_prev-all-key = Tab +s0_next-all-key = Tab + +[td] + + diff --git a/test/files/blanklines.ini b/test/files/blanklines.ini new file mode 100644 index 0000000..74fb8e6 --- /dev/null +++ b/test/files/blanklines.ini @@ -0,0 +1,71 @@ +[core] +; some core components + +s0_active_plugins = core;composite;opengl;compiztoolbox;copytex;decor;imgpng;cube;gnomecompat;regex;rotate;move;resize;grid;commands;staticswitcher;animation;expo;wobbly; +s0_hsize = 4 +s0_focus_prevention_level = 1 +s0_focus_prevention_match = !(class=Polkit-gnome-authentication-agent-1) & !(class=MintMenu.py) + +[gnomecompat] +# Gnome compatibility + +s0_command_screenshot = mate-screenshot +s0_command_window_screenshot = mate-screenshot --window +s0_command_terminal = mate-terminal + +[crashhandler] + +s0_wm_cmd = marco --replace + +[grid] + +s0_top_left_corner_action = 7 +s0_top_right_corner_action = 9 +s0_bottom_left_corner_action = 1 +s0_bottom_right_corner_action = 3 +s0_bottom_edge_action = 2 +s0_top_edge_action = 8 +s0_outline_color = #84fb009f +s0_fill_color = #74fb004f + +[resize] +# Colors on resizing + +s0_border_color = #7dfb009f +s0_fill_color = #8afb0019 + +[expo] + +s0_selected_color = #000000ff +s0_reflection = true +s0_expo_key = Up + +[wall] + +s0_up_key = Disabled +s0_down_key = Disabled + +[animation] +; Animation effects + +s0_unminimize_effects = +s0_unminimize_durations = +s0_unminimize_matches = +s0_unminimize_options = +s0_unminimize_random_effects = + +[cube] + +s0_top_color = #3c3c3cff +s0_bottom_color = #3c3c3cff +s0_skydome = true +s0_skydome_gradient_start_color = #000000ff +s0_skydome_gradient_end_color = #727272ff + +[staticswitcher] + +s0_prev-all-key = Tab +s0_next-all-key = Tab + +[td] + diff --git a/test/files/clone.ini b/test/files/clone.ini new file mode 100644 index 0000000..f0096f0 --- /dev/null +++ b/test/files/clone.ini @@ -0,0 +1,62 @@ +[core] +; some core components +s0_active_plugins = core;composite;opengl;compiztoolbox;copytex;decor;imgpng;cube;gnomecompat;regex;rotate;move;resize;grid;commands;staticswitcher;animation;expo;wobbly; +s0_hsize = 4 +s0_focus_prevention_level = 1 +s0_focus_prevention_match = !(class=Polkit-gnome-authentication-agent-1) & !(class=MintMenu.py) + +[gnomecompat] +# Gnome compatibility +s0_command_screenshot = mate-screenshot +s0_command_window_screenshot = mate-screenshot --window +s0_command_terminal = mate-terminal + +[crashhandler] +s0_wm_cmd = marco --replace + +[grid] +s0_top_left_corner_action = 7 +s0_top_right_corner_action = 9 +s0_bottom_left_corner_action = 1 +s0_bottom_right_corner_action = 3 +s0_bottom_edge_action = 2 +s0_top_edge_action = 8 +s0_outline_color = #84fb009f +s0_fill_color = #74fb004f + +[resize] +# Colors on resizing +s0_border_color = #7dfb009f +s0_fill_color = #8afb0019 + +[expo] +s0_selected_color = #000000ff +s0_reflection = true +s0_expo_key = Up + +[wall] +s0_up_key = Disabled +s0_down_key = Disabled + +[animation] +; Animation effects +s0_unminimize_effects = +s0_unminimize_durations = +s0_unminimize_matches = +s0_unminimize_options = +s0_unminimize_random_effects = + +[cube] +s0_top_color = #3c3c3cff +s0_bottom_color = #3c3c3cff +s0_skydome = true +s0_skydome_gradient_start_color = #000000ff +s0_skydome_gradient_end_color = #727272ff + +[staticswitcher] +s0_prev-all-key = Tab +s0_next-all-key = Tab + +[td] + + diff --git a/test/files/comments.ini b/test/files/comments.ini new file mode 100644 index 0000000..aaf51c7 --- /dev/null +++ b/test/files/comments.ini @@ -0,0 +1,62 @@ +[core] +s0_active_plugins = core;composite;opengl;compiztoolbox;copytex;decor;imgpng;cube;gnomecompat;regex;rotate;move;resize;grid;commands;staticswitcher;animation;expo;wobbly; +s0_hsize = 4 +s0_focus_prevention_level = 1 +s0_focus_prevention_match = !(class=Polkit-gnome-authentication-agent-1) & !(class=MintMenu.py) + +[gnomecompat] +# Gnome compatibility +s0_command_screenshot = mate-screenshot +s0_command_window_screenshot = mate-screenshot --window +s0_command_terminal = mate-terminal + +[crashhandler] +# crashhandler stuff +s0_wm_cmd = marco --replace + +[grid] +s0_top_left_corner_action = 7 +s0_top_right_corner_action = 9 +s0_bottom_left_corner_action = 1 +s0_bottom_right_corner_action = 3 +s0_bottom_edge_action = 2 +s0_top_edge_action = 8 +s0_outline_color = #84fb009f +s0_fill_color = #74fb004f + +[resize] +; Colors on resizing +s0_border_color = #7dfb009f +s0_fill_color = #8afb0019 + +[expo] +s0_selected_color = #000000ff +s0_reflection = true +s0_expo_key = Up + +[wall] +s0_up_key = Disabled +s0_down_key = Disabled + +[animation] +; Animation effects +s0_unminimize_effects = +s0_unminimize_durations = +s0_unminimize_matches = +s0_unminimize_options = +s0_unminimize_random_effects = + +[cube] +s0_top_color = #3c3c3cff +s0_bottom_color = #3c3c3cff +s0_skydome = true +s0_skydome_gradient_start_color = #000000ff +s0_skydome_gradient_end_color = #727272ff + +[staticswitcher] +s0_prev-all-key = Tab +s0_next-all-key = Tab + +[td] + +# vim: et filetype=dosini diff --git a/test/files/ignorecase.ini b/test/files/ignorecase.ini new file mode 100644 index 0000000..ae21c11 --- /dev/null +++ b/test/files/ignorecase.ini @@ -0,0 +1,62 @@ +[core] +; some core components +s0_active_plugins = core;composite;opengl;compiztoolbox;copytex;decor;imgpng;cube;gnomecompat;regex;rotate;move;resize;grid;commands;staticswitcher;animation;expo;wobbly; +s0_hsize = 4 +s0_focus_prevention_level = 1 +s0_focus_prevention_match = !(class=Polkit-gnome-authentication-agent-1) & !(class=MintMenu.py) + +[gnomecompat] +# Gnome compatibility +s0_command_screenshot = mate-screenshot +s0_command_window_screenshot = mate-screenshot --window +s0_command_terminal = mate-terminal + +[crashhandler] +s0_wm_cmd = marco --replace + +[grid] +s0_top_left_corner_action = 7 +s0_top_right_corner_action = 9 +s0_bottom_left_corner_action = 1 +s0_bottom_right_corner_action = 3 +s0_bottom_edge_action = 2 +s0_top_edge_action = 8 +s0_outline_color = #84fb009f +s0_fill_color = #74fb004f + +[resize] +# colors on resizing +s0_border_color = #7dfb009f +s0_fill_color = #8afb0019 + +[expo] +s0_selected_color = #000000ff +s0_reflection = true +s0_expo_key = Up + +[wall] +s0_up_key = Disabled +s0_down_key = Disabled + +[animation] +; animation effects +s0_unminimize_effects = +s0_unminimize_durations = +s0_unminimize_matches = +s0_unminimize_options = +s0_unminimize_random_effects = + +[cube] +s0_top_color = #3c3c3cff +s0_bottom_color = #3c3c3cff +s0_skydome = true +s0_skydome_gradient_start_color = #000000ff +s0_skydome_gradient_end_color = #727272ff + +[staticswitcher] +s0_prev-all-key = tab +s0_next-all-key = TAB + +[td] + + diff --git a/test/files/withespace.ini b/test/files/withespace.ini new file mode 100644 index 0000000..915f055 --- /dev/null +++ b/test/files/withespace.ini @@ -0,0 +1,62 @@ +[core] +; some core components +s0_active_plugins = core;composite;opengl;compiztoolbox;copytex;decor;imgpng;cube;gnomecompat;regex;rotate;move;resize;grid;commands;staticswitcher;animation;expo;wobbly; +s0_hsize = 4 +s0_focus_prevention_level = 1 +s0_focus_prevention_match = !(class=Polkit-gnome-authentication-agent-1) & !(class=MintMenu.py) + +[gnomecompat] +# Gnome compatibility +s0_command_screenshot = mate-screenshot +s0_command_window_screenshot = mate-screenshot --window +s0_command_terminal = mate-terminal + +[crashhandler] +s0_wm_cmd = marco --replace + +[grid] +s0_top_left_corner_action = 7 +s0_top_right_corner_action = 9 +s0_bottom_left_corner_action = 1 +s0_bottom_right_corner_action = 3 +s0_bottom_edge_action = 2 +s0_top_edge_action = 8 +s0_outline_color = #84fb009f +s0_fill_color = #74fb004f + +[resize] +# Colors on resizing +s0_border_color = #7dfb009f +s0_fill_color = #8afb0019 + +[expo] +s0_selected_color = #000000ff +s0_reflection = true +s0_expo_key = Up + +[wall] +s0_up_key = Disabled +s0_down_key = Disabled + +[animation] +; Animation effects +s0_unminimize_effects = +s0_unminimize_durations = +s0_unminimize_matches = +s0_unminimize_options = +s0_unminimize_random_effects = + +[cube] +s0_top_color = #3c3c3cff +s0_bottom_color = #3c3c3cff +s0_skydome = true +s0_skydome_gradient_start_color = #000000ff +s0_skydome_gradient_end_color = #727272ff + +[staticswitcher] +s0_prev-all-key = Tab +s0_next-all-key = Tab + +[td] + + diff --git a/test/general.py b/test/general.py index 8a87f10..3d58dbe 100644 --- a/test/general.py +++ b/test/general.py @@ -83,6 +83,8 @@ class AdminToolsTestcase(unittest.TestCase): super(AdminToolsTestcase, self).__init__(methodName) + self.test_dir = os.path.abspath(os.path.dirname(__file__)) + # ------------------------------------------------------------------------- @property def verbose(self): diff --git a/test/test_differ.py b/test/test_differ.py index cf31589..d1259c4 100755 --- a/test/test_differ.py +++ b/test/test_differ.py @@ -12,12 +12,15 @@ import os import sys import logging import locale +import re try: import unittest2 as unittest except ImportError: import unittest +import six + from pb_base.common import pp from pb_base.common import bytes2human @@ -40,10 +43,39 @@ class ConfigDifferTest(AdminToolsTestcase): def setUp(self): self.appname = APPNAME + self.files_dir = os.path.join(self.test_dir, 'files') + + self.cfg_base = os.path.join(self.files_dir, 'base.ini') + self.cfg_clone = os.path.join(self.files_dir, 'clone.ini') + self.cfg_blanklines = os.path.join(self.files_dir, 'blanklines.ini') + self.cfg_withespace = os.path.join(self.files_dir, 'withespace.ini') + self.cfg_comments = os.path.join(self.files_dir, 'comments.ini') + self.cfg_ignorecase = os.path.join(self.files_dir, 'ignorecase.ini') + + self.re_eol = re.compile('(?:\r|\r?\n)$') + # ------------------------------------------------------------------------- def tearDown(self): pass + # ------------------------------------------------------------------------- + def read_file(self, filename, strip_eol=False)): + + lines = [] + + open_args = {} + if six.PY3: + open_args = { + 'encoding': 'utf-8', + 'errors': 'surrogateescape', + } + + with open(filename, 'r', **open_args) as fh: + for line in fh.readlines(): + if strip_eol: + lines.append(self.re_eol.sub(line)) + else: + lines.append(line) # ------------------------------------------------------------------------- def test_import(self): @@ -123,6 +155,13 @@ class ConfigDifferTest(AdminToolsTestcase): self.assertEqual(result, expected) + # ------------------------------------------------------------------------- + def test_compare_equal(self): + + LOG.info("Testing execution of compare on equal string lists ...") + + list_a = + # ============================================================================= -- 2.39.5