Debian Codegraph @

tests/tools/test_converters.py

raw
1 """Test AusRouter converters tools."""
2
3 from datetime import UTC, datetime, timedelta
4 from enum import Enum
5 from typing import Any
6 from unittest.mock import MagicMock, patch
7
8 import pytest
9
10 from asusrouter.tools import converters
11
12
13 @pytest.mark.parametrize(
14 ("input_value", "jitter", "expected_output"),
15 [
16 # Real values, jitter 1
17 (0, 1, 1),
18 (1, 1, 1),
19 (2, 1, 1),
20 (3, 1, 4),
21 (4, 1, 4),
22 (5, 1, 4),
23 (6, 1, 7),
24 (7, 1, 7),
25 (8, 1, 7),
26 # Real values, jitter vary
27 (0, 2, 2),
28 (11, 2, 12),
29 (0, 3, 3),
30 (1, 4, 4),
31 (5, 11, 11),
32 # Int-convertible values
33 ("2", 1, 1),
34 (0.9, 2, 2),
35 ("4.4", 1, 4),
36 # Wrong jitter returns the value unchanged
37 (15, -1, 15),
38 (77, 0, 77),
39 ("any", -1, "any"),
40 # Any non-int values are returned unchanged
41 (None, None, None),
42 ("None", None, "None"),
43 ("string", None, "string"),
44 (" ", None, " "),
45 ],
46 )
47 def test_clean_jitter(
48 input_value: Any, jitter: Any | None, expected_output: Any
49 ) -> None:
50 """Test clean_jitter method."""
51
52 assert converters.clean_jitter(input_value, jitter) == expected_output # type: ignore[arg-type]
53
54
55 @pytest.mark.parametrize(
56 ("content", "result"),
57 [
58 (None, None), # Not a string
59 (12, None), # Not a string
60 ("", None), # Empty string
61 (" ", None), # Empty string
62 ("test", "test"), # Normal string
63 (" test ", "test"), # Normal string
64 ],
65 )
66 def test_clean_string(content: str | None, result: str | None) -> None:
67 """Test clean_string method."""
68
69 assert converters.clean_string(content) == result
70
71
72 def test_flatten_dict() -> None:
73 """Test flatten_dict method."""
74
75 nested_dict: dict[str, Any] = {"a": {"b": {"c": 1}}, "d": {"e": 2}}
76 expected_output: dict[str, Any] = {"a_b_c": 1, "d_e": 2}
77 assert converters.flatten_dict(nested_dict) == expected_output
78
79 # Test with None input
80 assert converters.flatten_dict(None) is None
81
82 # Test with non-dict input
83 assert converters.flatten_dict("not a dict") == {} # type: ignore[arg-type]
84
85 # Test with exclude parameter
86 nested_dict = {"a": {"b": {"c": 1}}, "d": 2}
87 expected_output = {"a_b": {"c": 1}, "d": 2}
88 assert converters.flatten_dict(nested_dict, exclude="b") == expected_output
89
90
91 class EnumForTest(Enum):
92 """Enum class."""
93
94 A = 1
95 B = 2
96
97
98 @pytest.mark.parametrize(
99 ("args", "kwargs", "expected_result"),
100 [
101 # Single string - should return single value
102 ("vpnc_unit", {"vpnc_unit": 1}, 1),
103 ("vpnc_unit", {"arguments": {"vpnc_unit": 1}}, 1),
104 # Tuple with single string - should return single value
105 (("vpnc_unit",), {"vpnc_unit": 1}, 1),
106 (("vpnc_unit",), {"arguments": {"vpnc_unit": 1}}, 1),
107 # Tuple with multiple strings and all are found
108 # - should return tuple with values
109 (
110 ("vpnc_unit", "vpnc_clientlist"),
111 {"vpnc_unit": 1, "vpnc_clientlist": "list"},
112 (1, "list"),
113 ),
114 # Tuple with multiple strings and not all are found
115 # - should return tuple with values, missing values should be None
116 (("vpnc_unit", "vpnc_clientlist"), {"vpnc_unit": 1}, (1, None)),
117 # Args issues - should return None
118 (None, {"vpnc_unit": 1}, None),
119 (1, {"vpnc_unit": 1}, None),
120 ],
121 )
122 def test_get_arguments(
123 args: str | tuple[str, ...],
124 kwargs: Any,
125 expected_result: Any | tuple[Any | None, ...],
126 ) -> None:
127 """Test _get_arguments."""
128
129 # Get the result
130 result = converters.get_arguments(args, **kwargs)
131
132 # Check the result
133 assert result == expected_result
134
135
136 def test_get_enum_key_by_value() -> None:
137 """Test get_enum_key_by_value method."""
138
139 assert (
140 converters.get_enum_key_by_value(EnumForTest, 1, EnumForTest.B)
141 == EnumForTest.A
142 )
143 assert (
144 converters.get_enum_key_by_value(EnumForTest, 2, EnumForTest.A)
145 == EnumForTest.B
146 )
147 assert (
148 converters.get_enum_key_by_value(EnumForTest, 3, EnumForTest.A)
149 == EnumForTest.A
150 )
151 with pytest.raises(ValueError): # noqa: PT011
152 converters.get_enum_key_by_value(EnumForTest, 3)
153
154
155 @pytest.mark.parametrize(
156 ("content", "result"),
157 [
158 (0, [False]),
159 (1, [True]),
160 (2, [False, True]),
161 (3, [True, True]),
162 (10, [False, True, False, True]),
163 # Test with negative integers and non-integer input
164 (-1, []),
165 ("string", []),
166 (None, []),
167 ],
168 )
169 def test_int_as_bits(content: int, result: list[bool]) -> None:
170 """Test int_as_bits method."""
171
172 assert converters.int_as_bits(content) == result
173
174
175 # Define a test Enum
176 class Capabilities(Enum):
177 """Capabilities enum."""
178
179 CAPABILITY1 = 0
180 CAPABILITY2 = 1
181 CAPABILITY3 = 2
182 CAPABILITY4 = 3
183 CAPABILITY5 = "not an int"
184
185
186 @pytest.mark.parametrize(
187 ("value", "capabilities", "result"),
188 [
189 (
190 0,
191 Capabilities,
192 {
193 Capabilities.CAPABILITY1: False,
194 Capabilities.CAPABILITY2: False,
195 Capabilities.CAPABILITY3: False,
196 Capabilities.CAPABILITY4: False,
197 },
198 ),
199 (
200 1,
201 Capabilities,
202 {
203 Capabilities.CAPABILITY1: True,
204 Capabilities.CAPABILITY2: False,
205 Capabilities.CAPABILITY3: False,
206 Capabilities.CAPABILITY4: False,
207 },
208 ),
209 (
210 10,
211 Capabilities,
212 {
213 Capabilities.CAPABILITY1: False,
214 Capabilities.CAPABILITY2: True,
215 Capabilities.CAPABILITY3: False,
216 Capabilities.CAPABILITY4: True,
217 },
218 ),
219 # Wrong input
220 (None, Capabilities, {}),
221 ("string", Capabilities, {}),
222 (15, "not an enum", {}),
223 (15, None, {}),
224 ],
225 )
226 def test_int_as_capabilities(
227 value: int, capabilities: type[Enum], result: dict[Enum, bool]
228 ) -> None:
229 """Test int_as_capabilities method."""
230
231 assert converters.int_as_capabilities(value, capabilities) == result
232
233
234 def test_is_enum() -> None:
235 """Test is_enum method."""
236
237 class TestEnum(Enum):
238 """Enum class."""
239
240 A = 1
241 B = 2
242
243 class NotEnum: # pylint: disable=too-few-public-methods
244 """Not enum class."""
245
246 assert converters.is_enum(TestEnum) is True
247 assert converters.is_enum(NotEnum) is False
248
249 # Test with non-class input
250 assert converters.is_enum("not a class") is False
251 assert converters.is_enum(None) is False
252
253
254 def test_list_from_dict() -> None:
255 """Test list_from_dict method."""
256
257 # Test with empty dict
258 assert converters.list_from_dict({}) == []
259
260 # Test with non-empty dict
261 assert converters.list_from_dict({"a": 1, "b": 2}) == ["a", "b"]
262
263 # Test with a list
264 assert converters.list_from_dict(["a", "b"]) == ["a", "b"]
265
266 # Test with non-dict input
267 assert converters.list_from_dict("not a dict") == [] # type: ignore[arg-type]
268 assert converters.list_from_dict(None) == []
269
270
271 def test_nvram_get() -> None:
272 """Test nvram_get method."""
273
274 # Test with empty input
275 assert converters.nvram_get(None) is None
276
277 # Test with string input
278 assert converters.nvram_get("test") == [("nvram_get", "test")]
279
280 # Test with list input
281 assert converters.nvram_get(["test1", "test2"]) == [
282 ("nvram_get", "test1"),
283 ("nvram_get", "test2"),
284 ]
285
286 # Test with other input
287 assert converters.nvram_get(123) == [("nvram_get", "123")] # type: ignore[arg-type]
288
289
290 def test_run_method() -> None:
291 """Test run_method method."""
292
293 # Test with empty input
294 assert converters.run_method(None, None) is None
295
296 # Test with non-list input
297 assert converters.run_method("TEST", str.lower) == "test"
298
299 # Test with list input
300 assert converters.run_method("TEST", [str.lower, str.upper]) == "TEST"
301
302 # Test with enum input
303 class TestEnum(Enum):
304 """Enum class."""
305
306 A = 1
307 B = 2
308
309 assert converters.run_method(1, TestEnum) == TestEnum.A
310 assert converters.run_method(2, TestEnum) == TestEnum.B
311 assert converters.run_method(3, TestEnum) is None
312
313 # Test with enum input with UNKNOWN
314 class TestEnumWithUnknown(Enum):
315 """Enum class."""
316
317 UNKNOWN = -999
318 A = 1
319 B = 2
320
321 assert (
322 converters.run_method(3, TestEnumWithUnknown)
323 == TestEnumWithUnknown.UNKNOWN
324 )
325
326
327 @pytest.mark.parametrize(
328 ("content", "result"),
329 [
330 (None, None), # Non-booleans
331 ("", None),
332 (" ", None),
333 ("unknown", None),
334 ("test", None),
335 (" test ", None),
336 (False, False), # False booleans
337 (0, False),
338 ("0", False),
339 ("false", False),
340 ("off", False),
341 ("disabled", False),
342 (True, True), # True booleans
343 (1, True),
344 ("1", True),
345 ("true", True),
346 ("on", True),
347 ("enabled", True),
348 ],
349 )
350 def test_safe_bool(
351 content: str | float | bool | None, result: bool | None
352 ) -> None:
353 """Test safe_bool method."""
354
355 assert converters.safe_bool(content) == result
356
357
358 @pytest.mark.parametrize(
359 ("content", "result"),
360 [
361 # Boolean-compatible values
362 (True, True),
363 ("False", False),
364 # Non-boolean values
365 (None, False),
366 (object(), False),
367 ],
368 )
369 def test_safe_bool_nn(content: Any, result: bool) -> None:
370 """Test safe_bool_nn method."""
371
372 assert converters.safe_bool_nn(content) is result
373
374
375 @pytest.mark.parametrize(
376 ("content", "result"),
377 [
378 ("2021-01-01 ", datetime(2021, 1, 1)), # Date content
379 ("2021-01-01 00:00:00", datetime(2021, 1, 1)),
380 (None, None), # None content
381 ("", None),
382 (" ", None),
383 ("unknown", None), # Non-datetime content
384 ("test", None),
385 (" test ", None),
386 ],
387 )
388 def test_safe_datetime(content: str | None, result: datetime | None) -> None:
389 """Test safe_datetime method."""
390
391 assert converters.safe_datetime(content) == result
392
393
394 @pytest.mark.parametrize(
395 ("enum", "value", "default_value", "default", "expected"),
396 [
397 (EnumForTest, 1, None, None, EnumForTest.A),
398 (EnumForTest, 2, None, None, EnumForTest.B),
399 (EnumForTest, None, 1, None, EnumForTest.A),
400 (EnumForTest, None, 2, None, EnumForTest.B),
401 (EnumForTest, None, None, EnumForTest.A, EnumForTest.A),
402 (EnumForTest, None, None, EnumForTest.B, EnumForTest.B),
403 (EnumForTest, 3, None, None, None),
404 (EnumForTest, None, None, None, None),
405 (EnumForTest, None, 2, EnumForTest.B, EnumForTest.B),
406 ],
407 )
408 def test_safe_enum(
409 enum: type[Enum],
410 value: int | None,
411 default_value: int | None,
412 default: Enum | None,
413 expected: Enum | None,
414 ) -> None:
415 """Test safe_enum method."""
416
417 assert (
418 converters.safe_enum(enum, value, default_value, default) == expected
419 )
420
421
422 def test_safe_exists() -> None:
423 """Test safe_exists method."""
424
425 assert converters.safe_exists("") is False
426 assert converters.safe_exists("test") is True
427
428
429 @pytest.mark.parametrize(
430 ("content", "result"),
431 [
432 (1, 1.0), # Number content
433 (1.0, 1.0),
434 ("1", 1.0),
435 ("1.0", 1.0),
436 (None, None), # None content
437 ("", None),
438 (" ", None),
439 ("unknown", None), # Non-number content
440 ("test", None),
441 (" test ", None),
442 ],
443 )
444 def test_safe_float(content: str | float | None, result: float | None) -> None:
445 """Test safe_float method."""
446
447 assert converters.safe_float(content) == result
448
449
450 @pytest.mark.parametrize(
451 ("content", "result"),
452 [
453 (1, 1.0),
454 (1.0, 1.0),
455 ("1", 1.0),
456 ("1.0", 1.0),
457 (None, 0.0),
458 ("", 0.0),
459 (" ", 0.0),
460 ("unknown", 0.0),
461 ("test", 0.0),
462 (" test ", 0.0),
463 ],
464 )
465 def test_safe_float_nn(content: Any, result: float) -> None:
466 """Test safe_float method."""
467
468 assert converters.safe_float_nn(content) == result
469
470
471 @pytest.mark.parametrize(
472 ("content", "base", "result"),
473 [
474 (1, 10, 1), # Integer content
475 ("1", 10, 1),
476 (1.0, 10, 1), # Float content
477 ("1.0", 10, 1),
478 ("1.1", 10, 1), # Float content with decimal
479 ("1.9", 10, 1),
480 (None, 10, None), # None content
481 ("", 10, None),
482 (" ", 10, None),
483 ("unknown", 10, None), # Non-number content
484 ("test", 10, None),
485 (" test ", 10, None),
486 ("0x1", 16, 1), # Hex content
487 ("0xA", 16, 10),
488 ("0xFF", 16, 255),
489 ("0x100", 16, 256),
490 ("0xabc", 16, 2748),
491 ("0xABC", 16, 2748),
492 ("0x2692247c7", 16, 10353788871),
493 ("0x123456789ABCDEF", 16, 81985529216486895),
494 ],
495 )
496 def test_safe_int(
497 content: str | float | None, base: int, result: int | None
498 ) -> None:
499 """Test safe_int method."""
500
501 assert converters.safe_int(content, base=base) == result
502
503
504 @pytest.mark.parametrize(
505 ("content", "result"),
506 [
507 (None, []), # None content
508 ("test", ["test"]), # Single value content
509 (1, [1]),
510 (1.0, [1.0]),
511 (True, [True]),
512 (False, [False]),
513 ([], []), # List content
514 ([1, 2, 3], [1, 2, 3]),
515 ],
516 )
517 def test_safe_list(content: Any, result: list[Any]) -> None:
518 """Test safe_list method."""
519
520 assert converters.safe_list(content) == result
521
522
523 def test_safe_list_csv() -> None:
524 """Test safe_list_csv method."""
525
526 assert converters.safe_list_csv("test") == ["test"]
527 assert converters.safe_list_csv("test1,test2") == ["test1", "test2"]
528
529
530 @pytest.mark.parametrize(
531 ("content", "delimiter", "result"),
532 [
533 (None, None, []), # Not a string
534 (1, None, []),
535 ({1: 2}, None, []),
536 ("test", None, ["test"]), # String
537 ("test1 test2", None, ["test1", "test2"]),
538 ("test1 test2", ";", ["test1 test2"]), # Wrong delimiter
539 ],
540 )
541 def test_safe_list_from_string(
542 content: str | None, delimiter: str, result: list[str]
543 ) -> None:
544 """Test safe_list_from_string method."""
545
546 assert converters.safe_list_from_string(content, delimiter) == result
547
548
549 @pytest.mark.parametrize(
550 ("content", "result"),
551 [
552 (None, None), # None content
553 (1, 1), # Integer content
554 (5.0, 5.0), # Float content
555 ([1, 2, 3], [1, 2, 3]), # List content
556 ({"a": 1}, {"a": 1}), # Dictionary content
557 ("test", "test"), # String content
558 (" test ", "test"),
559 (" ", None), # Empty string content
560 ("", None),
561 ],
562 )
563 def test_safe_return(content: Any, result: Any) -> None:
564 """Test safe_return method."""
565
566 assert converters.safe_return(content) == result
567
568
569 @pytest.mark.parametrize(
570 ("current", "previous", "time_delta", "result"),
571 [
572 (None, None, None, 0.0),
573 (1, None, None, 0.0),
574 (1, 1, None, 0.0),
575 (1, 1, 0, 0.0),
576 (1, 1, 1, 0.0),
577 (1, 1, 2, 0.0),
578 (1, 2, 1, 0.0),
579 (2, 1, 1, 1.0),
580 (4, 2, 2, 1.0),
581 ],
582 )
583 def test_safe_speed(
584 current: float, previous: float, time_delta: float | None, result: float
585 ) -> None:
586 """Test safe_speed method."""
587
588 assert converters.safe_speed(current, previous, time_delta) == result
589
590
591 @patch("asusrouter.tools.converters.datetime")
592 def test_safe_time_from_delta(mock_datetime: MagicMock) -> None:
593 """Test safe_time_from_delta method."""
594
595 # Set up the mock to return a specific datetime when now() is called
596 mock_datetime.now.return_value = datetime(2023, 8, 15, tzinfo=UTC)
597
598 result = converters.safe_time_from_delta(
599 "48:00:15"
600 ) # 48 hours, 15 seconds
601 expected = datetime(2023, 8, 12, 23, 59, 45, tzinfo=UTC)
602 assert result == expected
603
604
605 def test_safe_timedelta_long() -> None:
606 """Test safe_timedelta_long method."""
607
608 # Test with valid string
609 assert converters.safe_timedelta_long("01:30:15 ") == timedelta(
610 hours=1, minutes=30, seconds=15
611 )
612 assert converters.safe_timedelta_long(" 30:15:27") == timedelta(
613 hours=30, minutes=15, seconds=27
614 )
615
616 # Test with invalid string
617 assert converters.safe_timedelta_long("invalid") == timedelta()
618
619 # Test with None
620 assert converters.safe_timedelta_long(None) == timedelta()
621
622
623 def test_safe_unpack_key() -> None:
624 """Test safe_unpack_key method."""
625
626 def test_method(content: Any) -> dict[str, Any]:
627 """Test method."""
628
629 return {"content": content}
630
631 # Test with a key only
632 result = converters.safe_unpack_key("key")
633 assert result[0] == "key"
634 assert result[1] is None
635
636 # Test with a key and a method
637 result = converters.safe_unpack_key(("key", test_method))
638 if result[1] is not None and not isinstance(result[1], list):
639 assert result[0] == "key"
640 assert result[1](10) == test_method(10)
641 elif result[1] is not None:
642 assert result[0] == "key"
643 assert result[1][0](10) == test_method(10)
644 else:
645 assert result[0] == "key"
646 assert result[1] is None
647
648 # Test with a key and a list of methods
649 result = converters.safe_unpack_key(("key", [test_method, test_method]))
650 if isinstance(result[1], list):
651 assert result[0] == "key"
652 assert result[1][0](10) == test_method(10)
653 assert result[1][1](10) == test_method(10)
654
655 # Test with a key and a non-method at index 1
656 result = converters.safe_unpack_key(("key", 123)) # type: ignore[arg-type]
657 assert result[0] == "key"
658 assert result[1] is None
659
660 # Test with a tuple of one element
661 result = converters.safe_unpack_key(("key",))
662 assert result[0] == "key"
663 assert result[1] is None
664
665
666 def test_safe_unpack_keys() -> None:
667 """Test safe_unpack_keys method."""
668
669 def test_method(content: Any) -> dict[str, Any]:
670 """Test method."""
671
672 return {"content": content}
673
674 # Test with a key, key_to_use and a method
675 result = converters.safe_unpack_keys(("key", "key_to_use", test_method))
676 assert result[0] == "key"
677 assert result[1] == "key_to_use"
678 assert result[2](10) == test_method(10)
679
680 # Test with a key, key_to_use and a list of methods
681 result = converters.safe_unpack_keys(
682 ("key", "key_to_use", [test_method, test_method])
683 )
684 assert result[0] == "key"
685 assert result[1] == "key_to_use"
686 assert result[2][0](10) == test_method(10)
687 assert result[2][1](10) == test_method(10)
688
689 # Test with a key and key_to_use only
690 result = converters.safe_unpack_keys(("key", "key_to_use"))
691 assert result[0] == "key"
692 assert result[1] == "key_to_use"
693 assert result[2] is None
694
695 # Test with a key only
696 result = converters.safe_unpack_keys("key")
697 assert result[0] == "key"
698 assert result[1] == "key"
699 assert result[2] is None
700
701
702 @pytest.mark.parametrize(
703 ("used", "total", "result"),
704 [
705 (5, 10, 50.0), # normal usage
706 (10, 10, 100.0), # normal usage
707 (3, 9, 33.33), # round to 2 decimals
708 (-1, 2, 0.0), # negative usage not allowed
709 (1, -2, 0.0), # negative usage not allowed
710 (-1, -1, 100.0), # both negative values result in positive usage
711 (1, 0, 0.0), # zero total usage not allowed
712 (0, 0, 0.0), # zero total usage not allowed
713 ],
714 )
715 def test_safe_usage(used: float, total: float, result: float) -> None:
716 """Test safe_usage method."""
717
718 assert converters.safe_usage(used, total) == result
719
720
721 @pytest.mark.parametrize(
722 ("used", "total", "prev_used", "prev_total", "result"),
723 [
724 (10, 20, 5, 10, 50.0), # normal usage
725 (10, 20, 10, 20, 0.0), # no usage
726 (6, 18, 3, 9, 33.33), # round to 2 decimals
727 (
728 5,
729 20,
730 10,
731 10,
732 0.0,
733 ), # invalid case when current used is less than previous
734 (
735 10,
736 20,
737 5,
738 25,
739 0.0,
740 ), # invalid case when current total is less than previous
741 (
742 5,
743 10,
744 10,
745 20,
746 0.0,
747 ), # invalid case when current values are less than previous
748 ],
749 )
750 def test_safe_usage_historic(
751 used: float,
752 total: float,
753 prev_used: float,
754 prev_total: float,
755 result: float,
756 ) -> None:
757 """Test safe_usage_historic method."""
758
759 assert (
760 converters.safe_usage_historic(used, total, prev_used, prev_total)
761 == result
762 )
763
764
765 @pytest.mark.parametrize(
766 ("value", "result"),
767 [
768 # Actual timestamp in milliseconds
769 (
770 1700515143689,
771 datetime(2023, 11, 20, 21, 19, 3, 689000, tzinfo=UTC),
772 ),
773 # None
774 (None, None),
775 # The beginning of the epoch
776 (0, datetime(1970, 1, 1, 0, 0, 0, tzinfo=UTC)),
777 # Random string
778 ("test", None),
779 ],
780 )
781 def test_safe_timestamp_to_utc(
782 value: int | None, result: datetime | None
783 ) -> None:
784 """Test safe_timestamp_to_utc method."""
785
786 assert converters.safe_timestamp_to_utc(value) == result
787
788
789 @pytest.mark.parametrize(
790 ("value", "result"),
791 [
792 # Actual datetime
793 (
794 datetime(2023, 11, 20, 21, 19, 3, 689000, tzinfo=UTC),
795 1700515143.689,
796 ),
797 # None
798 (None, None),
799 # The beginning of the epoch
800 (datetime(1970, 1, 1, 0, 0, 0, tzinfo=UTC), 0),
801 # Random string
802 ("test", None),
803 ],
804 )
805 def test_safe_utc_to_timestamp(
806 value: datetime | None, result: float | None
807 ) -> None:
808 """Test safe_utc_to_timestamp method."""
809
810 assert converters.safe_utc_to_timestamp(value) == result
811
812
813 @pytest.mark.parametrize(
814 ("value", "result"),
815 [
816 # Actual datetime
817 (
818 datetime(2023, 11, 20, 21, 19, 3, 689000, tzinfo=UTC),
819 1700515143689,
820 ),
821 # None
822 (None, None),
823 # The beginning of the epoch
824 (datetime(1970, 1, 1, 0, 0, 0, tzinfo=UTC), 0),
825 # Random string
826 ("test", None),
827 ],
828 )
829 def test_safe_utc_to_timestamp_milli(
830 value: datetime | None, result: int | None
831 ) -> None:
832 """Test safe_utc_to_timestamp_milli method."""
833
834 assert converters.safe_utc_to_timestamp_milli(value) == result