Debian Codegraph @

flit_core/tests_core/test_wheel.py

raw
1 import os
2 import stat
3 import sys
4 from pathlib import Path
5 from zipfile import ZipFile
6
7 import pytest
8 from testpath import assert_isfile
9
10 from flit_core.wheel import make_wheel_in, main
11
12 samples_dir = Path(__file__).parent / 'samples'
13
14 def test_licenses_dir(tmp_path):
15 # Smoketest for https://github.com/pypa/flit/issues/399
16 info = make_wheel_in(samples_dir / 'inclusion' / 'pyproject.toml', tmp_path)
17 assert_isfile(info.file)
18
19
20 def test_source_date_epoch(tmp_path, monkeypatch):
21 monkeypatch.setenv('SOURCE_DATE_EPOCH', '1633007882')
22 info = make_wheel_in(samples_dir / 'pep621' / 'pyproject.toml', tmp_path)
23 assert_isfile(info.file)
24 # Minimum value for zip timestamps is 1980-1-1
25 with ZipFile(info.file, 'r') as zf:
26 assert zf.getinfo('module1a.py').date_time[:3] == (2021, 9, 30)
27
28
29 def test_zero_timestamp(tmp_path, monkeypatch):
30 monkeypatch.setenv('SOURCE_DATE_EPOCH', '0')
31 info = make_wheel_in(samples_dir / 'pep621' / 'pyproject.toml', tmp_path)
32 assert_isfile(info.file)
33 # Minimum value for zip timestamps is 1980-1-1
34 with ZipFile(info.file, 'r') as zf:
35 assert zf.getinfo('module1a.py').date_time == (1980, 1, 1, 0, 0, 0)
36
37
38 def test_main(tmp_path):
39 main(['--outdir', str(tmp_path), str(samples_dir / 'pep621')])
40 wheels = list(tmp_path.glob('*.whl'))
41 assert len(wheels) == 1
42 # Minimum value for zip timestamps is 1980-1-1
43 with ZipFile(wheels[0], 'r') as zf:
44 assert 'module1a.py' in zf.namelist()
45
46
47 def test_data_dir(tmp_path):
48 info = make_wheel_in(samples_dir / 'with_data_dir' / 'pyproject.toml', tmp_path)
49 assert_isfile(info.file)
50 with ZipFile(info.file, 'r') as zf:
51 assert 'module1-0.1.data/data/share/man/man1/foo.1' in zf.namelist()
52
53
54 def test_license_files(tmp_path):
55 info = make_wheel_in(samples_dir / 'pep621_license_files' / 'pyproject.toml', tmp_path)
56 assert_isfile(info.file)
57 with ZipFile(info.file, 'r') as zf:
58 assert 'module1-0.1.dist-info/licenses/LICENSE' in zf.namelist()
59 assert 'module1-0.1.dist-info/licenses/module/vendor/LICENSE_VENDOR' in zf.namelist()
60
61
62 @pytest.mark.skipif(sys.platform == 'win32', reason='Windows does not have Unix file permissions')
63 def test_wheel_file_permissions(tmp_path):
64 # mkstemp(), which is used to create the wheel before it's renamed to
65 # its final name, creates files with mode 0600. The built wheel file
66 # itself should not be left that restrictive. Regression test for
67 # https://github.com/pypa/flit/issues/804
68 info = make_wheel_in(samples_dir / 'pep621' / 'pyproject.toml', tmp_path)
69 assert_isfile(info.file)
70 mode = stat.S_IMODE(os.stat(info.file).st_mode)
71 assert mode & 0o777 == 0o644, oct(mode)