Skip to content

Commit

Permalink
Unit tests for verifying imports (#24)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
GhaziSyed authored Jul 17, 2024
1 parent 073f36e commit f22b2d1
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
27 changes: 27 additions & 0 deletions .github/workflows/unittests.yml
Original file line number Diff line number Diff line change
@@ -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/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down
39 changes: 39 additions & 0 deletions fmperf/tests/test_import.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit f22b2d1

Please sign in to comment.