Skip to content

Commit

Permalink
Add tearDown to remove temp folder after each test function
Browse files Browse the repository at this point in the history
  • Loading branch information
dachengx committed Jan 24, 2024
1 parent e6e27fb commit 263e74b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 22 deletions.
22 changes: 15 additions & 7 deletions tests/test_FullChain.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
import os
import shutil
import unittest
import fuse
import tempfile

class TestFullChain(unittest.TestCase):

@classmethod
def setUpClass(self):
def setUpClass(cls):

self.temp_dir = tempfile.TemporaryDirectory()
cls.temp_dir = tempfile.TemporaryDirectory()

self.test_context = fuse.context.full_chain_context(output_folder = self.temp_dir.name)
cls.test_context = fuse.context.full_chain_context(output_folder = cls.temp_dir.name)

self.test_context.set_config({"path": "/project2/lgrandi/xenonnt/simulations/testing",
cls.test_context.set_config({"path": "/project2/lgrandi/xenonnt/simulations/testing",
"file_name": "pmt_neutrons_100.root",
"entry_stop": 5,
})

self.run_number = "TestRun_00000"
cls.run_number = "TestRun_00000"

@classmethod
def tearDownClass(self):
def tearDownClass(cls):

self.temp_dir.cleanup()
cls.temp_dir.cleanup()

def tearDown(self):

# self.temp_dir.cleanup()
shutil.rmtree(self.temp_dir.name)
os.makedirs(self.temp_dir.name)

def test_S1PhotonHits(self):

Expand Down
22 changes: 15 additions & 7 deletions tests/test_MicroPhysics.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
import os
import shutil
import unittest
import fuse
import tempfile

class TestMicroPhysics(unittest.TestCase):

@classmethod
def setUpClass(self):
def setUpClass(cls):

self.temp_dir = tempfile.TemporaryDirectory()
cls.temp_dir = tempfile.TemporaryDirectory()

self.test_context = fuse.context.microphysics_context(self.temp_dir.name)
cls.test_context = fuse.context.microphysics_context(cls.temp_dir.name)

self.test_context.set_config({"path": "/project2/lgrandi/xenonnt/simulations/testing",
cls.test_context.set_config({"path": "/project2/lgrandi/xenonnt/simulations/testing",
"file_name": "pmt_neutrons_100.root",
"entry_stop": 25,
})

self.run_number = "TestRun_00000"
cls.run_number = "TestRun_00000"

@classmethod
def tearDownClass(self):
def tearDownClass(cls):

self.temp_dir.cleanup()
cls.temp_dir.cleanup()

def tearDown(self):

# self.temp_dir.cleanup()
shutil.rmtree(self.temp_dir.name)
os.makedirs(self.temp_dir.name)

def test_ChunkInput(self):

Expand Down
16 changes: 8 additions & 8 deletions tests/test_deterministic_seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def test_MicroPhysics_SameSeed(self):
self.test_context_0.make(self.run_number_0, "microphysics_summary")
self.test_context_1.make(self.run_number_1, "microphysics_summary")

output_0 = self.test_context_0.get_array(self.run_number_0, "microphysics_summary")
output_1 = self.test_context_1.get_array(self.run_number_0, "microphysics_summary")
output_0 = self.test_context_0.get_array(self.run_number_0, "microphysics_summary", progress_bar=False)
output_1 = self.test_context_1.get_array(self.run_number_0, "microphysics_summary", progress_bar=False)

assert_array_equal(output_0, output_1)

Expand All @@ -50,8 +50,8 @@ def test_MicroPhysics_DifferentSeed(self):
self.test_context_0.make(self.run_number_0, "microphysics_summary")
self.test_context_1.make(self.run_number_1, "microphysics_summary")

output_0 = self.test_context_0.get_array(self.run_number_0, "microphysics_summary")
output_1 = self.test_context_1.get_array(self.run_number_1, "microphysics_summary")
output_0 = self.test_context_0.get_array(self.run_number_0, "microphysics_summary", progress_bar=False)
output_1 = self.test_context_1.get_array(self.run_number_1, "microphysics_summary", progress_bar=False)

assert_raises(AssertionError, assert_array_equal, output_0, output_1)

Expand All @@ -61,8 +61,8 @@ def test_FullChain_SameSeed(self):
self.test_context_0.make(self.run_number_0, "raw_records")
self.test_context_1.make(self.run_number_1, "raw_records")

output_0 = self.test_context_0.get_array(self.run_number_0, "raw_records")
output_1 = self.test_context_1.get_array(self.run_number_0, "raw_records")
output_0 = self.test_context_0.get_array(self.run_number_0, "raw_records", progress_bar=False)
output_1 = self.test_context_1.get_array(self.run_number_0, "raw_records", progress_bar=False)

assert_array_equal(output_0, output_1)

Expand All @@ -72,8 +72,8 @@ def test_FullChain_DifferentSeed(self):
self.test_context_0.make(self.run_number_0, "raw_records")
self.test_context_1.make(self.run_number_1, "raw_records")

output_0 = self.test_context_0.get_array(self.run_number_0, "raw_records")
output_1 = self.test_context_1.get_array(self.run_number_1, "raw_records")
output_0 = self.test_context_0.get_array(self.run_number_0, "raw_records", progress_bar=False)
output_1 = self.test_context_1.get_array(self.run_number_1, "raw_records", progress_bar=False)

assert_raises(AssertionError, assert_array_equal, output_0, output_1)

Expand Down

0 comments on commit 263e74b

Please sign in to comment.