From 6114818cd1ff798819d4306cffb786fe63946d8c Mon Sep 17 00:00:00 2001 From: sajal1123 <113067506+sajal1123@users.noreply.github.com> Date: Tue, 8 Oct 2024 22:42:12 -0700 Subject: [PATCH 1/2] adding tests for running.py --- sandbox/.gitignore | 4 +++- sandbox/__init__.py | 0 sandbox/tests/__init__.py | 0 sandbox/tests/test_running.py | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 sandbox/__init__.py create mode 100644 sandbox/tests/__init__.py create mode 100644 sandbox/tests/test_running.py 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() From d7324d9831d573e6aba7ed56de272c695ecdf074 Mon Sep 17 00:00:00 2001 From: sajal1123 <113067506+sajal1123@users.noreply.github.com> Date: Tue, 8 Oct 2024 22:45:10 -0700 Subject: [PATCH 2/2] Update build-backend.yml -added step to run tests during build --- .github/workflows/build-backend.yml | 6 ++++++ 1 file changed, 6 insertions(+) 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: |