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

fail for - run_ids #567

Merged
merged 5 commits into from
Nov 3, 2021
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
6 changes: 6 additions & 0 deletions strax/storage/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def _scan_runs(self, store_fields):

def _find(self, key, write,
allow_incomplete, fuzzy_for, fuzzy_for_options):
self.raise_if_non_compatible_run_id(key.run_id)
dirname = osp.join(self.path, str(key))
exists = os.path.exists(dirname)
bk = self.backend_key(dirname)
Expand Down Expand Up @@ -192,6 +193,11 @@ def remove(self, key):
# (which FileStore should do) is sufficient.
pass

@staticmethod
def raise_if_non_compatible_run_id(run_id):
if '-' in str(run_id):
raise ValueError("The filesystem frontend does not understand"
" run_id's with '-', please replace with '_'")

@export
def dirname_to_prefix(dirname):
Expand Down
6 changes: 5 additions & 1 deletion strax/storage/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,11 @@ def _close(self):

def backend_key_to_query(backend_key):
"""Convert backend key to queryable dictionary"""
n, d, l = backend_key.split('-')
split_key = backend_key.split('-')
if len(split_key) != 3:
raise ValueError(f'backend_key ({backend_key}) has too many "-"s,'
f' don\'t use "-" within run_ids')
n, d, l = split_key
return {'number': int(n), 'data_type': d, 'lineage_hash': l}


Expand Down
32 changes: 32 additions & 0 deletions tests/test_storage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import unittest
import strax
from strax.testutils import Records, Peaks
import os
import shutil
import tempfile


class TestPerRunDefaults(unittest.TestCase):
"""Test the saving behavior of the context"""
def setUp(self):
self.path = os.path.join(tempfile.gettempdir(), 'strax_data')
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)

def test_write_data_dir(self):
self.st.storage = [strax.DataDirectory(self.path)]
run_id = '0'
self.st.make(run_id, self.target)
assert self.st.is_stored(run_id, self.target)

def test_complain_run_id(self):
self.st.storage = [strax.DataDirectory(self.path)]
run_id = 'run-0'
with self.assertRaises(ValueError):
self.st.make(run_id, self.target)