Commit 4ac29b53f5682c474b6f65c32ae7b40f820536c0

Authored by Christian Herdtweck
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,24 +12,33 @@ from oletools import ooxml
12 class TestOOXML(unittest.TestCase): 12 class TestOOXML(unittest.TestCase):
13 """ Tests my cool new feature """ 13 """ Tests my cool new feature """
14 14
  15 + DO_DEBUG = False
  16 +
15 def test_all_rough(self): 17 def test_all_rough(self):
16 """Checks all samples, expect either ole files or good ooxml output""" 18 """Checks all samples, expect either ole files or good ooxml output"""
17 acceptable = ooxml.DOCTYPE_EXCEL, ooxml.DOCTYPE_WORD, \ 19 acceptable = ooxml.DOCTYPE_EXCEL, ooxml.DOCTYPE_WORD, \
18 ooxml.DOCTYPE_POWERPOINT 20 ooxml.DOCTYPE_POWERPOINT
  21 +
  22 + # files that are neither OLE nor xml:
19 except_files = 'empty', 'text' 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 for base_dir, _, files in os.walk(DATA_BASE_DIR): 27 for base_dir, _, files in os.walk(DATA_BASE_DIR):
22 for filename in files: 28 for filename in files:
23 if filename in except_files: 29 if filename in except_files:
24 - #print('skip file: ' + filename) 30 + if self.DO_DEBUG:
  31 + print('skip file: ' + filename)
25 continue 32 continue
26 if splitext(filename)[1] in except_extns: 33 if splitext(filename)[1] in except_extns:
27 - #print('skip extn: ' + filename) 34 + if self.DO_DEBUG:
  35 + print('skip extn: ' + filename)
28 continue 36 continue
29 37
30 full_name = join(base_dir, filename) 38 full_name = join(base_dir, filename)
31 if isOleFile(full_name): 39 if isOleFile(full_name):
32 - #print('skip ole: ' + filename) 40 + if self.DO_DEBUG:
  41 + print('skip ole: ' + filename)
33 continue 42 continue
34 try: 43 try:
35 doctype = ooxml.get_type(full_name) 44 doctype = ooxml.get_type(full_name)
@@ -38,7 +47,8 @@ class TestOOXML(unittest.TestCase): @@ -38,7 +47,8 @@ class TestOOXML(unittest.TestCase):
38 self.assertTrue(doctype in acceptable, 47 self.assertTrue(doctype in acceptable,
39 msg='Doctype "{0}" for {1} not acceptable' 48 msg='Doctype "{0}" for {1} not acceptable'
40 .format(doctype, full_name)) 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 # just in case somebody calls this file as a script 54 # just in case somebody calls this file as a script