Skip to content

Commit a0ef537

Browse files
committed
Start on test_types
1 parent 96089c8 commit a0ef537

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

test/deprecation/test_types.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""Tests for dynamic and static characteristics of git.types module attributes."""
2+
3+
import sys
4+
5+
if sys.version_info >= (3, 8):
6+
from typing import Literal
7+
else:
8+
from typing_extensions import Literal
9+
10+
import pytest
11+
12+
import git.types
13+
14+
15+
def test_cannot_access_undefined() -> None:
16+
"""Accessing a bogus attribute in git.types remains a dynamic and static error."""
17+
with pytest.raises(AttributeError):
18+
git.types.foo # type: ignore[attr-defined]
19+
20+
21+
def test_lit_commit_ish() -> None:
22+
""" """
23+
# It would be fine to test attribute access rather than a "from" import. But a
24+
# "from" import is more likely to appear in actual usage, so it is used here.
25+
with pytest.deprecated_call() as ctx:
26+
from git.types import Lit_commit_ish
27+
28+
# As noted in test_toplevel.test_util_alias_import, there may be multiple warnings,
29+
# but all with the same message.
30+
(message,) = {str(entry.message) for entry in ctx}
31+
assert "Lit_commit_ish is deprecated." in message
32+
assert 'Literal["commit", "tag", "blob", "tree"]' in message, "Has old definition."
33+
assert 'Literal["commit", "tag"]' in message, "Has new definition."
34+
assert "GitObjectTypeString" in message, "Has new type name for old definition."
35+
36+
_: Lit_commit_ish = "commit" # type: ignore[valid-type]
37+
38+
# It should be as documented (even though deliberately unusable in static checks).
39+
assert Lit_commit_ish == Literal["commit", "tag"]

0 commit comments

Comments
 (0)