Commit 4ac29b53f5682c474b6f65c32ae7b40f820536c0
1 parent
63546685
unittest: add .csv to list of files to be ignored
Replace #print(...) with DEBUG_FLAG and conditional print(...)
Showing
1 changed file
with
15 additions
and
5 deletions
tests/ooxml/test_basic.py
| ... | ... | @@ -12,24 +12,33 @@ from oletools import ooxml |
| 12 | 12 | class TestOOXML(unittest.TestCase): |
| 13 | 13 | """ Tests my cool new feature """ |
| 14 | 14 | |
| 15 | + DO_DEBUG = False | |
| 16 | + | |
| 15 | 17 | def test_all_rough(self): |
| 16 | 18 | """Checks all samples, expect either ole files or good ooxml output""" |
| 17 | 19 | acceptable = ooxml.DOCTYPE_EXCEL, ooxml.DOCTYPE_WORD, \ |
| 18 | 20 | ooxml.DOCTYPE_POWERPOINT |
| 21 | + | |
| 22 | + # files that are neither OLE nor xml: | |
| 19 | 23 | except_files = 'empty', 'text' |
| 20 | - except_extns = '.xml', '.rtf' | |
| 24 | + except_extns = '.xml', '.rtf', '.csv' | |
| 25 | + | |
| 26 | + # analyse all files in data dir | |
| 21 | 27 | for base_dir, _, files in os.walk(DATA_BASE_DIR): |
| 22 | 28 | for filename in files: |
| 23 | 29 | if filename in except_files: |
| 24 | - #print('skip file: ' + filename) | |
| 30 | + if self.DO_DEBUG: | |
| 31 | + print('skip file: ' + filename) | |
| 25 | 32 | continue |
| 26 | 33 | if splitext(filename)[1] in except_extns: |
| 27 | - #print('skip extn: ' + filename) | |
| 34 | + if self.DO_DEBUG: | |
| 35 | + print('skip extn: ' + filename) | |
| 28 | 36 | continue |
| 29 | 37 | |
| 30 | 38 | full_name = join(base_dir, filename) |
| 31 | 39 | if isOleFile(full_name): |
| 32 | - #print('skip ole: ' + filename) | |
| 40 | + if self.DO_DEBUG: | |
| 41 | + print('skip ole: ' + filename) | |
| 33 | 42 | continue |
| 34 | 43 | try: |
| 35 | 44 | doctype = ooxml.get_type(full_name) |
| ... | ... | @@ -38,7 +47,8 @@ class TestOOXML(unittest.TestCase): |
| 38 | 47 | self.assertTrue(doctype in acceptable, |
| 39 | 48 | msg='Doctype "{0}" for {1} not acceptable' |
| 40 | 49 | .format(doctype, full_name)) |
| 41 | - #print('ok: ' + filename + doctype) | |
| 50 | + if self.DO_DEBUG: | |
| 51 | + print('ok: {0} --> {1}'.format(filename, doctype)) | |
| 42 | 52 | |
| 43 | 53 | |
| 44 | 54 | # just in case somebody calls this file as a script | ... | ... |