4
4
5
5
import pytest
6
6
7
+ from setuptools ._static import is_static
7
8
from setuptools .config import expand
8
9
from setuptools .discovery import find_package_path
9
10
@@ -93,11 +94,15 @@ def test_read_attr(self, tmp_path, monkeypatch):
93
94
with monkeypatch .context () as m :
94
95
m .chdir (tmp_path )
95
96
# Make sure it can read the attr statically without evaluating the module
96
- assert expand .read_attr ('pkg.sub.VERSION' ) == '0.1.1'
97
+ version = expand .read_attr ('pkg.sub.VERSION' )
97
98
values = expand .read_attr ('lib.mod.VALUES' , {'lib' : 'pkg/sub' })
98
99
100
+ assert version == '0.1.1'
101
+ assert is_static (values )
102
+
99
103
assert values ['a' ] == 0
100
104
assert values ['b' ] == {42 }
105
+ assert is_static (values )
101
106
102
107
# Make sure the same APIs work outside cwd
103
108
assert expand .read_attr ('pkg.sub.VERSION' , root_dir = tmp_path ) == '0.1.1'
@@ -118,7 +123,28 @@ def test_read_annotated_attr(self, tmp_path, example):
118
123
}
119
124
write_files (files , tmp_path )
120
125
# Make sure this attribute can be read statically
121
- assert expand .read_attr ('pkg.sub.VERSION' , root_dir = tmp_path ) == '0.1.1'
126
+ version = expand .read_attr ('pkg.sub.VERSION' , root_dir = tmp_path )
127
+ assert version == '0.1.1'
128
+ assert is_static (version )
129
+
130
+ @pytest .mark .parametrize (
131
+ "example" ,
132
+ [
133
+ "VERSION = (lambda: '0.1.1')()\n " ,
134
+ "def fn(): return '0.1.1'\n VERSION = fn()\n " ,
135
+ "VERSION: str = (lambda: '0.1.1')()\n " ,
136
+ ],
137
+ )
138
+ def test_read_dynamic_attr (self , tmp_path , monkeypatch , example ):
139
+ files = {
140
+ "pkg/__init__.py" : "" ,
141
+ "pkg/sub/__init__.py" : example ,
142
+ }
143
+ write_files (files , tmp_path )
144
+ monkeypatch .chdir (tmp_path )
145
+ version = expand .read_attr ('pkg.sub.VERSION' )
146
+ assert version == '0.1.1'
147
+ assert not is_static (version )
122
148
123
149
def test_import_order (self , tmp_path ):
124
150
"""
0 commit comments