1
1
"""Tests for dynamic and static attribute errors."""
2
2
3
+ import importlib
4
+
3
5
import pytest
4
6
5
7
@@ -12,4 +14,89 @@ def test_cannot_get_undefined() -> None:
12
14
13
15
def test_cannot_import_undefined () -> None :
14
16
with pytest .raises (ImportError ):
15
- from git import foo
17
+ from git import foo # noqa: F401
18
+
19
+
20
+ def test_util_alias_access_resolves () -> None :
21
+ """These resolve for now, though they're private we do not guarantee this."""
22
+ import git
23
+
24
+ assert git .util is git .index .util
25
+
26
+
27
+ def test_util_alias_import_resolves () -> None :
28
+ from git import util
29
+ import git
30
+
31
+ util is git .index .util
32
+
33
+
34
+ def test_util_alias_access_warns () -> None :
35
+ import git
36
+
37
+ with pytest .deprecated_call () as ctx :
38
+ git .util
39
+
40
+ assert len (ctx ) == 1
41
+ message = ctx [0 ].message .args [0 ]
42
+ assert "git.util" in message
43
+ assert "git.index.util" in message
44
+ assert "should not be relied on" in message
45
+
46
+
47
+ def test_util_alias_import_warns () -> None :
48
+ with pytest .deprecated_call () as ctx :
49
+ from git import util # noqa: F401
50
+
51
+ message = ctx [0 ].message .args [0 ]
52
+ assert "git.util" in message
53
+ assert "git.index.util" in message
54
+ assert "should not be relied on" in message
55
+
56
+
57
+ _parametrize_by_private_alias = pytest .mark .parametrize (
58
+ "name, fullname" ,
59
+ [
60
+ ("head" , "git.refs.head" ),
61
+ ("log" , "git.refs.log" ),
62
+ ("reference" , "git.refs.reference" ),
63
+ ("symbolic" , "git.refs.symbolic" ),
64
+ ("tag" , "git.refs.tag" ),
65
+ ("base" , "git.index.base" ),
66
+ ("fun" , "git.index.fun" ),
67
+ ("typ" , "git.index.typ" ),
68
+ ],
69
+ )
70
+
71
+
72
+ @_parametrize_by_private_alias
73
+ def test_private_module_alias_access_resolves (name : str , fullname : str ) -> None :
74
+ """These resolve for now, though they're private we do not guarantee this."""
75
+ import git
76
+
77
+ assert getattr (git , name ) is importlib .import_module (fullname )
78
+
79
+
80
+ @_parametrize_by_private_alias
81
+ def test_private_module_alias_import_resolves (name : str , fullname : str ) -> None :
82
+ exec (f"from git import { name } " )
83
+ locals ()[name ] is importlib .import_module (fullname )
84
+
85
+
86
+ @_parametrize_by_private_alias
87
+ def test_private_module_alias_access_warns (name : str , fullname : str ) -> None :
88
+ import git
89
+
90
+ with pytest .deprecated_call () as ctx :
91
+ getattr (git , name )
92
+
93
+ assert len (ctx ) == 1
94
+ assert ctx [0 ].message .args [0 ].endswith (f"Use { fullname } instead." )
95
+
96
+
97
+ @_parametrize_by_private_alias
98
+ def test_private_module_alias_import_warns (name : str , fullname : str ) -> None :
99
+ with pytest .deprecated_call () as ctx :
100
+ exec (f"from git import { name } " )
101
+
102
+ assert ctx [0 ].message .args [0 ].endswith (f"Use { fullname } instead." )
0 commit comments