Skip to content

Commit a07be0e

Browse files
committed
Start on test_compat
And rename test_attributes to test_toplevel accordingly.
1 parent 5b1fa58 commit a07be0e

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

test/deprecation/test_compat.py

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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")

test/deprecation/test_attributes.py renamed to test/deprecation/test_toplevel.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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
33
Provided mypy has ``warn_unused_ignores = true`` set, running mypy on these test cases
44
checks static typing of the code under test. This is the reason for the many separate
@@ -31,13 +31,13 @@
3131

3232

3333
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."""
3535
with pytest.raises(AttributeError):
3636
git.foo # type: ignore[attr-defined]
3737

3838

3939
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."""
4141
with pytest.raises(ImportError):
4242
from git import foo # type: ignore[attr-defined] # noqa: F401
4343

0 commit comments

Comments
 (0)