From 9574ff0821ac7b254e19fc7e3c2315e42762a65b Mon Sep 17 00:00:00 2001 From: Matthew Archer <36638242+ma595@users.noreply.github.com> Date: Tue, 10 Dec 2024 22:21:40 +0000 Subject: [PATCH] Add a simple build and smoke workflow - and package (#20) * Add a build workflow * Add a smoke test workflow of forecast.py * Add preliminary package code to streamline tests --- .github/workflows/python.yml | 31 +++++++++++++++++++++++++++++++ lib/__init__.py | 0 pytest.ini | 2 ++ setup.py | 24 ++++++++++++++++++++++++ tests/test_forecast.py | 19 +++++++++++++++++++ 5 files changed, 76 insertions(+) create mode 100644 .github/workflows/python.yml create mode 100644 lib/__init__.py create mode 100644 pytest.ini create mode 100644 setup.py create mode 100644 tests/test_forecast.py diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml new file mode 100644 index 0000000..519c181 --- /dev/null +++ b/.github/workflows/python.yml @@ -0,0 +1,31 @@ +name: Build +on: + pull_request: + branches: + - main + push: + branches: + - main + +jobs: + Build: + runs-on: ubuntu-latest + name: Install + steps: + - name: Check out code + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.11' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install . + + - name: Smoke test + run: | + pip install pytest + pytest ./tests diff --git a/lib/__init__.py b/lib/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..5ee6477 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,2 @@ +[pytest] +testpaths = tests diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..bc2c8fc --- /dev/null +++ b/setup.py @@ -0,0 +1,24 @@ +from setuptools import setup, find_packages +import os + + +# Function to parse requirements.txt +def parse_requirements(filename): + """Load requirements from a pip requirements file.""" + with open(filename, "r") as file: + return file.read().splitlines() + + +# Get the list of requirements from requirements.txt +requirements_file = os.path.abspath( + os.path.join(os.path.dirname(__file__), "requirements.txt") +) +install_requires = parse_requirements(requirements_file) + +setup( + name="spinup_nemo", + version="0.1", + packages=find_packages(include=["lib"]), + package_dir={"": "."}, # The root directory is the base + install_requires=install_requires, +) diff --git a/tests/test_forecast.py b/tests/test_forecast.py new file mode 100644 index 0000000..16beb6c --- /dev/null +++ b/tests/test_forecast.py @@ -0,0 +1,19 @@ +""" +This file contains tests for the 'forecast' module in the 'lib' package. + +The tests are written using pytest. +""" + +import sys +import os +import pytest + + +def test_import_forecast(): + """Test that the forecast module can be imported successfully.""" + try: + import lib.forecast + + assert True, "forecast imported successfully." + except ImportError as e: + pytest.fail(f"Failed to import forecast: {e}")