Debian Codegraph @

flit_core/tests_core/test_build_thyself.py

raw
1 """Tests of flit_core building itself"""
2 import email.parser
3 import os
4 import os.path as osp
5 import pytest
6 import tarfile
7 from testpath import assert_isdir, assert_isfile
8 import zipfile
9
10 from flit_core import buildapi
11
12 @pytest.fixture()
13 def cwd_project():
14 proj_dir = osp.dirname(osp.dirname(osp.abspath(buildapi.__file__)))
15 if not osp.isfile(osp.join(proj_dir, 'pyproject.toml')):
16 pytest.skip("need flit_core source directory")
17
18 old_cwd = os.getcwd()
19 try:
20 os.chdir(proj_dir)
21 yield
22 finally:
23 os.chdir(old_cwd)
24
25
26 def test_prepare_metadata(tmp_path, cwd_project):
27 tmp_path = str(tmp_path)
28 dist_info = buildapi.prepare_metadata_for_build_wheel(tmp_path)
29
30 assert dist_info.endswith('.dist-info')
31 assert dist_info.startswith('flit_core')
32 dist_info = osp.join(tmp_path, dist_info)
33 assert_isdir(dist_info)
34
35 assert_isfile(osp.join(dist_info, 'WHEEL'))
36 assert_isfile(osp.join(dist_info, 'METADATA'))
37
38 # Check METADATA valid in a real package (test_common has minimal examples)
39 with open(osp.join(dist_info, 'METADATA'), 'rb') as f:
40 metadata_b = f.read()
41
42 assert email.parser.BytesParser().parsebytes(metadata_b).defects == []
43
44
45 def test_wheel(tmp_path, cwd_project):
46 tmp_path = str(tmp_path)
47 filename = buildapi.build_wheel(tmp_path)
48
49 assert filename.endswith('.whl')
50 assert filename.startswith('flit_core')
51 path = osp.join(tmp_path, filename)
52 assert_isfile(path)
53 assert zipfile.is_zipfile(path)
54
55
56 def test_sdist(tmp_path, cwd_project):
57 tmp_path = str(tmp_path)
58 filename = buildapi.build_sdist(tmp_path)
59
60 assert filename.endswith('.tar.gz')
61 assert filename.startswith('flit_core')
62 path = osp.join(tmp_path, filename)
63 assert_isfile(path)
64 assert tarfile.is_tarfile(path)