Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CI/CD] adding tests for backend build #2

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/build-backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
4 changes: 3 additions & 1 deletion sandbox/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ Milan*
images
Census*
model.pth
dataset
dataset
*__pycache__*
*.cpython-39.pyc
Empty file added sandbox/__init__.py
Empty file.
Empty file added sandbox/tests/__init__.py
Empty file.
33 changes: 33 additions & 0 deletions sandbox/tests/test_running.py
Original file line number Diff line number Diff line change
@@ -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()
Loading