Commit 9ef736929f9b308edcf379b33687b6350903d8d7

Authored by Christian Herdtweck
1 parent f2d2fe46

unittest: move definition of data base dir to utils package

tests/json/test_output.py
@@ -9,9 +9,9 @@ import unittest @@ -9,9 +9,9 @@ import unittest
9 import sys 9 import sys
10 import json 10 import json
11 import os 11 import os
12 -from os.path import join, dirname, normpath 12 +from os.path import join
13 from oletools import msodde 13 from oletools import msodde
14 -from tests.test_utils import OutputCapture 14 +from tests.test_utils import OutputCapture, DATA_BASE_DIR
15 15
16 if sys.version_info[0] <= 2: 16 if sys.version_info[0] <= 2:
17 from oletools import olevba 17 from oletools import olevba
@@ -19,16 +19,12 @@ else: @@ -19,16 +19,12 @@ else:
19 from oletools import olevba3 as olevba 19 from oletools import olevba3 as olevba
20 20
21 21
22 -# Directory with test data, independent of current working directory  
23 -DATA_DIR = normpath(join(dirname(__file__), '..', 'test-data'))  
24 -  
25 -  
26 class TestValidJson(unittest.TestCase): 22 class TestValidJson(unittest.TestCase):
27 """ Ensure that script output is valid json (if return code is 0) """ 23 """ Ensure that script output is valid json (if return code is 0) """
28 24
29 def iter_test_files(self): 25 def iter_test_files(self):
30 - """ Iterate over all test files in DATA_DIR """  
31 - for dirpath, _, filenames in os.walk(DATA_DIR): 26 + """ Iterate over all test files in DATA_BASE_DIR """
  27 + for dirpath, _, filenames in os.walk(DATA_BASE_DIR):
32 for filename in filenames: 28 for filename in filenames:
33 yield join(dirpath, filename) 29 yield join(dirpath, filename)
34 30
tests/msodde_doc/test_basic.py
@@ -10,16 +10,12 @@ from __future__ import print_function @@ -10,16 +10,12 @@ from __future__ import print_function
10 10
11 import unittest 11 import unittest
12 from oletools import msodde 12 from oletools import msodde
13 -from tests.test_utils import OutputCapture 13 +from tests.test_utils import OutputCapture, DATA_BASE_DIR as BASE_DIR
14 import shlex 14 import shlex
15 -from os.path import join, dirname, normpath 15 +from os.path import join
16 from traceback import print_exc 16 from traceback import print_exc
17 17
18 18
19 -# base directory for test input  
20 -BASE_DIR = normpath(join(dirname(__file__), '..', 'test-data'))  
21 -  
22 -  
23 class TestReturnCode(unittest.TestCase): 19 class TestReturnCode(unittest.TestCase):
24 20
25 def test_valid_doc(self): 21 def test_valid_doc(self):
tests/test_utils/__init__.py
1 from .output_capture import OutputCapture 1 from .output_capture import OutputCapture
  2 +
  3 +from os.path import dirname, join
  4 +
  5 +# Directory with test data, independent of current working directory
  6 +DATA_BASE_DIR = join(dirname(dirname(__file__)), 'test-data')