File tree Expand file tree Collapse file tree 2 files changed +36
-3
lines changed Expand file tree Collapse file tree 2 files changed +36
-3
lines changed Original file line number Diff line number Diff line change 1+ """Tests for dynamic and static errors and warnings in GitPython's git.compat module.
2+
3+ These tests verify that the is_<platform> aliases are available, and are even listed in
4+ the output of dir(), but issue warnings, and that bogus (misspelled or unrecognized)
5+ attribute access is still an error both at runtime and with mypy. This is similar to
6+ some of the tests in test_toplevel, but the situation being tested here is simpler
7+ because it does not involve unintuitive module aliasing or import behavior. So this only
8+ tests attribute access, not "from" imports (whose behavior can be intuitively inferred).
9+ """
10+
11+ import os
12+ import sys
13+
14+ import pytest
15+
16+ import git .compat
17+
18+
19+ _MESSAGE_LEADER = "{} and other is_<platform> aliases are deprecated."
20+
21+
22+ def test_cannot_access_undefined () -> None :
23+ """Accessing a bogus attribute in git.compat remains a dynamic and static error."""
24+ with pytest .raises (AttributeError ):
25+ git .compat .foo # type: ignore[attr-defined]
26+
27+
28+ def test_is_win () -> None :
29+ with pytest .deprecated_call () as ctx :
30+ value = git .compat .is_win
31+ (message ,) = [str (entry .message ) for entry in ctx ] # Exactly one message.
32+ assert message .startswith (_MESSAGE_LEADER .format ("git.compat.is_win" ))
33+ assert value == (os .name == "nt" )
Original file line number Diff line number Diff line change 1- """Tests for dynamic and static attribute errors in GitPython's top-level git module.
1+ """Tests for dynamic and static errors and warnings in GitPython's top-level git module.
22
33Provided mypy has ``warn_unused_ignores = true`` set, running mypy on these test cases
44checks static typing of the code under test. This is the reason for the many separate
3131
3232
3333def test_cannot_access_undefined () -> None :
34- """Accessing a bogus attribute in git remains both a dynamic and static error."""
34+ """Accessing a bogus attribute in git remains a dynamic and static error."""
3535 with pytest .raises (AttributeError ):
3636 git .foo # type: ignore[attr-defined]
3737
3838
3939def test_cannot_import_undefined () -> None :
40- """Importing a bogus attribute from git remains both a dynamic and static error."""
40+ """Importing a bogus attribute from git remains a dynamic and static error."""
4141 with pytest .raises (ImportError ):
4242 from git import foo # type: ignore[attr-defined] # noqa: F401
4343
You can’t perform that action at this time.
0 commit comments