Skip to content

Commit 0772323

Browse files
committed
Refactor setup and teardown of test
1 parent 33dc1fd commit 0772323

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

test/test.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,23 @@
1313

1414

1515
class TestMain(unittest.TestCase):
16-
def test_example(self):
17-
db_path = tempfile.mkstemp()[1]
18-
pathtraits.scan.batch("test/example", db_path, False)
16+
db_path = None
17+
db = None
18+
19+
@classmethod
20+
def setUpClass(cls):
21+
cls.db_path = tempfile.mkstemp()[1]
22+
pathtraits.scan.batch("test/example", cls.db_path, False)
23+
cls.db = pathtraits.db.TraitsDB(cls.db_path)
1924

20-
db = pathtraits.db.TraitsDB(db_path)
21-
self.assertTrue(db is not None)
25+
@classmethod
26+
def tearDownClass(cls):
27+
os.remove(cls.db_path)
28+
29+
def test_example(self):
30+
self.assertTrue(self.db is not None)
2231

23-
source = pathtraits.access.get_dict(db, "test/example/EU/de.txt")
32+
source = pathtraits.access.get_dict(self.db, "test/example/EU/de.txt")
2433
target = {
2534
"description": "Germany data",
2635
"has_sidecar_meta_file": True,
@@ -30,7 +39,7 @@ def test_example(self):
3039
for k, v in target.items():
3140
self.assertEqual(source[k], v)
3241

33-
source = pathtraits.access.get_dict(db, "test/example/EU")
42+
source = pathtraits.access.get_dict(self.db, "test/example/EU")
3443
target = {
3544
"description": "EU data",
3645
"is_example": True,
@@ -40,7 +49,7 @@ def test_example(self):
4049
for k, v in target.items():
4150
self.assertEqual(source[k], v)
4251

43-
source = pathtraits.access.get_dict(db, "test/example")
52+
source = pathtraits.access.get_dict(self.db, "test/example")
4453
target = {
4554
"description": "all data",
4655
"is_example": True,
@@ -49,10 +58,9 @@ def test_example(self):
4958
for k, v in target.items():
5059
self.assertEqual(source[k], v)
5160

52-
source = len(db.execute("SELECT * FROM data;").fetchall())
61+
source = len(self.db.execute("SELECT * FROM data;").fetchall())
5362
target = 6
5463
self.assertEqual(source, target)
55-
os.remove(db_path)
5664

5765

5866
if __name__ == "__main__":

0 commit comments

Comments
 (0)