pytest-homeassistant-custom-component 0.13.163__py3-none-any.whl → 0.13.298__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (21) hide show
  1. pytest_homeassistant_custom_component/common.py +289 -46
  2. pytest_homeassistant_custom_component/components/__init__.py +351 -0
  3. pytest_homeassistant_custom_component/components/diagnostics/__init__.py +71 -0
  4. pytest_homeassistant_custom_component/components/recorder/common.py +143 -13
  5. pytest_homeassistant_custom_component/components/recorder/db_schema_0.py +1 -1
  6. pytest_homeassistant_custom_component/const.py +4 -3
  7. pytest_homeassistant_custom_component/patch_json.py +41 -0
  8. pytest_homeassistant_custom_component/patch_recorder.py +1 -1
  9. pytest_homeassistant_custom_component/patch_time.py +66 -0
  10. pytest_homeassistant_custom_component/plugins.py +429 -177
  11. pytest_homeassistant_custom_component/syrupy.py +188 -1
  12. pytest_homeassistant_custom_component/test_util/aiohttp.py +56 -20
  13. pytest_homeassistant_custom_component/typing.py +5 -0
  14. {pytest_homeassistant_custom_component-0.13.163.dist-info → pytest_homeassistant_custom_component-0.13.298.dist-info}/METADATA +54 -29
  15. pytest_homeassistant_custom_component-0.13.298.dist-info/RECORD +28 -0
  16. {pytest_homeassistant_custom_component-0.13.163.dist-info → pytest_homeassistant_custom_component-0.13.298.dist-info}/WHEEL +1 -1
  17. pytest_homeassistant_custom_component-0.13.163.dist-info/RECORD +0 -26
  18. {pytest_homeassistant_custom_component-0.13.163.dist-info → pytest_homeassistant_custom_component-0.13.298.dist-info}/entry_points.txt +0 -0
  19. {pytest_homeassistant_custom_component-0.13.163.dist-info → pytest_homeassistant_custom_component-0.13.298.dist-info/licenses}/LICENSE +0 -0
  20. {pytest_homeassistant_custom_component-0.13.163.dist-info → pytest_homeassistant_custom_component-0.13.298.dist-info/licenses}/LICENSE_HA_CORE.md +0 -0
  21. {pytest_homeassistant_custom_component-0.13.163.dist-info → pytest_homeassistant_custom_component-0.13.298.dist-info}/top_level.txt +0 -0
@@ -4,8 +4,9 @@ Constants used by Home Assistant components.
4
4
  This file is originally from homeassistant/core and modified by pytest-homeassistant-custom-component.
5
5
  """
6
6
  from typing import TYPE_CHECKING, Final
7
- MAJOR_VERSION: Final = 2024
8
- MINOR_VERSION: Final = 9
9
- PATCH_VERSION: Final = "2"
7
+ MAJOR_VERSION: Final = 2025
8
+ MINOR_VERSION: Final = 12
9
+ PATCH_VERSION: Final = "0"
10
10
  __short_version__: Final = f"{MAJOR_VERSION}.{MINOR_VERSION}"
11
11
  __version__: Final = f"{__short_version__}.{PATCH_VERSION}"
12
+ CONF_API_VERSION: Final = "api_version"
@@ -0,0 +1,41 @@
1
+ """
2
+ Patch JSON related functions.
3
+
4
+ This file is originally from homeassistant/core and modified by pytest-homeassistant-custom-component.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import functools
10
+ from typing import Any
11
+ from unittest import mock
12
+
13
+ import orjson
14
+
15
+ from homeassistant.helpers import json as json_helper
16
+
17
+ real_json_encoder_default = json_helper.json_encoder_default
18
+
19
+ mock_objects = []
20
+
21
+
22
+ def json_encoder_default(obj: Any) -> Any:
23
+ """Convert Home Assistant objects.
24
+
25
+ Hand other objects to the original method.
26
+ """
27
+ if isinstance(obj, mock.Base):
28
+ mock_objects.append(obj)
29
+ raise TypeError(f"Attempting to serialize mock object {obj}")
30
+ return real_json_encoder_default(obj)
31
+
32
+
33
+ json_helper.json_encoder_default = json_encoder_default
34
+ json_helper.json_bytes = functools.partial(
35
+ orjson.dumps, option=orjson.OPT_NON_STR_KEYS, default=json_encoder_default
36
+ )
37
+ json_helper.json_bytes_sorted = functools.partial(
38
+ orjson.dumps,
39
+ option=orjson.OPT_NON_STR_KEYS | orjson.OPT_SORT_KEYS,
40
+ default=json_encoder_default,
41
+ )
@@ -10,7 +10,7 @@ from contextlib import contextmanager
10
10
  import sys
