|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | + |
| 18 | +"""Tests verifying that the sdist includes tests and examples. |
| 19 | +
|
| 20 | +Per Apache release policy, voters must be able to build from source |
| 21 | +and run tests to validate. These tests ensure that pyproject.toml |
| 22 | +is configured to include tests/ and examples/ in the source distribution. |
| 23 | +""" |
| 24 | + |
| 25 | +import sys |
| 26 | +from pathlib import Path |
| 27 | + |
| 28 | +if sys.version_info >= (3, 11): |
| 29 | + import tomllib |
| 30 | +else: |
| 31 | + import tomli as tomllib |
| 32 | + |
| 33 | + |
| 34 | +def get_sdk_dir() -> Path: |
| 35 | + return Path(__file__).resolve().parent.parent |
| 36 | + |
| 37 | + |
| 38 | +def load_sdist_config() -> dict: |
| 39 | + pyproject = get_sdk_dir() / "pyproject.toml" |
| 40 | + with open(pyproject, "rb") as f: |
| 41 | + config = tomllib.load(f) |
| 42 | + return config["tool"]["flit"]["sdist"] |
| 43 | + |
| 44 | + |
| 45 | +class TestSdistIncludesTests: |
| 46 | + """Verify tests are included in the source distribution.""" |
| 47 | + |
| 48 | + def test_tests_in_sdist_include(self): |
| 49 | + sdist = load_sdist_config() |
| 50 | + includes = sdist.get("include", []) |
| 51 | + assert "tests/**" in includes, ( |
| 52 | + "pyproject.toml [tool.flit.sdist] must include 'tests/**'. " |
| 53 | + "Apache release policy requires tests in the source tarball." |
| 54 | + ) |
| 55 | + |
| 56 | + def test_tests_not_in_sdist_exclude(self): |
| 57 | + sdist = load_sdist_config() |
| 58 | + excludes = sdist.get("exclude", []) |
| 59 | + assert "tests/**" not in excludes, ( |
| 60 | + "pyproject.toml [tool.flit.sdist] must not exclude 'tests/**'. " |
| 61 | + "Apache release policy requires tests in the source tarball." |
| 62 | + ) |
| 63 | + |
| 64 | + |
| 65 | +class TestSdistIncludesExamples: |
| 66 | + """Verify examples are included in the source distribution.""" |
| 67 | + |
| 68 | + def test_examples_in_sdist_include(self): |
| 69 | + sdist = load_sdist_config() |
| 70 | + includes = sdist.get("include", []) |
| 71 | + assert "examples/**" in includes, ( |
| 72 | + "pyproject.toml [tool.flit.sdist] must include 'examples/**'. " |
| 73 | + "Examples help voters validate the package works correctly." |
| 74 | + ) |
| 75 | + |
| 76 | + def test_examples_not_in_sdist_exclude(self): |
| 77 | + sdist = load_sdist_config() |
| 78 | + excludes = sdist.get("exclude", []) |
| 79 | + assert "examples/**" not in excludes, ( |
| 80 | + "pyproject.toml [tool.flit.sdist] must not exclude 'examples/**'." |
| 81 | + ) |
| 82 | + |
| 83 | + |
| 84 | +class TestSdistExcludesBinaries: |
| 85 | + """Verify binary files are excluded to keep tarballs source-only.""" |
| 86 | + |
| 87 | + def test_parquet_excluded(self): |
| 88 | + sdist = load_sdist_config() |
| 89 | + excludes = sdist.get("exclude", []) |
| 90 | + assert "**/*.parquet" in excludes, ( |
| 91 | + "pyproject.toml [tool.flit.sdist] must exclude '**/*.parquet'. " |
| 92 | + "Binary files should not be in source tarballs." |
| 93 | + ) |
| 94 | + |
| 95 | + def test_pkl_excluded(self): |
| 96 | + sdist = load_sdist_config() |
| 97 | + excludes = sdist.get("exclude", []) |
| 98 | + assert "**/*.pkl" in excludes, ( |
| 99 | + "pyproject.toml [tool.flit.sdist] must exclude '**/*.pkl'. " |
| 100 | + "Binary files should not be in source tarballs." |
| 101 | + ) |
| 102 | + |
| 103 | + def test_ipynb_excluded(self): |
| 104 | + sdist = load_sdist_config() |
| 105 | + excludes = sdist.get("exclude", []) |
| 106 | + assert "**/*.ipynb" in excludes, ( |
| 107 | + "pyproject.toml [tool.flit.sdist] must exclude '**/*.ipynb'. " |
| 108 | + "Notebooks should not be in source tarballs." |
| 109 | + ) |
0 commit comments