Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change tempdirs in test #657

Merged
merged 2 commits into from
Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 3 additions & 5 deletions tests/test_saving.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import strax
from strax.testutils import Records, Peaks
import os
import shutil
import tempfile


Expand All @@ -11,16 +10,15 @@ class TestPerRunDefaults(unittest.TestCase):
def setUp(self):
self.test_run_id = '0'
self.target = 'records'
self.path = os.path.join(tempfile.gettempdir(), 'strax_data')
self.tempdir = tempfile.TemporaryDirectory()
self.path = self.tempdir.name
self.st = strax.Context(use_per_run_defaults=True,
register=[Records],
storage=[strax.DataDirectory(self.path)])
assert not self.st.is_stored(self.test_run_id, self.target)

def tearDown(self):
if os.path.exists(self.path):
print(f'rm {self.path}')
shutil.rmtree(self.path)
self.tempdir.cleanup()

def test_savewhen_never(self, **kwargs):
self.set_save_when('NEVER')
Expand Down
17 changes: 7 additions & 10 deletions tests/test_storage.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from unittest import TestCase, skipIf
from unittest import TestCase
import strax
from strax.testutils import Records
import os
import shutil
import tempfile
import numpy as np
import typing as ty
Expand All @@ -15,15 +14,14 @@ class TestPerRunDefaults(TestCase):
"""

def setUp(self):
self.path = os.path.join(tempfile.gettempdir(), 'strax_data')
self.tempdir = tempfile.TemporaryDirectory()
self.path = self.tempdir.name
self.st = strax.Context(use_per_run_defaults=True,
register=[Records], )
self.target = 'records'

def tearDown(self):
if os.path.exists(self.path):
print(f'rm {self.path}')
shutil.rmtree(self.path)
self.tempdir.cleanup()

def test_write_data_dir(self):
self.st.storage = [strax.DataDirectory(self.path)]
Expand Down Expand Up @@ -85,13 +83,12 @@ class TestStorageType(TestCase):
@classmethod
def setUpClass(cls) -> None:
"""Get a temp directory available of all the tests"""
cls.path = os.path.join(tempfile.gettempdir(), 'strax_data')
cls.tempdir = tempfile.TemporaryDirectory()
cls.path = cls.tempdir.name

def tearDown(self):
"""After each test, delete the temporary directory"""
if os.path.exists(self.path):
print(f'rm {self.path}')
shutil.rmtree(self.path)
self.tempdir.cleanup()

def _sub_dir(self, subdir: str) -> str:
return os.path.join(self.path, subdir)
Expand Down