11
11
 
12
12
  # Patch recorder util session scope
13
- from homeassistant.helpers import recorder as recorder_helper # noqa: E402
13
+ from homeassistant.helpers import recorder as recorder_helper
14
14
 
15
15
  # Make sure homeassistant.components.recorder.util is not already imported
16
16
  assert "homeassistant.components.recorder.util" not in sys.modules
@@ -9,6 +9,72 @@ from __future__ import annotations
9
9
  import datetime
10
10
  import time
11
11
 
12
+ import freezegun
13
+
14
+
15
+ def ha_datetime_to_fakedatetime(datetime) -> freezegun.api.FakeDatetime: # type: ignore[name-defined]
16
+ """Convert datetime to FakeDatetime.
17
+
18
+ Modified to include https://github.com/spulec/freezegun/pull/424.
19
+ """
20
+ return freezegun.api.FakeDatetime( # type: ignore[attr-defined]
21
+ datetime.year,
22
+ datetime.month,
23
+ datetime.day,
24
+ datetime.hour,
25
+ datetime.minute,
26
+ datetime.second,
27
+ datetime.microsecond,
28
+ datetime.tzinfo,
29
+ fold=datetime.fold,
30
+ )
31
+
32
+
33
+ class HAFakeDateMeta(freezegun.api.FakeDateMeta):
34
+ """Modified to override the string representation."""
35
+
36
+ def __str__(cls) -> str: # noqa: N805 (ruff doesn't know this is a metaclass)
37
+ """Return the string representation of the class."""
38
+ return "<class 'datetime.date'>"
39
+
40
+
41
+ class HAFakeDate(freezegun.api.FakeDate, metaclass=HAFakeDateMeta): # type: ignore[name-defined]
42
+ """Modified to improve class str."""
43
+
44
+
45
+ class HAFakeDatetimeMeta(freezegun.api.FakeDatetimeMeta):
46
+ """Modified to override the string representation."""
47
+
48
+ def __str__(cls) -> str: # noqa: N805 (ruff doesn't know this is a metaclass)
49
+ """Return the string representation of the class."""
50
+ return "<class 'datetime.datetime'>"
51
+
52
+
53
+ class HAFakeDatetime(freezegun.api.FakeDatetime, metaclass=HAFakeDatetimeMeta): # type: ignore[name-defined]
54
+ """Modified to include basic fold support and improve class str.
55
+
56
+ Fold support submitted to upstream in https://github.com/spulec/freezegun/pull/424.
57
+ """
58
+
59
+ @classmethod
60
+ def now(cls, tz=None):
61
+ """Return frozen now."""
62
+ now = cls._time_to_freeze() or freezegun.api.real_datetime.now()
63
+ if tz:
64
+ result = tz.fromutc(now.replace(tzinfo=tz))
65
+ else:
66
+ result = now
67
+
68
+ # Add the _tz_offset only if it's non-zero to preserve fold
69
+ if cls._tz_offset():
70
+ result += cls._tz_offset()
71
+
72
+ return ha_datetime_to_fakedatetime(result)
73
+
74
+
75
+ # Needed by Mashumaro
76
+ datetime.HAFakeDatetime = HAFakeDatetime
77
+
12
78
  # Do not add any Home Assistant import here
13
79
 
14
80