From 333f899440e05ca0f96c21233941832960bba43b Mon Sep 17 00:00:00 2001 From: Bryce Kalmbach Date: Mon, 1 Mar 2021 16:59:26 -0800 Subject: [PATCH] Make tests thread-safe. --- python/lsst/ts/wep/CreatePhosimDonutTemplates.py | 13 +++++++++++++ tests/test_createPhosimDonutTemplates.py | 9 +++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/python/lsst/ts/wep/CreatePhosimDonutTemplates.py b/python/lsst/ts/wep/CreatePhosimDonutTemplates.py index 88c680323..cb961cc90 100644 --- a/python/lsst/ts/wep/CreatePhosimDonutTemplates.py +++ b/python/lsst/ts/wep/CreatePhosimDonutTemplates.py @@ -51,6 +51,19 @@ def __init__(self): # The location where we will store the final templates self.templateDestDir = os.path.join(self.templateDataPath, "phosimTemplates") + def setTempWorkPaths(self, newBasePath): + """ + Point to a new temporary work directory. Update work repo as well. + + Parameters + ---------- + newBasePath : str + New location of temporary work directories. + """ + + self.tempWorkPath = newBasePath + self.repoDir = os.path.join(self.tempWorkPath, 'input') + def createWorkDirectories(self): """ Create the final template directory as well as diff --git a/tests/test_createPhosimDonutTemplates.py b/tests/test_createPhosimDonutTemplates.py index 80bdc123f..1ba6dde93 100644 --- a/tests/test_createPhosimDonutTemplates.py +++ b/tests/test_createPhosimDonutTemplates.py @@ -22,6 +22,7 @@ import unittest import os import shutil +import tempfile import numpy as np from lsst.ts.wep.CreatePhosimDonutTemplates import CreatePhosimDonutTemplates @@ -41,9 +42,9 @@ def setUp(self): # Location where templates are created 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) + self.tempTestDirectory = tempfile.TemporaryDirectory() + self.tempWorkDir = self.tempTestDirectory.name + self.createPhosimDonuts.setTempWorkPaths(self.tempWorkDir) def tearDown(self): @@ -54,7 +55,7 @@ def tearDown(self): pass # Remove work directory in case of clean up method test failure - shutil.rmtree(self.tempWorkDir) + self.tempTestDirectory.cleanup() def _copyPhosimFiles(self):