diff --git a/.github/workflows/build-backend.yml b/.github/workflows/build-backend.yml index 47e8603..4b49436 100644 --- a/.github/workflows/build-backend.yml +++ b/.github/workflows/build-backend.yml @@ -68,6 +68,12 @@ jobs: run: | curl http://localhost:2000/liveness || echo "Sandbox not reachable" + # Run Unit Tests + - name: Run Unit Tests + working-directory: ./curio + run: | + python -m unittest discover -p "test_*.py" -v + # Stop all servers - name: Stop all servers run: | diff --git a/sandbox/.gitignore b/sandbox/.gitignore index 660eedd..f2ece34 100644 --- a/sandbox/.gitignore +++ b/sandbox/.gitignore @@ -7,4 +7,6 @@ Milan* images Census* model.pth -dataset \ No newline at end of file +dataset +*__pycache__* +*.cpython-39.pyc \ No newline at end of file diff --git a/sandbox/__init__.py b/sandbox/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/sandbox/tests/__init__.py b/sandbox/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/sandbox/tests/test_running.py b/sandbox/tests/test_running.py new file mode 100644 index 0000000..f26549d --- /dev/null +++ b/sandbox/tests/test_running.py @@ -0,0 +1,33 @@ +import unittest +import json +from sandbox.running import * + +class TestToJsonInput(unittest.TestCase): + + def test_simple_input(self): + input_data = '{"dataType": "inputs", "data": {"key": "value"}}' + expected_output = {"dataType": "inputs", "data": {"key": "value"}} + + result = toJsonInput(input_data) + self.assertEqual(result, expected_output) + + def test_nested_outputs(self): + # This test will raise a TypeError because the recursive call sends a dict to json.loads + input_data = '{"dataType": "outputs", "data": [{"dataType": "outputs", "data": [{"key": "value"}]}]}' + with self.assertRaises(TypeError): + toJsonInput(input_data) + + def test_no_data_type(self): + # This test will raise a KeyError because 'dataType' key is missing + input_data = '{"data": {"key": "value"}}' + with self.assertRaises(KeyError): + toJsonInput(input_data) + + def test_invalid_json(self): + # Tests invalid JSON formatting + input_data = '{"dataType": "outputs", "data": [}' + with self.assertRaises(json.JSONDecodeError): + toJsonInput(input_data) + +if __name__ == "__main__": + unittest.main()