Skip to content

Commit 3715cc1

Browse files
authored
✅ Migrate/add tests (#7)
1 parent 4354c1a commit 3715cc1

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

tests/test_main.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import pickle
2+
3+
from typing_extensions import Annotated, get_type_hints
4+
15
from annotated_doc import Doc
26

37

@@ -9,3 +13,41 @@ def test_doc_basic() -> None:
913
assert doc == Doc("This is a test documentation.")
1014
assert doc != Doc("Different documentation.")
1115
assert doc != "Not a Doc instance"
16+
17+
18+
def test_annotation():
19+
def hi(name: Annotated[str, Doc("Who to say hi to")]) -> None: # pragma: no cover
20+
pass
21+
22+
hints = get_type_hints(hi, include_extras=True)
23+
doc_info: Doc = hints["name"].__metadata__[0]
24+
assert doc_info.documentation == "Who to say hi to"
25+
assert isinstance(doc_info, Doc)
26+
27+
28+
def test_repr():
29+
doc_info = Doc("Who to say hi to")
30+
assert repr(doc_info) == "Doc('Who to say hi to')"
31+
32+
33+
def test_hashability():
34+
doc_info = Doc("Who to say hi to")
35+
assert isinstance(hash(doc_info), int)
36+
assert hash(doc_info) != hash(Doc("Who not to say hi to"))
37+
38+
39+
def test_equality():
40+
doc_info = Doc("Who to say hi to")
41+
# Equal to itself
42+
assert doc_info == doc_info
43+
# Equal to another instance with the same string
44+
assert doc_info == Doc("Who to say hi to")
45+
# Not equal to another instance with a different string
46+
assert doc_info != Doc("Who not to say hi to")
47+
48+
49+
def test_pickle():
50+
doc_info = Doc("Who to say hi to")
51+
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
52+
pickled = pickle.dumps(doc_info, protocol=proto)
53+
assert doc_info == pickle.loads(pickled)

0 commit comments

Comments
 (0)