Skip to content

Commit fd7d71b

Browse files
committed
Add test for build utils
1 parent ba9f19c commit fd7d71b

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

linearmodels/tests/test_build.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import tempfile
2+
3+
import pytest
4+
5+
from linearmodels import __version__, version_tuple
6+
7+
try:
8+
from linearmodels._build.git_version import get_version, write_version_file
9+
10+
HAS_SETUPTOOLS_SCM = True
11+
except ImportError:
12+
HAS_SETUPTOOLS_SCM = False
13+
14+
15+
@pytest.mark.skipif(not HAS_SETUPTOOLS_SCM, reason="setuptools_scm is not installed")
16+
def test_get_version():
17+
try:
18+
version, version_fields = get_version()
19+
20+
assert isinstance(version, str)
21+
assert isinstance(version_fields, tuple)
22+
assert all(isinstance(v, (int, str)) for v in version_fields)
23+
except LookupError:
24+
pytest.skip("No git repository found")
25+
26+
27+
@pytest.mark.skipif(not HAS_SETUPTOOLS_SCM, reason="setuptools_scm is not installed")
28+
def test_write_version_file():
29+
with tempfile.NamedTemporaryFile(delete=False) as tmpfile:
30+
31+
write_version_file(tmpfile.name, __version__, version_tuple)
32+
with open(tmpfile.name, "r") as f:
33+
content = f.read()
34+
35+
assert f"__version__ = version = '{__version__}'" in content
36+
assert f"__version_tuple__ = version_tuple = {version_tuple}" in content

0 commit comments

Comments
 (0)