diff --git a/tests/test_buildingsync_asset_extractor.py b/tests/test_buildingsync_asset_extractor.py index 3f20776..8d01187 100644 --- a/tests/test_buildingsync_asset_extractor.py +++ b/tests/test_buildingsync_asset_extractor.py @@ -35,7 +35,6 @@ """ import unittest from pathlib import Path -from shutil import rmtree from buildingsync_asset_extractor.processor import BSyncProcessor @@ -46,13 +45,12 @@ def setUp(self): self.no_ns_testfile = Path(__file__).parent / 'files' / 'testfile2.xml' self.output_dir = Path(__file__).parent / 'output' self.out_file = 'testoutput.json' + self.out_file_2 = 'testoutput_2.json' self.num_assets_to_extract = 8 self.num_sections_in_testfile = 3 # create output dir - if self.output_dir.exists(): - rmtree(self.output_dir) - self.output_dir.mkdir(parents=True) + self.output_dir.mkdir(parents=True, exist_ok=True) print("TESTFILE: {}".format(self.testfile)) self.bp = BSyncProcessor(self.testfile) @@ -66,6 +64,9 @@ def test_initialize_and_parse(self): self.assertIsNotNone(doc) def test_extract(self): + filename = self.output_dir / self.out_file_2 + if filename.exists(): + filename.unlink() self.bp.extract() sections = self.bp.get_sections() @@ -90,6 +91,9 @@ def test_extract(self): age = next((item for item in assets if item["name"] == "Oldest Boiler"), None) self.assertEqual(age['value'], '2010') + filename = self.output_dir / self.out_file_2 + self.bp.save(filename) + def test_set_asset_defs(self): num_assets_to_extract = 9 test_assets_file = Path(__file__).parent / 'files' / 'test_asset_defs.json' @@ -130,5 +134,7 @@ def test_extract_no_ns(self): def test_save(self): filename = self.output_dir / self.out_file + if filename.exists(): + filename.unlink() self.bp.save(filename) self.assertTrue(filename.exists())