about summary refs log tree commit diff
path: root/pkgs/servers/home-assistant/tests.nix
blob: 989bfccb7236d5237e117d4e78cc2db49f583ada (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
{ lib
, home-assistant
}:

let
  # some components' tests have additional dependencies
  extraCheckInputs = with home-assistant.python.pkgs; {
    airzone_cloud = [
      aioairzone
    ];
    bluetooth = [
      pyswitchbot
    ];
    govee_ble = [
      ibeacon-ble
    ];
    lovelace = [
      pychromecast
    ];
    matrix = [
      pydantic
    ];
    mopeka = [
      pyswitchbot
    ];
    onboarding = [
      pymetno
      radios
      rpi-bad-power
    ];
    raspberry_pi = [
      rpi-bad-power
    ];
    shelly = [
      pyswitchbot
    ];
    tilt_ble = [
      ibeacon-ble
    ];
    xiaomi_miio = [
      arrow
    ];
    zha = [
      pydeconz
    ];
  };

  extraDisabledTestPaths = {
  };

  extraDisabledTests = {
    private_ble_device = [
      # AssertionError: assert '90' == '90.0'
      "test_estimated_broadcast_interval"
    ];
    shell_command = [
      # tries to retrieve file from github
      "test_non_text_stdout_capture"
    ];
    sma = [
      # missing operating_status attribute in entity
      "test_sensor_entities"
    ];
  };

  extraPytestFlagsArray = {
    cloud = [
      # Tries to connect to alexa-api.nabucasa.com:443
      "--deselect tests/components/cloud/test_http_api.py::test_websocket_update_preferences_alexa_report_state"
    ];
    dnsip = [
      # Tries to resolve DNS entries
      "--deselect tests/components/dnsip/test_config_flow.py::test_options_flow"
    ];
    jellyfin = [
      # AssertionError: assert 'audio/x-flac' == 'audio/flac'
      "--deselect tests/components/jellyfin/test_media_source.py::test_resolve"
      # AssertionError: assert [+ received] == [- snapshot]
      "--deselect tests/components/jellyfin/test_media_source.py::test_music_library"
    ];
    modem_callerid = [
      # aioserial mock produces wrong state
      "--deselect tests/components/modem_callerid/test_init.py::test_setup_entry"
    ];
    velux = [
      # uses unmocked sockets
      "--deselect tests/components/velux/test_config_flow.py::test_user_success"
      "--deselect tests/components/velux/test_config_flow.py::test_import_valid_config"
    ];
  };
in lib.listToAttrs (map (component: lib.nameValuePair component (
  home-assistant.overridePythonAttrs (old: {
    pname = "homeassistant-test-${component}";
    format = "other";

    dontBuild = true;
    dontInstall = true;

    nativeCheckInputs = old.nativeCheckInputs
      ++ home-assistant.getPackages component home-assistant.python.pkgs
      ++ extraCheckInputs.${component} or [ ];

    disabledTests = old.disabledTests or [] ++ extraDisabledTests.${component} or [];
    disabledTestPaths = old.disabledTestPaths or [] ++ extraDisabledTestPaths.${component} or [ ];

    # components are more often racy than the core
    dontUsePytestXdist = true;

    pytestFlagsArray = lib.remove "tests" old.pytestFlagsArray
      ++ extraPytestFlagsArray.${component} or [ ]
      ++ [ "tests/components/${component}" ];

    preCheck = old.preCheck + lib.optionalString (builtins.elem component [ "emulated_hue" "songpal" "system_log" ]) ''
      patch -p1 < ${./patches/tests-mock-source-ip.patch}
    '';

    meta = old.meta // {
      broken = lib.elem component [
        # pinned version incompatible with urllib3>=2.0
        "telegram_bot"
        # depends on telegram_bot
        "telegram"
      ];
      # upstream only tests on Linux, so do we.
      platforms = lib.platforms.linux;
    };
  })
)) home-assistant.supportedComponentsWithTests)