Skip to content

Commit

Permalink
TST: TemplateConfiguration fixture and basic test
Browse files Browse the repository at this point in the history
  • Loading branch information
tangkong committed May 25, 2024
1 parent 2cd48b3 commit 764850a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
23 changes: 22 additions & 1 deletion atef/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
from atef.check import Equals, Greater, GreaterOrEqual, LessOrEqual, NotEquals
from atef.config import (AnyConfiguration, ConfigurationFile,
ConfigurationGroup, DeviceConfiguration,
PVConfiguration, ToolConfiguration)
PVConfiguration, TemplateConfiguration,
ToolConfiguration)
from atef.find_replace import RegexFindReplace
from atef.procedure import AnyProcedure, ProcedureFile
from atef.tools import Ping
from atef.type_hints import AnyDataclass
Expand Down Expand Up @@ -380,6 +382,25 @@ def tool_configuration():
return group


@pytest.fixture
def template_configuration():
replace_title_path = [
('atef.config.ConfigurationFile', 'root'),
('atef.config.ConfigurationGroup', 'name')
]
replace_title_edit = RegexFindReplace(
path=replace_title_path,
search_regex='root',
replace_text='template replaced title'
)
group = TemplateConfiguration(
name='template all fields',
filename=CONFIG_PATH / 'blank_passive.json',
edits=[replace_title_edit],
)
return group


@pytest.fixture
def comparison_page():
comp = Equals(value=3)
Expand Down
12 changes: 11 additions & 1 deletion atef/tests/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import pytest

from atef.config import (ConfigurationFile, DeviceConfiguration, PreparedFile,
PVConfiguration)
PreparedTemplateConfiguration, PVConfiguration,
TemplateConfiguration)
from atef.type_hints import AnyDataclass
from atef.widgets.config.utils import get_relevant_pvs

Expand Down Expand Up @@ -50,3 +51,12 @@ def test_gather_pvs(
readback_comp = device_configuration.by_attr['readback'][0]
assert len(get_relevant_pvs(setpoint_comp, device_configuration)) == 2
assert len(get_relevant_pvs(readback_comp, device_configuration)) == 2


def test_template_configuration(template_configuration: TemplateConfiguration):
assert len(template_configuration.edits) == 1

# prepare and verify changes were applied
ptc = PreparedTemplateConfiguration.from_config(template_configuration)

assert ptc.file.root.config.name == 'template replaced title'

0 comments on commit 764850a

Please sign in to comment.