From f22b2d132412b1720b57e1fa9289ea808b44b2e2 Mon Sep 17 00:00:00 2001 From: GhaziSyed <115798228+GhaziSyed@users.noreply.github.com> Date: Wed, 17 Jul 2024 16:14:17 +0530 Subject: [PATCH] Unit tests for verifying imports (#24) - added a script that runs unit tests to see if library imports of fmperf are working - also added a github action workflow to automate the testing upon push and pull request --- .github/workflows/unittests.yml | 27 +++++++++++++++++++++++ README.md | 2 +- fmperf/tests/test_import.py | 39 +++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/unittests.yml create mode 100644 fmperf/tests/test_import.py diff --git a/.github/workflows/unittests.yml b/.github/workflows/unittests.yml new file mode 100644 index 0000000..d897137 --- /dev/null +++ b/.github/workflows/unittests.yml @@ -0,0 +1,27 @@ +name: Pytest + +on: [push, pull_request] + +jobs: + test: + + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Set up Python 3.11 + uses: actions/setup-python@v2 + with: + python-version: 3.11 + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -e . + pip install -r requirements.txt + + - name: Run tests + run: | + pytest fmperf/tests/ \ No newline at end of file diff --git a/README.md b/README.md index e6988f1..82a2f09 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ Firstly, one can generate a set of requests assuming simple uniform distribution ```bash docker run --env-file .env -it --rm -v $(pwd)/requests:/requests fmperf python -m fmperf.loadgen.generate-input ``` -Alternatively, one can generate a set of requests using models that have been trained on requests sent to the internal production deployment of BAM: +Alternatively, one can generate a set of requests using models that have been trained on requests sent to a production deployment: ```bash docker run --env-file .env -it --rm -v $(pwd)/requests:/requests fmperf python -m fmperf.loadgen.generate-input --from-model ``` diff --git a/fmperf/tests/test_import.py b/fmperf/tests/test_import.py new file mode 100644 index 0000000..516b2ff --- /dev/null +++ b/fmperf/tests/test_import.py @@ -0,0 +1,39 @@ +import unittest +import logging + + +# Configure logging +logging.basicConfig( + filename="test_logs.log", + level=logging.DEBUG, + format="%(asctime)s %(levelname)s:%(message)s", + filemode="w", +) +logging.debug("Logging configured successfully") + + +# Test class to check if the imports are working for the files in the examples folder +class TestImports(unittest.TestCase): + def setUp(self): + # Setup code goes here + logging.info("Running a test case.") + + def tearDown(self): + # Teardown code can go here, if we needed to clean up after tests + pass + + def test_fmperf_import(self): + """Test if fmperf import works correctly.""" + try: + import fmperf + + self.assertIsNotNone(fmperf) + logging.info("test_fmperf_import passed.") + except Exception as e: + logging.error(f"test_fmperf_import failed: {e}") + raise + + +if __name__ == "__main__": + unittest.main() + logging.getLogger().handlers[0].flush()