-
Notifications
You must be signed in to change notification settings - Fork 2
test(tes,wes): add comprehensive unit tests #17
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
de59af2
879a84a
ddaa0de
75ee3a5
29f774d
1300eb3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| { | ||
| "id": "task-id-1", | ||
| "name": "example-task-1", | ||
| "description": "Example task description 1", | ||
| "executors": [{"image": "executor-image-1"}], | ||
| "inputs": [ | ||
| {"url": "input-url-1", "path": "input-path-1"}, | ||
| {"url": "input-url-2", "path": "input-path-2"} | ||
| ], | ||
| "outputs": [ | ||
| {"url": "output-url-1", "path": "output-path-1"} | ||
| ], | ||
| "creation_time": "2023-07-10T14:30:00Z", | ||
| "logs": [{"end_time": "2023-07-10T15:30:00Z"}] | ||
| } | ||
|
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "id": "task-id-3", | ||
| "name": "example-task-3", | ||
| "description": "Example task description 3", | ||
| "executors": [{"image": "executor-image-3"}], | ||
| "inputs": [], | ||
| "outputs": [], | ||
| "creation_time": "2023-07-12T12:00:00Z", | ||
| "logs": [{"end_time": "2023-07-12T12:30:00Z"}] | ||
| } |
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "run_id": "run-id-1", | ||
| "run_log": { | ||
| "name": "example-run-1", | ||
| "start_time": "2023-07-10T14:30:00Z", | ||
| "end_time": "2023-07-10T15:30:00Z" | ||
| }, | ||
| "state": "COMPLETED", | ||
| "outputs": [ | ||
| {"location": "output-location-1", "name": "output-name-1"} | ||
| ] | ||
| } |
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| { | ||
| "@id": "task-id-1", | ||
| "name": "example-task-1", | ||
| "description": "Example task description 1", | ||
| "instrument": "executor-image-1", | ||
| "object": [ | ||
| { | ||
| "@id": "input-url-1", | ||
| "name": "input-path-1" | ||
| }, | ||
| { | ||
| "@id": "input-url-2", | ||
| "name": "input-path-2" | ||
| } | ||
| ], | ||
| "result": [ | ||
| { | ||
| "@id": "output-url-1", | ||
| "name": "output-path-1" | ||
| } | ||
| ], | ||
| "startTime": "2023-07-10T14:30:00Z", | ||
| "endTime": "2023-07-10T15:30:00Z" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "@id": "task-id-3", | ||
| "name": "example-task-3", | ||
| "description": "Example task description 3", | ||
| "instrument": "executor-image-3", | ||
| "object": [], | ||
| "result": [], | ||
| "startTime": "2023-07-12T12:00:00Z", | ||
| "endTime": "2023-07-12T12:30:00Z" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| { | ||
| "@id": "run-id-1", | ||
| "name": "example-run-1", | ||
| "status": "COMPLETED", | ||
| "startTime": "2023-07-10T14:30:00Z", | ||
| "endTime": "2023-07-10T15:30:00Z", | ||
| "result": [ | ||
| { | ||
| "@id": "output-location-1", | ||
| "name": "output-name-1" | ||
| } | ||
| ] | ||
| } |
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can group tests together using comments, that will help improve readability and maintainability further down the line. Also the way you're currently writing data validation tests will make it difficult to test for complex validation issues, implementing a pydantic model will reduce the need for simple validation tests like this, that way you can focus on possible, edge cases and you can create more complex instances of invalid data and test them at the same time.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 Small note: When using |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,122 @@ | ||||||||||||||||||||||
| import unittest | ||||||||||||||||||||||
| from crategen.converters.tes_converter import TESConverter | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| class TestTESConverter(unittest.TestCase): | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def setUp(self): | ||||||||||||||||||||||
| self.converter = TESConverter() | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def test_convert_to_wrroc(self): | ||||||||||||||||||||||
|
||||||||||||||||||||||
| def test_convert_to_wrroc(self): | |
| def test_convert_to_wrroc_invalid_data(self): | |
| invalid_tes_data = { | |
| "id": 123, # id should be a string | |
| "name": None, # name should be a string | |
| } | |
| with self.assertRaises(ValueError): | |
| self.converter.convert_to_wrroc(invalid_tes_data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (testing): Add assertions for specific error messages
It would be helpful to add assertions that check for specific error messages or exceptions when invalid data is passed to the converter. This ensures that the error handling is working as expected.
| def test_convert_from_wrroc(self): | |
| def test_convert_from_wrroc(self): | |
| wrroc_data = { | |
| "@id": "task-id-1", | |
| } | |
| with self.assertRaises(SomeSpecificException) as context: | |
| self.converter.convert_from_wrroc(invalid_data) | |
| self.assertIn('specific error message', str(context.exception)) |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (testing): Test for partially missing fields
Consider adding tests where only some fields are missing, rather than all or none. This will help ensure that the converter can handle partial data loss gracefully.
| def test_convert_to_wrroc_missing_fields(self): | |
| def test_convert_to_wrroc_missing_fields(self): | |
| tes_data = { | |
| "id": "task-id-2", | |
| "name": "example-task" | |
| } | |
| result = self.converter.convert_to_wrroc(tes_data) | |
| self.assertIsNotNone(result) | |
| self.assertIn("id", result) | |
| self.assertNotIn("name", result) |
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can group tests together using comments, that will help improve readability and maintainability further down the line. Also the way you're currently writing data validation tests will make it difficult to test for complex validation issues, implementing a pydantic model will reduce the need for simple validation tests like this, that way you can focus on possible, edge cases and you can create more complex instances of invalid data and test them at the same time. |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,98 @@ | ||||||||||||||||||||||
| import unittest | ||||||||||||||||||||||
| from crategen.converters.wes_converter import WESConverter | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| class TestWESConverter(unittest.TestCase): | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def setUp(self): | ||||||||||||||||||||||
| self.converter = WESConverter() | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def test_convert_to_wrroc(self): | ||||||||||||||||||||||
|
||||||||||||||||||||||
| def test_convert_to_wrroc(self): | |
| def test_convert_to_wrroc_with_nested_structures(self): | |
| tes_data = { | |
| "id": "task-id-1", | |
| "inputs": [{"name": "input1", "description": "desc1", "type": "File"}], | |
| "outputs": [{"name": "output1", "description": "desc1", "type": "File"}], | |
| "resources": {"cpu_cores": 2, "ram_gb": 4, "disk_gb": 10} | |
| } | |
| result = self.converter.convert_to_wrroc(tes_data) | |
| self.assertIsNotNone(result) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (testing): Add tests for invalid nested structures
Consider adding tests that include invalid nested structures or unexpected data types within the nested fields to ensure robust error handling.
| def test_convert_from_wrroc(self): | |
| def test_convert_from_wrroc_invalid_nested_structure(self): | |
| wrroc_data = { | |
| "@id": "task-id-1", | |
| "nested": { | |
| "unexpected_field": "unexpected_value" | |
| } | |
| } | |
| with self.assertRaises(ValueError): | |
| self.converter.convert_from_wrroc(wrroc_data) |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (testing): Test for partially missing fields
Consider adding tests where only some fields are missing, rather than all or none. This will help ensure that the converter can handle partial data loss gracefully.
| def test_convert_to_wrroc_missing_fields(self): | |
| def test_convert_to_wrroc_missing_fields(self): | |
| tes_data = { | |
| "id": "task-id-2", | |
| "name": "example-task" | |
| } | |
| result = self.converter.convert_to_wrroc(tes_data) | |
| self.assertIsNotNone(result) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could easily make this more useful by picking values from a real toy TES run, i.e., put a container image that is actually available, put in a command that actually can be executed in that container, put input files that are permanently available on the web via HTTP(S) (e.g., the raw
README.mdandLICENSEfiles from this repo). Please open another issue for that.It's a bit more tricky for the output, we can think about that in that issue.