File tree 2 files changed +36
-3
lines changed
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.
2
2
3
3
Provided mypy has ``warn_unused_ignores = true`` set, running mypy on these test cases
4
4
checks static typing of the code under test. This is the reason for the many separate
31
31
32
32
33
33
def 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."""
35
35
with pytest .raises (AttributeError ):
36
36
git .foo # type: ignore[attr-defined]
37
37
38
38
39
39
def 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."""
41
41
with pytest .raises (ImportError ):
42
42
from git import foo # type: ignore[attr-defined] # noqa: F401
43
43
You can’t perform that action at this time.
0 commit comments