Skip to content

Commit c1d80c8

Browse files
committed
make test for naming convention
1 parent f229d5d commit c1d80c8

File tree

1 file changed

+76
-1
lines changed

1 file changed

+76
-1
lines changed

tests/backends/epics/test_ioc.py

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
from fastcs.backends.epics.ioc import (
88
EPICS_MAX_NAME_LENGTH,
99
EpicsIOC,
10+
EpicsIOCOptions,
1011
_add_pvi_info,
1112
_get_input_record,
1213
_get_output_record,
1314
)
14-
from fastcs.controller import Controller
15+
from fastcs.backends.epics.util import EpicsNameOptions, PvNamingConvention
16+
from fastcs.controller import Controller, SubController
1517
from fastcs.cs_methods import Command
1618
from fastcs.datatypes import Int, String
1719
from fastcs.exceptions import FastCSException
@@ -461,3 +463,76 @@ def test_long_pv_names_discarded(mocker: MockerFixture):
461463
always_update=True,
462464
on_update=mocker.ANY,
463465
)
466+
467+
468+
class FooSubController(SubController):
469+
def __init__(self):
470+
self.foo_bar_2 = AttrR(Int())
471+
super().__init__()
472+
473+
474+
class FooController(Controller):
475+
def __init__(self):
476+
self.foo_bar_1 = AttrR(Int())
477+
self.sub_controller = FooSubController()
478+
super().__init__()
479+
self.register_sub_controller("sub_controller", self.sub_controller)
480+
481+
482+
@pytest.mark.parametrize(
483+
("naming_convention", "separator", "foo_bar_1", "sub_controller", "foo_bar_2"),
484+
[
485+
(
486+
PvNamingConvention.NO_CONVERSION,
487+
"&",
488+
f"{DEVICE}&foo_bar_1",
489+
f"{DEVICE}&sub_controller&PVI",
490+
f"{DEVICE}&sub_controller&foo_bar_2",
491+
),
492+
(
493+
PvNamingConvention.PASCAL,
494+
":",
495+
f"{DEVICE}:FooBar1",
496+
f"{DEVICE}:SubController:PVI",
497+
f"{DEVICE}:SubController:FooBar2",
498+
),
499+
(
500+
PvNamingConvention.CAPITALIZED,
501+
":",
502+
f"{DEVICE}:FOO-BAR-1",
503+
f"{DEVICE}:SUB-CONTROLLER:PVI",
504+
f"{DEVICE}:SUB-CONTROLLER:FOO-BAR-2",
505+
),
506+
(
507+
PvNamingConvention.CAPITALIZED_CONTROLLER_PASCAL_ATTRIBUTE,
508+
":",
509+
f"{DEVICE}:FooBar1",
510+
f"{DEVICE}:SUB-CONTROLLER:PVI",
511+
f"{DEVICE}:SUB-CONTROLLER:FooBar2",
512+
),
513+
],
514+
)
515+
def test_pv_naming_conventions(
516+
mocker: MockerFixture,
517+
naming_convention: PvNamingConvention,
518+
separator: str,
519+
foo_bar_1: str,
520+
sub_controller: str,
521+
foo_bar_2: str,
522+
):
523+
options = EpicsIOCOptions(
524+
name_options=EpicsNameOptions(
525+
pv_naming_convention=naming_convention, pv_separator=separator
526+
)
527+
)
528+
builder = mocker.patch("fastcs.backends.epics.ioc.builder")
529+
controller = FooController()
530+
mapping = Mapping(controller)
531+
EpicsIOC(DEVICE, mapping, options=options)
532+
builder.longIn.assert_any_call(foo_bar_1)
533+
builder.longIn.assert_any_call(foo_bar_2)
534+
builder.longStringIn.assert_any_call(
535+
f"{sub_controller}_PV",
536+
initial_value=f"{sub_controller}",
537+
DESC="The records in this controller",
538+
)

0 commit comments

Comments
 (0)