Skip to content

Commit a050e3e

Browse files
committed
Add test_format to check repr()/str()
Verifies that OrderedSet.__repr__/OrderedSet.__str__ are using the expected formatting.
1 parent 7289aa8 commit a050e3e

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

tests/test_simple.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ def test_dedup():
5656
assert list(OrderedSet.dedup(example)) == _remove_duplicates(example)
5757

5858

59+
def test_format():
60+
# OrderedSet.__repr__ needs to round trip through eval
61+
assert repr(OrderedSet([1, 2, 3])) == "OrderedSet([1, 2, 3])"
62+
assert repr(OrderedSet(["foo"])) == "OrderedSet(['foo'])"
63+
# OrderedSet.__str__ has no such requirement
64+
assert str(OrderedSet([1, 2, 3])) == "{1, 2, 3}"
65+
# however, it still should call repr on each element, not str
66+
assert str(OrderedSet([" "])) == "{' '}"
67+
68+
5969
@pytest.mark.asyncio
6070
async def test_async_dedup():
6171
for example in EXAMPLE_DATA:

0 commit comments

Comments
 (0)