1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-02 03:12:20 +01:00

Handle nanoseconds in config (#5695)

This commit is contained in:
Jesse Hills
2023-11-08 21:34:44 +13:00
committed by GitHub
parent d81bec860b
commit 972598a698
4 changed files with 57 additions and 12 deletions

View File

@@ -116,14 +116,16 @@ class TestTimePeriod:
assert actual == expected
def test_init__microseconds_with_fraction(self):
with pytest.raises(ValueError, match="Maximum precision is microseconds"):
core.TimePeriod(microseconds=1.1)
def test_init__nanoseconds_with_fraction(self):
with pytest.raises(ValueError, match="Maximum precision is nanoseconds"):
core.TimePeriod(nanoseconds=1.1)
@pytest.mark.parametrize(
"kwargs, expected",
(
({}, "0s"),
({"nanoseconds": 1}, "1ns"),
({"nanoseconds": 1.0001}, "1ns"),
({"microseconds": 1}, "1us"),
({"microseconds": 1.0001}, "1us"),
({"milliseconds": 2}, "2ms"),