notify-api-412 use black to enforce python coding style

This commit is contained in:
Kenneth Kehl
2023-08-25 09:12:23 -07:00
parent c6eb007386
commit 8c9721d8e2
201 changed files with 31660 additions and 28105 deletions

View File

@@ -4,35 +4,34 @@ from app.models import JSONModel
def test_looks_up_from_dict():
class Custom(JSONModel):
ALLOWED_PROPERTIES = {'foo'}
ALLOWED_PROPERTIES = {"foo"}
assert Custom({'foo': 'bar'}).foo == 'bar'
assert Custom({"foo": "bar"}).foo == "bar"
def test_raises_when_overriding_custom_properties():
class Custom(JSONModel):
ALLOWED_PROPERTIES = {'foo'}
ALLOWED_PROPERTIES = {"foo"}
@property
def foo(self):
pass
with pytest.raises(AttributeError) as e:
Custom({'foo': 'NOPE'})
Custom({"foo": "NOPE"})
assert str(e.value) == "can't set attribute"
@pytest.mark.parametrize('json_response', (
{},
{'foo': 'bar'}, # Should still raise an exception
))
@pytest.mark.parametrize(
"json_response",
(
{},
{"foo": "bar"}, # Should still raise an exception
),
)
def test_model_raises_for_unknown_attributes(json_response):
class Custom(JSONModel):
ALLOWED_PROPERTIES = set()
@@ -46,9 +45,8 @@ def test_model_raises_for_unknown_attributes(json_response):
def test_model_raises_keyerror_if_item_missing_from_dict():
class Custom(JSONModel):
ALLOWED_PROPERTIES = {'foo'}
ALLOWED_PROPERTIES = {"foo"}
with pytest.raises(AttributeError) as e:
Custom({}).foo
@@ -56,30 +54,31 @@ def test_model_raises_keyerror_if_item_missing_from_dict():
assert str(e.value) == "'Custom' object has no attribute 'foo'"
@pytest.mark.parametrize('json_response', (
{},
{'foo': 'bar'}, # Should be ignored
))
@pytest.mark.parametrize(
"json_response",
(
{},
{"foo": "bar"}, # Should be ignored
),
)
def test_model_doesnt_swallow_attribute_errors(json_response):
class Custom(JSONModel):
ALLOWED_PROPERTIES = set()
@property
def foo(self):
raise AttributeError('Something has gone wrong')
raise AttributeError("Something has gone wrong")
with pytest.raises(AttributeError) as e:
Custom(json_response).foo
assert str(e.value) == 'Something has gone wrong'
assert str(e.value) == "Something has gone wrong"
def test_dynamic_properties_are_introspectable():
class Custom(JSONModel):
ALLOWED_PROPERTIES = {'foo', 'bar', 'baz'}
ALLOWED_PROPERTIES = {"foo", "bar", "baz"}
model = Custom({'foo': None, 'bar': None, 'baz': None})
model = Custom({"foo": None, "bar": None, "baz": None})
assert dir(model)[-3:] == ['bar', 'baz', 'foo']
assert dir(model)[-3:] == ["bar", "baz", "foo"]