Skip to content

Commit

Permalink
measurement: update internal checks to identify enqueued duplicates (#…
Browse files Browse the repository at this point in the history
…130)

* measurement: update internal checks to identify enqueued duplicates
* tests: for duplicates in enqueued measurements
  • Loading branch information
fvalmorra authored and MatthieuDartiailh committed Mar 9, 2018
1 parent 5b29cd8 commit 478a086
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
10 changes: 10 additions & 0 deletions exopy/measurement/hooks/internal_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ def check(self, workbench, **kwargs):
# Running the checks
check, errors = task.check(**kwargs)

# Check that no enqueued measurement has the same name and id as
# the one being enqueued
plugin = workbench.get_plugin('exopy.measurement')
for enq_meas in plugin.enqueued_measurements.measurements:
if meas.name == enq_meas.name and meas.id == enq_meas.id:
msg = ('A measurement with the same name and id has already '
'been enqueued: increment the id of your measurement '
'to avoid overwriting it.')
errors['enqueued-duplicate'] = msg

# Check that no measurement with the same name and id is saved in
# the default path used by the root_task.
default_filename = (meas.name + '_' + meas.id + '.meas.ini')
Expand Down
21 changes: 21 additions & 0 deletions tests/measurement/hooks/test_internal_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,27 @@ def test_attempt_to_overwrite(fake_meas, tmpdir):
res, err = fake_meas.run_checks()
assert res
assert 'exopy.internal_checks' in err
assert 'duplicate' in err['exopy.internal_checks']


def test_attempt_to_overwrite_enqueued(measurement_workbench, fake_meas,
tmpdir):
"""Test running the checks when an enqueued measurement with the same name
and id already exists.
"""
fake_meas.name = 'test'
fake_meas.id = '001'
fake_meas.root_task.default_path = str(tmpdir)

plugin = measurement_workbench.get_plugin('exopy.measurement')
plugin.enqueued_measurements.measurements.append(fake_meas)

fake_meas.dependencies.collect_runtimes()
res, err = fake_meas.run_checks()
assert res
assert 'exopy.internal_checks' in err
assert 'enqueued-duplicate' in err['exopy.internal_checks']


def test_fail_build_collection(fake_meas, tmpdir, monkeypatch):
Expand Down

0 comments on commit 478a086

Please sign in to comment.