Skip to content

Commit

Permalink
Clean up test tearDown.
Browse files Browse the repository at this point in the history
  • Loading branch information
jbkalmbach committed Mar 1, 2021
1 parent 7a5c74f commit 018e461
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions tests/test_createPhosimDonutTemplates.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def setUp(self):
self.templateDir = os.path.join(self.templateDataDir, "phosimTemplates")
# Temporary work directory
self.tempWorkDir = os.path.join(self.templateDataDir, "tempDir")
# Make the temporary directory for all tests
os.mkdir(self.tempWorkDir)

def tearDown(self):

Expand All @@ -52,10 +54,7 @@ def tearDown(self):
pass

# Remove work directory in case of clean up method test failure
try:
shutil.rmtree(self.tempWorkDir)
except FileNotFoundError:
pass
shutil.rmtree(self.tempWorkDir)

def _copyPhosimFiles(self):

Expand All @@ -74,24 +73,24 @@ def _copyPhosimFiles(self):
os.path.join(
self.testDataDir,
"testDonutTemplates",
"centroid_lsst_e_9006001_f1_R99_S11_E000.txt"
"centroid_lsst_e_9006001_f1_R99_S11_E000.txt",
),
os.path.join(self.tempWorkDir, "phosimOutput", "extra")
os.path.join(self.tempWorkDir, "phosimOutput", "extra"),
)

def testCreateAndCleanUpWorkDirectories(self):

# Test clean up of work directories
self.createPhosimDonuts.cleanUpWorkDirs()
self.assertFalse(os.path.exists(self.tempWorkDir))

# Test creation of work directories
self.createPhosimDonuts.createWorkDirectories()
self.assertTrue(os.path.exists(self.tempWorkDir))
self.assertTrue(
os.path.exists(os.path.join(self.tempWorkDir, "phosimOutput", "extra"))
)

# Test clean up of work directories
self.createPhosimDonuts.cleanUpWorkDirs()
self.assertFalse(os.path.exists(self.tempWorkDir))

def testCreateDetectorLists(self):

testDetectors = "R22_S00 R22_S11"
Expand Down Expand Up @@ -123,7 +122,6 @@ def testIngestImages(self):
)
)
)
self.createPhosimDonuts.cleanUpWorkDirs()

def testMakeFlatsAndIngest(self):

Expand All @@ -138,7 +136,6 @@ def testMakeFlatsAndIngest(self):
self.assertTrue(
os.path.exists(os.path.join(self.tempWorkDir, "input", "flat", "g"))
)
self.createPhosimDonuts.cleanUpWorkDirs()

def testRunISR(self):

Expand All @@ -164,7 +161,6 @@ def testRunISR(self):
)
)
)
self.createPhosimDonuts.cleanUpWorkDirs()

def testCutOutTemplatesAndSave(self):

Expand All @@ -176,10 +172,7 @@ def testCutOutTemplatesAndSave(self):
self._copyPhosimFiles()

self.createPhosimDonuts.cutOutTemplatesAndSave(
testPhosimPath,
240,
DefocalType.Extra,
9006001,
testPhosimPath, 240, DefocalType.Extra, 9006001,
)

newTemplate = np.genfromtxt(
Expand All @@ -191,7 +184,6 @@ def testCutOutTemplatesAndSave(self):
)
)
np.testing.assert_array_equal(newTemplate, trueTemplate)
self.createPhosimDonuts.cleanUpWorkDirs()


if __name__ == "__main__":
Expand Down

0 comments on commit 018e461

Please sign in to comment.