Skip to content

Commit 1b539de

Browse files
committed
move asserts out of round trip test utils
1 parent 9fee59e commit 1b539de

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

tests/snippets/exceptions.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@ def exceptions_eq(e1, e2):
22
return type(e1) is type(e2) and e1.args == e2.args
33

44
def round_trip_repr(e):
5-
assert exceptions_eq(e, eval(repr(e)))
5+
return exceptions_eq(e, eval(repr(e)))
66

77
# KeyError
88
empty_exc = KeyError()
99
assert str(empty_exc) == ''
10-
round_trip_repr(empty_exc)
10+
assert round_trip_repr(empty_exc)
1111
assert len(empty_exc.args) == 0
1212
assert type(empty_exc.args) == tuple
1313

1414
exc = KeyError('message')
1515
assert str(exc) == "'message'"
16-
round_trip_repr(exc)
16+
assert round_trip_repr(exc)
1717

1818
exc = KeyError('message', 'another message')
1919
assert str(exc) == "('message', 'another message')"
20-
round_trip_repr(exc)
20+
assert round_trip_repr(exc)
2121
assert exc.args[0] == 'message'
2222
assert exc.args[1] == 'another message'
2323

@@ -31,7 +31,7 @@ def __eq__(self, other):
3131

3232
exc = KeyError(A())
3333
assert str(exc) == 'A()'
34-
round_trip_repr(exc)
34+
assert round_trip_repr(exc)
3535

3636
# ImportError / ModuleNotFoundError
3737
exc = ImportError()

tests/snippets/json_snippet.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ def round_trip_test(obj):
55
# serde_json and Python's json module produce slightly differently spaced
66
# output; direct string comparison can't pass on both so we use this as a
77
# proxy
8-
assert obj == json.loads(json.dumps(obj))
8+
return obj == json.loads(json.dumps(obj))
99

1010
assert '"string"' == json.dumps("string")
1111
assert "1" == json.dumps(1)
@@ -17,7 +17,7 @@ def round_trip_test(obj):
1717
assert '[]' == json.dumps([])
1818
assert '[1]' == json.dumps([1])
1919
assert '[[1]]' == json.dumps([[1]])
20-
round_trip_test([1, "string", 1.0, True])
20+
assert round_trip_test([1, "string", 1.0, True])
2121

2222
assert '[]' == json.dumps(())
2323
assert '[1]' == json.dumps((1,))
@@ -26,7 +26,7 @@ def round_trip_test(obj):
2626
assert [1, "string", 1.0, True] == json.loads(json.dumps((1, "string", 1.0, True)))
2727

2828
assert '{}' == json.dumps({})
29-
round_trip_test({'a': 'b'})
29+
assert round_trip_test({'a': 'b'})
3030

3131
# should reject non-str keys in jsons
3232
assert_raises(json.JSONDecodeError, lambda: json.loads('{3: "abc"}'))

0 commit comments

Comments
 (0)