From 3e53f2e2701df99ce7c08177ba1723ad9d81e41c Mon Sep 17 00:00:00 2001 From: Minijackson Date: Wed, 3 Jul 2024 16:06:37 +0200 Subject: [PATCH] ioc/tests/pyepics: init simple test --- ioc/tests/default.nix | 2 ++ ioc/tests/pyepics/default.nix | 47 +++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 ioc/tests/pyepics/default.nix diff --git a/ioc/tests/default.nix b/ioc/tests/default.nix index 7f7d020e..4150e7d8 100644 --- a/ioc/tests/default.nix +++ b/ioc/tests/default.nix @@ -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; diff --git a/ioc/tests/pyepics/default.nix b/ioc/tests/pyepics/default.nix new file mode 100644 index 00000000..7c11aabc --- /dev/null +++ b/ioc/tests/pyepics/default.nix @@ -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}")) + ''; + }