diff --git a/exopy/measurement/hooks/internal_checks.py b/exopy/measurement/hooks/internal_checks.py index a137b73b..90639c4d 100644 --- a/exopy/measurement/hooks/internal_checks.py +++ b/exopy/measurement/hooks/internal_checks.py @@ -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') diff --git a/tests/measurement/hooks/test_internal_checks.py b/tests/measurement/hooks/test_internal_checks.py index bf2bfaf9..15814302 100644 --- a/tests/measurement/hooks/test_internal_checks.py +++ b/tests/measurement/hooks/test_internal_checks.py @@ -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):