Skip to content

Commit

Permalink
TST #271 test for reported bug
Browse files Browse the repository at this point in the history
  • Loading branch information
prjemian committed Jun 12, 2024
1 parent 7f2b059 commit 57bee92
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions bluesky/tests/test_newSpecFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@

import pytest
from apstools.utils import cleanupText
from instrument.callbacks.spec_data_file_writer import newSpecFile, specwriter
from spec2nexus.spec import SpecDataFile, is_spec_file
from spec2nexus.spec import SpecDataFile
from spec2nexus.spec import is_spec_file

from bluesky.run_engine import RunEngine
from instrument.callbacks.spec_data_file_writer import RE_finder
from instrument.callbacks.spec_data_file_writer import newSpecFile
from instrument.callbacks.spec_data_file_writer import specwriter

INITIAL_SCAN_ID = 1234
RE = RunEngine(dict(scan_id=INITIAL_SCAN_ID))
Expand Down Expand Up @@ -61,6 +64,37 @@ def test_newSpecFile(title, scan_id, tempdir):
assert isinstance(specwriter.spec_filename, pathlib.Path)


@pytest.mark.parametrize("scan_id", [1, 2, 3, INITIAL_SCAN_ID - 1, INITIAL_SCAN_ID + 1])
def test_issue_271(scan_id, tempdir):
"""newSpecFile("title", scan_id=1) did not reset scan id."""
found_RE = RE_finder() # Won't find the one in this module's globals()
assert found_RE is None

RE = RunEngine() # define for this function, so it can be found
found_RE = RE_finder()
assert found_RE is not None
assert found_RE == RE

assert isinstance(scan_id, int)
assert tempdir.exists()
os.chdir(tempdir) # newSpecFile() works in pwd

RE.md["scan_id"] = INITIAL_SCAN_ID
assert RE.md["scan_id"] == INITIAL_SCAN_ID

newSpecFile("title", scan_id=scan_id, RE=RE)
assert RE.md["scan_id"] != INITIAL_SCAN_ID
assert RE.md["scan_id"] == scan_id

# repeat, without passing RE as parameter
RE.md["scan_id"] = INITIAL_SCAN_ID
assert RE.md["scan_id"] == INITIAL_SCAN_ID

newSpecFile("title", scan_id=scan_id)
assert RE.md["scan_id"] != INITIAL_SCAN_ID
assert RE.md["scan_id"] == scan_id


def test_newSpecFile_with_existing(tempdir):
assert tempdir.exists()
os.chdir(tempdir) # newSpecFile() works in pwd
Expand Down

0 comments on commit 57bee92

Please sign in to comment.