|
| 1 | +# |
| 2 | +# This source file is part of the Gel open source project. |
| 3 | +# |
| 4 | +# Copyright 2025-present Gel Data Inc. and the Gel authors. |
| 5 | +# |
| 6 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +# you may not use this file except in compliance with the License. |
| 8 | +# You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, software |
| 13 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +# See the License for the specific language governing permissions and |
| 16 | +# limitations under the License. |
| 17 | +# |
| 18 | + |
| 19 | +import pathlib |
| 20 | +import subprocess |
| 21 | +import sys |
| 22 | +import unittest |
| 23 | + |
| 24 | + |
| 25 | +def find_root_path() -> pathlib.Path: |
| 26 | + return pathlib.Path(__file__).parent.parent |
| 27 | + |
| 28 | + |
| 29 | +class TestSourceCode(unittest.TestCase): |
| 30 | + def test_cqa_mypy(self) -> None: |
| 31 | + root_path = find_root_path() |
| 32 | + config_path = root_path / "pyproject.toml" |
| 33 | + if not config_path.exists(): |
| 34 | + raise RuntimeError("could not locate pyproject.toml file") |
| 35 | + |
| 36 | + try: |
| 37 | + import mypy # NoQA |
| 38 | + except ImportError: |
| 39 | + raise unittest.SkipTest("mypy module is missing") |
| 40 | + |
| 41 | + for subdir in ["src", "tests"]: |
| 42 | + with self.subTest(subdir=subdir): |
| 43 | + try: |
| 44 | + subprocess.run( |
| 45 | + [ |
| 46 | + sys.executable, |
| 47 | + "-m", |
| 48 | + "mypy", |
| 49 | + "--config-file", |
| 50 | + config_path, |
| 51 | + subdir, |
| 52 | + ], |
| 53 | + check=True, |
| 54 | + stdout=subprocess.PIPE, |
| 55 | + stderr=subprocess.PIPE, |
| 56 | + cwd=root_path, |
| 57 | + ) |
| 58 | + except subprocess.CalledProcessError as ex: |
| 59 | + output = ex.stdout.decode() |
| 60 | + if ex.stderr: |
| 61 | + output += "\n\n" + ex.stderr.decode() |
| 62 | + raise AssertionError( |
| 63 | + f"mypy validation failed:\n{output}" |
| 64 | + ) from None |
| 65 | + |
| 66 | + def test_cqa_ruff(self): |
| 67 | + root_path = find_root_path() |
| 68 | + |
| 69 | + try: |
| 70 | + import ruff # type: ignore # NoQA |
| 71 | + except ImportError: |
| 72 | + raise unittest.SkipTest("ruff module is missing") |
| 73 | + |
| 74 | + for subdir in ["src", "tests"]: |
| 75 | + with self.subTest(subdir=subdir): |
| 76 | + try: |
| 77 | + subprocess.run( |
| 78 | + ["ruff", "check", subdir], |
| 79 | + check=True, |
| 80 | + stdout=subprocess.PIPE, |
| 81 | + stderr=subprocess.PIPE, |
| 82 | + cwd=root_path, |
| 83 | + ) |
| 84 | + except subprocess.CalledProcessError as ex: |
| 85 | + output = ex.output.decode() |
| 86 | + raise AssertionError( |
| 87 | + f"ruff validation failed:\n{output}" |
| 88 | + ) from None |
0 commit comments