summaryrefslogtreecommitdiffstats
path: root/flit_core/flit_core/tests/test_build_thyself.py
blob: ad15819db57bf78aa5ab3c06ebdeb45878af2ce2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""Tests of flit_core building itself"""
import os
import os.path as osp
import pytest
import tarfile
from testpath import assert_isdir, assert_isfile
import zipfile

from flit_core import buildapi

@pytest.fixture()
def cwd_project():
    proj_dir = osp.dirname(osp.dirname(osp.abspath(buildapi.__file__)))
    if not osp.isfile(osp.join(proj_dir, 'pyproject.toml')):
        pytest.skip("need flit_core source directory")

    old_cwd = os.getcwd()
    try:
        os.chdir(proj_dir)
        yield
    finally:
        os.chdir(old_cwd)


def test_prepare_metadata(tmp_path, cwd_project):
    tmp_path = str(tmp_path)
    dist_info = buildapi.prepare_metadata_for_build_wheel(tmp_path)

    assert dist_info.endswith('.dist-info')
    assert dist_info.startswith('flit_core')
    dist_info = osp.join(tmp_path, dist_info)
    assert_isdir(dist_info)

    assert_isfile(osp.join(dist_info, 'WHEEL'))
    assert_isfile(osp.join(dist_info, 'METADATA'))


def test_wheel(tmp_path, cwd_project):
    tmp_path = str(tmp_path)
    filename = buildapi.build_wheel(tmp_path)

    assert filename.endswith('.whl')
    assert filename.startswith('flit_core')
    path = osp.join(tmp_path, filename)
    assert_isfile(path)
    assert zipfile.is_zipfile(path)


def test_sdist(tmp_path, cwd_project):
    tmp_path = str(tmp_path)
    filename = buildapi.build_sdist(tmp_path)

    assert filename.endswith('.tar.gz')
    assert filename.startswith('flit_core')
    path = osp.join(tmp_path, filename)
    assert_isfile(path)
    assert tarfile.is_tarfile(path)