Skip to content

Commit

Permalink
ioc/tests/pyepics: init simple test
Browse files Browse the repository at this point in the history
  • Loading branch information
minijackson committed Jul 3, 2024
1 parent 2f7bd2c commit 3e53f2e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ioc/tests/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ with pkgs.lib;
default-ioc-epics-base-3 = import ./default-ioc "3" args;
default-ioc-epics-base-7 = import ./default-ioc "7" args;

pyepics = import ./pyepics args;

support-autosave-simple = import ./support/autosave/simple args;
support-pvxs-ioc = import ./support/pvxs/ioc args;
support-pvxs-qsrv2 = import ./support/pvxs/qsrv2 args;
Expand Down
47 changes: 47 additions & 0 deletions ioc/tests/pyepics/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{pkgs, ...}: let
inherit (pkgs) epnixLib lib;
in
pkgs.nixosTest {
name = "pytest";
meta.maintainers = with epnixLib.maintainers; [minijackson];

extraPythonPackages = p: [p.pyepics];
skipTypeCheck = true;

nodes.ioc = {
imports = [
(epnixLib.testing.softIoc ''
record(ai, "AI") { }
record(stringout, "STRINGOUT") { }
'')
];
};

testScript = let
python = lib.getExe (pkgs.python3.withPackages (p: [p.pyepics]));
iocTestScript = pkgs.writeText "iocTestScript.py" ''
import os
import epics
os.environ["EPICS_CA_AUTO_ADDR_LIST"] = "NO"
os.environ["EPICS_CA_ADDR_LIST"] = "localhost"
stringout = epics.PV("STRINGOUT")
assert epics.caget("AI") == 0
assert stringout.get() == ""
assert epics.caput("AI", 42.0, wait=True) == 1
assert stringout.put("hello", wait=True) == 1
assert epics.caget("AI") == 42
assert stringout.get() == "hello"
'';
in ''
start_all()
ioc.wait_for_unit("ioc.service")
print(ioc.succeed("${python} ${iocTestScript}"))
'';
}

0 comments on commit 3e53f2e

Please sign in to comment.