Commit fb4a7daccb57a33ca83b9cbb981c7f15a3f3a132
Committed by
Christian Herdtweck
1 parent
aa24ab97
fix unit tests
Showing
4 changed files
with
9 additions
and
7 deletions
oletools/olevba.py
oletools/rtfobj.py
| ... | ... | @@ -701,7 +701,7 @@ def is_rtf(arg, treat_str_as_data=False): |
| 701 | 701 | if isinstance(arg, str): # could be bytes, but we assume file name |
| 702 | 702 | if treat_str_as_data: |
| 703 | 703 | try: |
| 704 | - return arg[:magic_len].encode('ascii', error='strict').lower()\ | |
| 704 | + return arg[:magic_len].encode('ascii', errors='strict').lower()\ | |
| 705 | 705 | == RTF_MAGIC |
| 706 | 706 | except UnicodeError: |
| 707 | 707 | return False | ... | ... |
tests/json/test_output.py
| ... | ... | @@ -28,7 +28,7 @@ class TestValidJson(unittest.TestCase): |
| 28 | 28 | for filename in filenames: |
| 29 | 29 | yield join(dirpath, filename) |
| 30 | 30 | |
| 31 | - def run_and_parse(self, program, args, print_output=False): | |
| 31 | + def run_and_parse(self, program, args, print_output=False, check_return_code=True): | |
| 32 | 32 | """ run single program with single file and parse output """ |
| 33 | 33 | return_code = None |
| 34 | 34 | with OutputCapture() as capturer: # capture stdout |
| ... | ... | @@ -38,7 +38,7 @@ class TestValidJson(unittest.TestCase): |
| 38 | 38 | return_code = 1 # would result in non-zero exit |
| 39 | 39 | except SystemExit as se: |
| 40 | 40 | return_code = se.code or 0 # se.code can be None |
| 41 | - if return_code is not 0: | |
| 41 | + if check_return_code and return_code is not 0: | |
| 42 | 42 | if print_output: |
| 43 | 43 | print('Command failed ({0}) -- not parsing output' |
| 44 | 44 | .format(return_code)) |
| ... | ... | @@ -82,7 +82,8 @@ class TestValidJson(unittest.TestCase): |
| 82 | 82 | def test_olevba_recurse(self): |
| 83 | 83 | """ Test olevba.py with -r """ |
| 84 | 84 | json_data = self.run_and_parse(olevba.main, |
| 85 | - ['-j', '-r', join(DATA_BASE_DIR, '*')]) | |
| 85 | + ['-j', '-r', join(DATA_BASE_DIR, '*')], | |
| 86 | + check_return_code=False) | |
| 86 | 87 | self.assertNotEqual(len(json_data), 0, |
| 87 | 88 | msg='olevba[3] returned non-zero or no output') |
| 88 | 89 | self.assertNotEqual(json_data[-1]['n_processed'], 0, | ... | ... |
tests/rtfobj/test_is_rtf.py
| ... | ... | @@ -23,9 +23,9 @@ class TestIsRtf(unittest.TestCase): |
| 23 | 23 | |
| 24 | 24 | def test_bytes(self): |
| 25 | 25 | """ test that is_rtf works with bytearray """ |
| 26 | - self.assertTrue(is_rtf(RTF_MAGIC + b'asasdffdfasdfasdfasdfasdf'), True) | |
| 27 | - self.assertTrue(is_rtf(RTF_MAGIC.upper() + b'asdffasdfasdasdff'), True) | |
| 28 | - self.assertFalse(is_rtf(b'asdfasdfasdfasdfasdfasdasdfffsdfsdfa'), True) | |
| 26 | + self.assertTrue(is_rtf(RTF_MAGIC + b'asasdffdfasdfasdfasdfasdf', True), True) | |
| 27 | + self.assertTrue(is_rtf(RTF_MAGIC.upper() + b'asdffasdfasdasdff', True), True) | |
| 28 | + self.assertFalse(is_rtf(b'asdfasdfasdfasdfasdfasdasdfffsdfsdfa', True), True) | |
| 29 | 29 | |
| 30 | 30 | def test_tuple(self): |
| 31 | 31 | """ test that is_rtf works with byte tuples """ | ... | ... |