File: test_hello_fortran.py

package info (click to toggle)
scikit-build 0.18.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,768 kB
  • sloc: python: 5,259; cpp: 284; makefile: 171; f90: 12; sh: 7
file content (77 lines) | stat: -rw-r--r-- 2,376 bytes parent folder | download | duplicates (2)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""test_hello_fortran
---------------------

Tries to build and test the `hello-fortran` sample project.
"""

from __future__ import annotations

import glob
import os
import shutil
import sys

import pytest

from . import get_ext_suffix, project_setup_py_test
from .pytest_helpers import check_sdist_content, check_wheel_content

pytest.importorskip("numpy")


@pytest.mark.fortran()
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Fortran not supported on Windows")
@pytest.mark.skipif(not ("FC" in os.environ or shutil.which("gfortran")), reason="GFortran required")
@project_setup_py_test("hello-fortran", ["build"])
def test_hello_fortran_build():
    pass


@pytest.mark.fortran()
@project_setup_py_test("hello-fortran", ["sdist"])
def test_hello_fortran_sdist():
    sdists_tar = glob.glob("dist/*.tar.gz")
    sdists_zip = glob.glob("dist/*.zip")
    assert sdists_tar or sdists_zip

    dirname = "hello-fortran-1.2.3"
    # setuptools 69.3.0 and above now canonicalize the filename as well.
    if any("hello_fortran" in x for x in sdists_zip + sdists_tar):
        dirname = "hello_fortran-1.2.3"

    expected_content = [
        f"{dirname}/bonjour/_bonjour.f90",
        f"{dirname}/bonjour/_bonjour.pyf",
        f"{dirname}/bonjour/CMakeLists.txt",
        f"{dirname}/CMakeLists.txt",
        f"{dirname}/hello/_hello.f90",
        f"{dirname}/hello/CMakeLists.txt",
        f"{dirname}/hello/__init__.py",
        f"{dirname}/hello/__main__.py",
        f"{dirname}/setup.py",
    ]

    sdist_archive = f"dist/{dirname}.zip"
    if sdists_tar:
        sdist_archive = f"dist/{dirname}.tar.gz"

    check_sdist_content(sdist_archive, dirname, expected_content)


@pytest.mark.fortran()
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Fortran not supported on Windows")
@pytest.mark.skipif(not ("FC" in os.environ or shutil.which("gfortran")), reason="GFortran required")
@project_setup_py_test("hello-fortran", ["bdist_wheel"])
def test_hello_fortran_wheel():
    expected_content = [
        f"hello/_bonjour{get_ext_suffix()}",
        f"hello/_hello{get_ext_suffix()}",
        "hello/__init__.py",
        "hello/__main__.py",
    ]

    expected_distribution_name = "hello_fortran-1.2.3"

    whls = glob.glob("dist/*.whl")
    assert len(whls) == 1
    check_wheel_content(whls[0], expected_distribution_name, expected_content)