|
7 | 7 | from fastcs.backends.epics.ioc import ( |
8 | 8 | EPICS_MAX_NAME_LENGTH, |
9 | 9 | EpicsIOC, |
| 10 | + EpicsIOCOptions, |
10 | 11 | _add_pvi_info, |
11 | 12 | _get_input_record, |
12 | 13 | _get_output_record, |
13 | 14 | ) |
14 | | -from fastcs.controller import Controller |
| 15 | +from fastcs.backends.epics.util import EpicsNameOptions, PvNamingConvention |
| 16 | +from fastcs.controller import Controller, SubController |
15 | 17 | from fastcs.cs_methods import Command |
16 | 18 | from fastcs.datatypes import Int, String |
17 | 19 | from fastcs.exceptions import FastCSException |
@@ -461,3 +463,76 @@ def test_long_pv_names_discarded(mocker: MockerFixture): |
461 | 463 | always_update=True, |
462 | 464 | on_update=mocker.ANY, |
463 | 465 | ) |
| 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