1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-02 11:22:24 +01:00
* Add black

Update pre commit

Update pre commit

add empty line

* Format with black
This commit is contained in:
Guillermo Ruffino
2021-03-07 16:03:16 -03:00
committed by GitHub
parent 2b60b0f1fa
commit 69879920eb
398 changed files with 21624 additions and 12644 deletions

View File

@@ -6,69 +6,89 @@ from hypothesis.provisional import ip_addresses
from esphome import helpers
@pytest.mark.parametrize("preferred_string, current_strings, expected", (
("foo", [], "foo"),
# TODO: Should this actually start at 1?
("foo", ["foo"], "foo_2"),
("foo", ("foo",), "foo_2"),
("foo", ("foo", "foo_2"), "foo_3"),
("foo", ("foo", "foo_2", "foo_2"), "foo_3"),
))
@pytest.mark.parametrize(
"preferred_string, current_strings, expected",
(
("foo", [], "foo"),
# TODO: Should this actually start at 1?
("foo", ["foo"], "foo_2"),
("foo", ("foo",), "foo_2"),
("foo", ("foo", "foo_2"), "foo_3"),
("foo", ("foo", "foo_2", "foo_2"), "foo_3"),
),
)
def test_ensure_unique_string(preferred_string, current_strings, expected):
actual = helpers.ensure_unique_string(preferred_string, current_strings)
assert actual == expected
@pytest.mark.parametrize("text, expected", (
("foo", "foo"),
("foo\nbar", "foo\nbar"),
("foo\nbar\neek", "foo\n bar\neek"),
))
@pytest.mark.parametrize(
"text, expected",
(
("foo", "foo"),
("foo\nbar", "foo\nbar"),
("foo\nbar\neek", "foo\n bar\neek"),
),
)
def test_indent_all_but_first_and_last(text, expected):
actual = helpers.indent_all_but_first_and_last(text)
assert actual == expected
@pytest.mark.parametrize("text, expected", (
("foo", [" foo"]),
("foo\nbar", [" foo", " bar"]),
("foo\nbar\neek", [" foo", " bar", " eek"]),
))
@pytest.mark.parametrize(
"text, expected",
(
("foo", [" foo"]),
("foo\nbar", [" foo", " bar"]),
("foo\nbar\neek", [" foo", " bar", " eek"]),
),
)
def test_indent_list(text, expected):
actual = helpers.indent_list(text)
assert actual == expected
@pytest.mark.parametrize("text, expected", (
("foo", " foo"),
("foo\nbar", " foo\n bar"),
("foo\nbar\neek", " foo\n bar\n eek"),
))
@pytest.mark.parametrize(
"text, expected",
(
("foo", " foo"),
("foo\nbar", " foo\n bar"),
("foo\nbar\neek", " foo\n bar\n eek"),
),
)
def test_indent(text, expected):
actual = helpers.indent(text)
assert actual == expected
@pytest.mark.parametrize("string, expected", (
("foo", '"foo"'),
("foo\nbar", '"foo\\012bar"'),
("foo\\bar", '"foo\\134bar"'),
('foo "bar"', '"foo \\042bar\\042"'),
('foo 🐍', '"foo \\360\\237\\220\\215"'),
))
@pytest.mark.parametrize(
"string, expected",
(
("foo", '"foo"'),
("foo\nbar", '"foo\\012bar"'),
("foo\\bar", '"foo\\134bar"'),
('foo "bar"', '"foo \\042bar\\042"'),
("foo 🐍", '"foo \\360\\237\\220\\215"'),
),
)
def test_cpp_string_escape(string, expected):
actual = helpers.cpp_string_escape(string)
assert actual == expected
@pytest.mark.parametrize("host", (
"127.0.0", "localhost", "127.0.0.b",
))
@pytest.mark.parametrize(
"host",
(
"127.0.0",
"localhost",
"127.0.0.b",
),
)
def test_is_ip_address__invalid(host):
actual = helpers.is_ip_address(host)
@@ -82,13 +102,16 @@ def test_is_ip_address__valid(value):
assert actual is True
@pytest.mark.parametrize("var, value, default, expected", (
("FOO", None, False, False),
("FOO", None, True, True),
("FOO", "", False, False),
("FOO", "Yes", False, True),
("FOO", "123", False, True),
))
@pytest.mark.parametrize(
"var, value, default, expected",
(
("FOO", None, False, False),
("FOO", None, True, True),
("FOO", "", False, False),
("FOO", "Yes", False, True),
("FOO", "123", False, True),
),
)
def test_get_bool_env(monkeypatch, var, value, default, expected):
if value is None:
monkeypatch.delenv(var, raising=False)
@@ -100,10 +123,7 @@ def test_get_bool_env(monkeypatch, var, value, default, expected):
assert actual == expected
@pytest.mark.parametrize("value, expected", (
(None, False),
("Yes", True)
))
@pytest.mark.parametrize("value, expected", ((None, False), ("Yes", True)))
def test_is_hassio(monkeypatch, value, expected):
if value is None:
monkeypatch.delenv("ESPHOME_IS_HASSIO", raising=False)
@@ -185,20 +205,23 @@ class Test_copy_file_if_changed:
assert src.read_text() == dst.read_text()
@pytest.mark.parametrize("file1, file2, expected", (
# Same file
("file-a.txt", "file-a.txt", True),
# Different files, different size
("file-a.txt", "file-b_1.txt", False),
# Different files, same size
("file-a.txt", "file-c.txt", False),
# Same files
("file-b_1.txt", "file-b_2.txt", True),
# Not a file
("file-a.txt", "", False),
# File doesn't exist
("file-a.txt", "file-d.txt", False),
))
@pytest.mark.parametrize(
"file1, file2, expected",
(
# Same file
("file-a.txt", "file-a.txt", True),
# Different files, different size
("file-a.txt", "file-b_1.txt", False),
# Different files, same size
("file-a.txt", "file-c.txt", False),
# Same files
("file-b_1.txt", "file-b_2.txt", True),
# Not a file
("file-a.txt", "", False),
# File doesn't exist
("file-a.txt", "file-d.txt", False),
),
)
def test_file_compare(fixture_path, file1, file2, expected):
path1 = fixture_path / "helpers" / file1
path2 = fixture_path / "helpers" / file2