Visitar URL original
make exceptions repr tests Python 3.7-friendly by eval-repr round-trip by silmeth · Pull Request #1117 · RustPython/RustPython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
move asserts out of round trip test utils
  • Loading branch information
silmeth committed Jul 7, 2019
commit 1b539dedd0ee3d463095f6e725ba27185cbb6194
10 changes: 5 additions & 5 deletions tests/snippets/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ def exceptions_eq(e1, e2):
return type(e1) is type(e2) and e1.args == e2.args

def round_trip_repr(e):
assert exceptions_eq(e, eval(repr(e)))
return exceptions_eq(e, eval(repr(e)))

# KeyError
empty_exc = KeyError()
assert str(empty_exc) == ''
round_trip_repr(empty_exc)
assert round_trip_repr(empty_exc)
assert len(empty_exc.args) == 0
assert type(empty_exc.args) == tuple

exc = KeyError('message')
assert str(exc) == "'message'"
round_trip_repr(exc)
assert round_trip_repr(exc)

exc = KeyError('message', 'another message')
assert str(exc) == "('message', 'another message')"
round_trip_repr(exc)
assert round_trip_repr(exc)
assert exc.args[0] == 'message'
assert exc.args[1] == 'another message'

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

exc = KeyError(A())
assert str(exc) == 'A()'
round_trip_repr(exc)
assert round_trip_repr(exc)

# ImportError / ModuleNotFoundError
exc = ImportError()
Expand Down
6 changes: 3 additions & 3 deletions tests/snippets/json_snippet.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def round_trip_test(obj):
# serde_json and Python's json module produce slightly differently spaced
# output; direct string comparison can't pass on both so we use this as a
# proxy
assert obj == json.loads(json.dumps(obj))
return obj == json.loads(json.dumps(obj))

assert '"string"' == json.dumps("string")
assert "1" == json.dumps(1)
Expand All @@ -17,7 +17,7 @@ def round_trip_test(obj):
assert '[]' == json.dumps([])
assert '[1]' == json.dumps([1])
assert '[[1]]' == json.dumps([[1]])
round_trip_test([1, "string", 1.0, True])
assert round_trip_test([1, "string", 1.0, True])

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

assert '{}' == json.dumps({})
round_trip_test({'a': 'b'})
assert round_trip_test({'a': 'b'})

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