Skip to content

Commit

Permalink
add run_tests CLI command (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
giancastro authored Dec 16, 2024
1 parent fa75f68 commit 6b91a40
Show file tree
Hide file tree
Showing 30 changed files with 89 additions and 24 deletions.
7 changes: 1 addition & 6 deletions .github/workflows/conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,10 @@ jobs:
miniconda-version: "latest"
python-version: ${{ matrix.python-version }}
channels: conda-forge
auto-activate-base: true

- name: Prepare
run: conda install conda-build conda-verify pytest

- name: Build
run: conda build conda.recipe

- name: Install
run: conda install -c ${CONDA_PREFIX}/conda-bld/ pyrte_rrtmgp

- name: Test
run: pytest tests
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ include(ExternalProject REQUIRED)
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
set(BUILD_COMMAND_STRING "set FC=%CMAKE_Fortran_COMPILER% && cd build && nmake /A")
else()
set(BUILD_COMMAND_STRING "FC=${CMAKE_Fortran_COMPILER} make -C build -j ${N}")
set(BUILD_COMMAND_STRING "FC=${CMAKE_Fortran_COMPILER} FCFLAGS='-fPIC' make -C build -j ${N}")
endif()

ExternalProject_Add(
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,10 @@ Once built, the module will be located in a folder called `pyrte_rrtmgp`
<!-- end-local-build-section -->
## Pytest Setup Instructions
## Running Tests
* Go to the 'tests' folder: `cd tests/`
* Install the test prerequisites (if you haven't already) by running `pip3 install -r requirements-test.txt`
* Run `pytest tests`
After installing the package, you can run the tests by executing the following command:
```bash
pyrte_rrtmgp run_tests
```
10 changes: 5 additions & 5 deletions conda.recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,24 @@ requirements:
- m2w64-gcc-fortran # [win]
- libuv==1.44.2
- cmake==3.26.4
- git==2.44.0
- make==4.3
- git
- make

host:
- python
- pip
- scikit-build-core
- pybind11 >=2.10.0
- numpy >=1.21.0
- pytest>=7.4

run:
- python
- numpy >=1.21.0
- xarray >=2023.5.0
- netcdf4 >=1.5.7
- requests>=2.4.0
- pytest>=7.4

test:
imports:
Expand All @@ -47,10 +49,8 @@ test:
- xarray >=2023.5.0
- netcdf4 >=1.5.7
- requests>=2.4.0
source_files:
- tests
commands:
- pytest tests
- pyrte_rrtmgp run_tests

about:
summary: A Python interface to the RTE+RRTMGP Fortran software package.
Expand Down
26 changes: 18 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ version = "0.0.6"
description = "A Python interface to the RTE+RRTMGP Fortran software package."
readme = "README.md"
requires-python = ">=3.7"
dependencies = ["numpy>=2.0.0", "xarray>=2023.5.0", "netcdf4>=1.5.7", "requests>=2.4.0"]
dependencies = [
"numpy>=2.0.0",
"xarray>=2023.5.0",
"netcdf4>=1.5.7",
"requests>=2.4.0",
"pytest>=6.0.0"
]
classifiers = [
"Development Status :: 4 - Beta",
"License :: OSI Approved :: MIT License",
Expand All @@ -18,20 +24,25 @@ classifiers = [
"Programming Language :: Python :: 3.13",
]

[project.optional-dependencies]
test = [
"pytest>=6.0.0",
"numpy>=2.0.0",
"xarray>=2023.5.0",
"netcdf4>=1.5.7",
"requests>=2.4.0"
]

[project.scripts]
pyrte_rrtmgp = "pyrte_rrtmgp.cli:main"

[build-system]
requires = ["scikit-build-core>=0.3.3", "pybind11"]
build-backend = "scikit_build_core.build"


[project.optional-dependencies]
test = ["pytest", "numpy>=2.0.0", "xarray>=2023.5.0", "netcdf4>=1.5.7", "requests>=2.4.0"]


[tool.scikit-build]
wheel.expand-macos-universal-tags = true


[tool.pytest.ini_options]
minversion = "6.0"
addopts = ["-ra", "--showlocals", "--strict-markers", "--strict-config"]
Expand All @@ -40,7 +51,6 @@ log_cli_level = "INFO"
filterwarnings = ["error"]
testpaths = ["tests"]


[tool.cibuildwheel]
test-command = "pytest {project}/tests"
test-extras = ["test"]
Expand Down
58 changes: 58 additions & 0 deletions pyrte_rrtmgp/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import argparse
import os
import sys
import subprocess


def run_tests():
"""Run tests using pytest."""
package_root = os.path.dirname(os.path.abspath(__file__))
tests_path = os.path.join(package_root, "tests")

if not os.path.exists(tests_path):
print(f"Error: Test directory '{tests_path}' does not exist.")
sys.exit(1)

try:
print("Running tests...")
result = subprocess.run(
[sys.executable, "-m", "pytest", tests_path],
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
)
print(result.stdout)
print("All tests passed successfully.")
except subprocess.CalledProcessError as e:
print("Tests failed!")
print(e.stdout)
print(e.stderr)
sys.exit(e.returncode)


def main():
parser = argparse.ArgumentParser(
description="pyRTE-RRTMGP command line interface"
)
subparsers = parser.add_subparsers(
dest="command",
help="Available commands",
)

run_tests_parser = subparsers.add_parser(
"run_tests",
help="Run the test suite",
)
run_tests_parser.set_defaults(func=run_tests)

args = parser.parse_args()

if args.command:
args.func()
else:
parser.print_help()


if __name__ == "__main__":
main()
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 6b91a40

Please sign in to comment.