I am writing production code that parses a large file, which itself contains many different cases. To unittest the production code, I want to write a test case for each case. My question case is what a good way is to set up the testing directory and the testing code.
The current directory structure is:
root/
src/
parser.py
test/
test_parser.py
raw/
case_1.csv
case_2.csv
...
The testing code looks like this:
from parser import parse
import unittest import TestCase
class Test_Parser(TestCase):
def setUp(self):
raw_dir = 'raw'
def test_case_1(self):
filename = self.raw_dir + '/case_1.csv'
actual = parse(filename)
# assert actual == expected
def test_case_2(self):
filename = self.raw_dir + '/case_2.csv'
actual = parser(filename)
# assert actual == expected
...
Is there a more Pythonic way to factor the directory self.raw_dir out, so that the test case is cleaner and one only has to write filename = 'case_1.csv'?
os.path.join