Coverage for tests/test_main.py: 100%
33 statements
« prev ^ index » next coverage.py v7.10.7, created at 2026-10-19 03:36 +0000
« prev ^ index » next coverage.py v7.10.7, created at 2026-10-19 03:36 +0000
1import pickle 1abcdefghi
2from typing import Annotated, get_type_hints 1abcdefghi
4from annotated_doc import Doc 1abcdefghi
7def test_doc_basic() -> None: 1abcdefghi
8 doc = Doc("This is a test documentation.") 1jklmnopqr
9 assert doc.documentation == "This is a test documentation." 1jklmnopqr
10 assert repr(doc) == "Doc('This is a test documentation.')" 1jklmnopqr
11 assert hash(doc) == hash("This is a test documentation.") 1jklmnopqr
12 assert doc == Doc("This is a test documentation.") 1jklmnopqr
13 assert doc != Doc("Different documentation.") 1jklmnopqr
14 assert doc != "Not a Doc instance" 1jklmnopqr
17def test_annotation(): 1abcdefghi
18 def hi(name: Annotated[str, Doc("Who to say hi to")]) -> None: # pragma: no cover 1stuvwxyzA
19 pass
21 hints = get_type_hints(hi, include_extras=True) 1stuvwxyzA
22 doc_info: Doc = hints["name"].__metadata__[0] 1stuvwxyzA
23 assert doc_info.documentation == "Who to say hi to" 1stuvwxyzA
24 assert isinstance(doc_info, Doc) 1stuvwxyzA
27def test_repr(): 1abcdefghi
28 doc_info = Doc("Who to say hi to") 123456789!
29 assert repr(doc_info) == "Doc('Who to say hi to')" 123456789!
32def test_hashability(): 1abcdefghi
33 doc_info = Doc("Who to say hi to") 1TUVWXYZ01
34 assert isinstance(hash(doc_info), int) 1TUVWXYZ01
35 assert hash(doc_info) != hash(Doc("Who not to say hi to")) 1TUVWXYZ01
38def test_equality(): 1abcdefghi
39 doc_info = Doc("Who to say hi to") 1BCDEFGHIJ
40 # Equal to itself
41 assert doc_info == doc_info 1BCDEFGHIJ
42 # Equal to another instance with the same string
43 assert doc_info == Doc("Who to say hi to") 1BCDEFGHIJ
44 # Not equal to another instance with a different string
45 assert doc_info != Doc("Who not to say hi to") 1BCDEFGHIJ
48def test_pickle(): 1abcdefghi
49 doc_info = Doc("Who to say hi to") 1KLMNOPQRS
50 for proto in range(pickle.HIGHEST_PROTOCOL + 1): 1KLMNOPQRS
51 pickled = pickle.dumps(doc_info, protocol=proto) 1KLMNOPQRS
52 assert doc_info == pickle.loads(pickled) 1KLMNOPQRS