Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow using type() in tests (pydantic#916)
Browse files Browse the repository at this point in the history
adriangb authored Aug 23, 2023
1 parent 15f62b6 commit a5cb738
Showing 5 changed files with 14 additions and 11 deletions.
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -56,7 +56,10 @@ features = ["pyo3/extension-module"]
[tool.ruff]
line-length = 120
extend-select = ['Q', 'RUF100', 'C90', 'I']
extend-ignore = ['E501']
extend-ignore = [
'E501', # ignore line too long and let black handle it
'E721', # using type() instead of isinstance() - we use this in tests
]
flake8-quotes = {inline-quotes = 'single', multiline-quotes = 'double'}
mccabe = { max-complexity = 13 }
isort = { known-first-party = ['pydantic_core', 'tests'] }
2 changes: 1 addition & 1 deletion tests/serializers/test_bytes.py
Original file line number Diff line number Diff line change
@@ -86,7 +86,7 @@ def test_subclass_bytes(schema_type, input_value, expected_json):

v = s.to_python(input_value, mode='json')
assert v == expected_json
assert type(v) == str # noqa: E721
assert type(v) == str

assert s.to_json(input_value) == json.dumps(expected_json).encode('utf-8')

14 changes: 7 additions & 7 deletions tests/serializers/test_simple.py
Original file line number Diff line number Diff line change
@@ -70,19 +70,19 @@ def test_int_to_float():
s = SchemaSerializer(core_schema.float_schema())
v_plain = s.to_python(1)
assert v_plain == 1
assert type(v_plain) == int # noqa: E721
assert type(v_plain) == int

v_plain_subclass = s.to_python(IntSubClass(1))
assert v_plain_subclass == IntSubClass(1)
assert type(v_plain_subclass) == IntSubClass

v_json = s.to_python(1, mode='json')
assert v_json == 1.0
assert type(v_json) == float # noqa: E721
assert type(v_json) == float

v_json_subclass = s.to_python(IntSubClass(1), mode='json')
assert v_json_subclass == 1
assert type(v_json_subclass) == float # noqa: E721
assert type(v_json_subclass) == float

assert s.to_json(1) == b'1.0'
assert s.to_json(IntSubClass(1)) == b'1.0'
@@ -95,12 +95,12 @@ def test_int_to_float_key():
s = SchemaSerializer(core_schema.dict_schema(core_schema.float_schema(), core_schema.float_schema()))
v_plain = s.to_python({1: 1})
assert v_plain == {1: 1}
assert type(list(v_plain.keys())[0]) == int # noqa: E721
assert type(v_plain[1]) == int # noqa: E721
assert type(list(v_plain.keys())[0]) == int
assert type(v_plain[1]) == int

v_json = s.to_python({1: 1}, mode='json')
assert v_json == {'1': 1.0}
assert type(v_json['1']) == float # noqa: E721
assert type(v_json['1']) == float

assert s.to_json({1: 1}) == b'{"1":1.0}'

@@ -133,6 +133,6 @@ def test_numpy():

v = s.to_python(numpy.float64(1.0), mode='json')
assert v == 1.0
assert type(v) == float # noqa: E721
assert type(v) == float

assert s.to_json(numpy.float64(1.0)) == b'1.0'
2 changes: 1 addition & 1 deletion tests/serializers/test_string.py
Original file line number Diff line number Diff line change
@@ -72,6 +72,6 @@ def test_subclass_str(schema_type, input_value, expected):

v = s.to_python(input_value, mode='json')
assert v == expected
assert type(v) == str # noqa: E721
assert type(v) == str

assert s.to_json(input_value) == json.dumps(expected).encode('utf-8')
2 changes: 1 addition & 1 deletion tests/validators/test_string.py
Original file line number Diff line number Diff line change
@@ -233,7 +233,7 @@ def test_lax_subclass(FruitEnum, kwargs):
assert v.validate_python(b'foobar') == 'foobar'
p = v.validate_python(FruitEnum.pear)
assert p == 'pear'
assert type(p) is str # noqa: E721
assert type(p) is str
assert repr(p) == "'pear'"


0 comments on commit a5cb738

Please sign in to comment.