about summary refs log tree commit diff
path: root/pkgs/servers/home-assistant/tests.nix
diff options
context:
space:
mode:
authorRobert Schütz <nix@dotlambda.de>2022-01-15 00:20:08 +0000
committerRobert Schütz <nix@dotlambda.de>2022-01-16 00:51:45 +0000
commit61265ec0b4176678aa776d901ace3d5191728b65 (patch)
tree2efb538761d0f5d7e65d8843721f11788d322726 /pkgs/servers/home-assistant/tests.nix
parent6054fb82d5e5351d6432f57bd66de64723fe53ba (diff)
home-assistant: outsource component tests
A component's tests can now be run by building
    home-assistant.tests.components.${component}

Co-authored-by: Martin Weinelt <hexa@darmstadt.ccc.de>
Diffstat (limited to 'pkgs/servers/home-assistant/tests.nix')
-rw-r--r--pkgs/servers/home-assistant/tests.nix69
1 files changed, 69 insertions, 0 deletions
diff --git a/pkgs/servers/home-assistant/tests.nix b/pkgs/servers/home-assistant/tests.nix
new file mode 100644
index 0000000000000..8e552ed15e0b3
--- /dev/null
+++ b/pkgs/servers/home-assistant/tests.nix
@@ -0,0 +1,69 @@
+{ lib
+, home-assistant
+}:
+
+let
+  # some components' tests have additional dependencies
+  extraCheckInputs = with home-assistant.python.pkgs; {
+    alexa = [ ha-av ];
+    camera = [ ha-av ];
+    cloud = [ mutagen ];
+    config = [ pydispatcher ];
+    generic = [ ha-av ];
+    google_translate = [ mutagen ];
+    nest = [ ha-av ];
+    onboarding = [ pymetno rpi-bad-power ];
+    voicerss = [ mutagen ];
+    yandextts = [ mutagen ];
+    zha = [ pydeconz ];
+    zwave_js = [ homeassistant-pyozw ];
+  };
+
+  extraDisabledTestPaths = {
+    tado = [
+      # tado/test_{climate,water_heater}.py: Tries to connect to my.tado.com
+      "tests/components/tado/test_climate.py"
+      "tests/components/tado/test_water_heater.py"
+    ];
+  };
+
+  extraPytestFlagsArray = {
+    asuswrt = [
+      # asuswrt/test_config_flow.py: Sandbox network limitations, fails with unexpected error
+      "--deselect tests/components/asuswrt/test_config_flow.py::test_on_connect_failed"
+    ];
+  };
+in lib.listToAttrs (map (component: lib.nameValuePair component (
+  home-assistant.overridePythonAttrs (old: {
+    pname = "homeassistant-test-${component}";
+
+    dontBuild = true;
+    dontInstall = true;
+
+    checkInputs = old.checkInputs
+      ++ home-assistant.getPackages component home-assistant.python.pkgs
+      ++ extraCheckInputs.${component} or [ ];
+
+    disabledTestPaths = old.disabledTestPaths ++ extraDisabledTestPaths.${component} or [ ];
+
+    pytestFlagsArray = lib.remove "tests" old.pytestFlagsArray
+      ++ extraPytestFlagsArray.${component} or [ ]
+      ++ [ "tests/components/${component}" ];
+
+    preCheck = old.preCheck + lib.optionalString (component != "network") ''
+      patch -p1 < ${./patches/tests-mock-source-ip.patch}
+    '';
+
+    meta = old.meta // {
+      broken = lib.elem component [
+        "airtouch4"
+        "glances"
+        "ridwell"
+        "venstar"
+        "yamaha_musiccast"
+      ];
+      # upstream only tests on Linux, so do we.
+      platforms = lib.platforms.linux;
+    };
+  })
+)) home-assistant.supportedComponentsWithTests)