-
Notifications
You must be signed in to change notification settings - Fork 92
PLAT-159: Migrate test_jobs #1131
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
0a498a6
cp to tests
ethho e2acbea
Migrate test_fetch_same
ethho 74402eb
cp to tests
ethho 66cd1c1
nose2pytest test_jobs
ethho b2c1f0e
All but two test_jobs passing
ethho 4fa05a2
Clean jobs table in fixture
ethho c7a3036
Change from generator to list
ethho dfdb805
Tolerate error when cleaning up schema_any.jobs
ethho a4ea5ff
Format with black
ethho 6906193
Remove unnecessary fixture usage
ethho 4026a56
Fix typo
ethho 52e78bb
test_long_error_stack requires subjects fixture
ethho d5445bf
Merge remote-tracking branch 'upstream/dev-tests' into dev-tests-plat…
ethho 42c50f3
Merge remote-tracking branch 'upstream/dev-tests' into dev-tests-plat…
ethho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import pytest | ||
| from . import PREFIX, CONN_INFO | ||
| import numpy as np | ||
| import datajoint as dj | ||
|
|
||
|
|
||
| class ProjData(dj.Manual): | ||
| definition = """ | ||
| id : int | ||
| --- | ||
| resp : float | ||
| sim : float | ||
| big : longblob | ||
| blah : varchar(10) | ||
| """ | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def schema_fetch_same(connection_root): | ||
| schema = dj.Schema( | ||
| PREFIX + "_fetch_same", | ||
| context=dict(ProjData=ProjData), | ||
| connection=connection_root, | ||
| ) | ||
| schema(ProjData) | ||
| ProjData().insert( | ||
| [ | ||
| {"id": 0, "resp": 20.33, "sim": 45.324, "big": 3, "blah": "yes"}, | ||
| { | ||
| "id": 1, | ||
| "resp": 94.3, | ||
| "sim": 34.23, | ||
| "big": {"key1": np.random.randn(20, 10)}, | ||
| "blah": "si", | ||
| }, | ||
| { | ||
| "id": 2, | ||
| "resp": 1.90, | ||
| "sim": 10.23, | ||
| "big": np.random.randn(4, 2), | ||
| "blah": "sim", | ||
| }, | ||
| ] | ||
| ) | ||
| yield schema | ||
| schema.drop() | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def projdata(): | ||
| yield ProjData() | ||
|
|
||
|
|
||
| class TestFetchSame: | ||
| def test_object_conversion_one(self, schema_fetch_same, projdata): | ||
| new = projdata.proj(sub="resp").fetch("sub") | ||
| assert new.dtype == np.float64 | ||
|
|
||
| def test_object_conversion_two(self, schema_fetch_same, projdata): | ||
| [sub, add] = projdata.proj(sub="resp", add="sim").fetch("sub", "add") | ||
| assert sub.dtype == np.float64 | ||
| assert add.dtype == np.float64 | ||
|
|
||
| def test_object_conversion_all(self, schema_fetch_same, projdata): | ||
| new = projdata.proj(sub="resp", add="sim").fetch() | ||
| assert new["sub"].dtype == np.float64 | ||
| assert new["add"].dtype == np.float64 | ||
|
|
||
| def test_object_no_convert(self, schema_fetch_same, projdata): | ||
| new = projdata.fetch() | ||
| assert new["big"].dtype == "object" | ||
| assert new["blah"].dtype == "object" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| import pytest | ||
| from . import schema | ||
| from datajoint.jobs import ERROR_MESSAGE_LENGTH, TRUNCATION_APPENDIX | ||
| import random | ||
| import string | ||
| import datajoint as dj | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def subjects(): | ||
| yield schema.Subject() | ||
|
|
||
|
|
||
| def test_reserve_job(schema_any, subjects): | ||
| assert subjects | ||
| table_name = "fake_table" | ||
|
|
||
| # reserve jobs | ||
| for key in subjects.fetch("KEY"): | ||
| assert schema_any.jobs.reserve(table_name, key), "failed to reserve a job" | ||
|
|
||
| # refuse jobs | ||
| for key in subjects.fetch("KEY"): | ||
| assert not schema_any.jobs.reserve( | ||
| table_name, key | ||
| ), "failed to respect reservation" | ||
|
|
||
| # complete jobs | ||
| for key in subjects.fetch("KEY"): | ||
| schema_any.jobs.complete(table_name, key) | ||
| assert not schema_any.jobs, "failed to free jobs" | ||
|
|
||
| # reserve jobs again | ||
| for key in subjects.fetch("KEY"): | ||
| assert schema_any.jobs.reserve(table_name, key), "failed to reserve new jobs" | ||
|
|
||
| # finish with error | ||
| for key in subjects.fetch("KEY"): | ||
| schema_any.jobs.error(table_name, key, "error message") | ||
|
|
||
| # refuse jobs with errors | ||
| for key in subjects.fetch("KEY"): | ||
| assert not schema_any.jobs.reserve( | ||
| table_name, key | ||
| ), "failed to ignore error jobs" | ||
|
|
||
| # clear error jobs | ||
| (schema_any.jobs & dict(status="error")).delete() | ||
| assert not schema_any.jobs, "failed to clear error jobs" | ||
|
|
||
|
|
||
| def test_restrictions(schema_any): | ||
| jobs = schema_any.jobs | ||
| jobs.delete() | ||
| jobs.reserve("a", {"key": "a1"}) | ||
| jobs.reserve("a", {"key": "a2"}) | ||
| jobs.reserve("b", {"key": "b1"}) | ||
| jobs.error("a", {"key": "a2"}, "error") | ||
| jobs.error("b", {"key": "b1"}, "error") | ||
|
|
||
| assert len(jobs & {"table_name": "a"}) == 2 | ||
| assert len(jobs & {"status": "error"}) == 2 | ||
| assert len(jobs & {"table_name": "a", "status": "error"}) == 1 | ||
| jobs.delete() | ||
|
|
||
|
|
||
| def test_sigint(schema_any): | ||
| try: | ||
| schema.SigIntTable().populate(reserve_jobs=True) | ||
| except KeyboardInterrupt: | ||
| pass | ||
|
|
||
| assert len(schema_any.jobs.fetch()), "SigInt jobs table is empty" | ||
| status, error_message = schema_any.jobs.fetch1("status", "error_message") | ||
| assert status == "error" | ||
| assert error_message == "KeyboardInterrupt" | ||
|
|
||
|
|
||
| def test_sigterm(schema_any): | ||
| try: | ||
| schema.SigTermTable().populate(reserve_jobs=True) | ||
| except SystemExit: | ||
| pass | ||
|
|
||
| assert len(schema_any.jobs.fetch()), "SigTerm jobs table is empty" | ||
| status, error_message = schema_any.jobs.fetch1("status", "error_message") | ||
| assert status == "error" | ||
| assert error_message == "SystemExit: SIGTERM received" | ||
|
|
||
|
|
||
| def test_suppress_dj_errors(schema_any): | ||
| """test_suppress_dj_errors: dj errors suppressible w/o native py blobs""" | ||
| with dj.config(enable_python_native_blobs=False): | ||
| schema.ErrorClass.populate(reserve_jobs=True, suppress_errors=True) | ||
| assert len(schema.DjExceptionName()) == len(schema_any.jobs) > 0 | ||
|
|
||
|
|
||
| def test_long_error_message(schema_any, subjects): | ||
| # create long error message | ||
| long_error_message = "".join( | ||
| random.choice(string.ascii_letters) for _ in range(ERROR_MESSAGE_LENGTH + 100) | ||
| ) | ||
| short_error_message = "".join( | ||
| random.choice(string.ascii_letters) for _ in range(ERROR_MESSAGE_LENGTH // 2) | ||
| ) | ||
| assert subjects | ||
| table_name = "fake_table" | ||
|
|
||
| key = subjects.fetch("KEY")[0] | ||
|
|
||
| # test long error message | ||
| schema_any.jobs.reserve(table_name, key) | ||
| schema_any.jobs.error(table_name, key, long_error_message) | ||
| error_message = schema_any.jobs.fetch1("error_message") | ||
| assert ( | ||
| len(error_message) == ERROR_MESSAGE_LENGTH | ||
| ), "error message is longer than max allowed" | ||
| assert error_message.endswith( | ||
| TRUNCATION_APPENDIX | ||
| ), "appropriate ending missing for truncated error message" | ||
| schema_any.jobs.delete() | ||
|
|
||
| # test long error message | ||
| schema_any.jobs.reserve(table_name, key) | ||
| schema_any.jobs.error(table_name, key, short_error_message) | ||
| error_message = schema_any.jobs.fetch1("error_message") | ||
| assert error_message == short_error_message, "error messages do not agree" | ||
| assert not error_message.endswith( | ||
| TRUNCATION_APPENDIX | ||
| ), "error message should not be truncated" | ||
| schema_any.jobs.delete() | ||
|
|
||
|
|
||
| def test_long_error_stack(schema_any, subjects): | ||
| # create long error stack | ||
| STACK_SIZE = ( | ||
| 89942 # Does not fit into small blob (should be 64k, but found to be higher) | ||
| ) | ||
| long_error_stack = "".join( | ||
| random.choice(string.ascii_letters) for _ in range(STACK_SIZE) | ||
| ) | ||
| assert subjects | ||
| table_name = "fake_table" | ||
|
|
||
| key = subjects.fetch("KEY")[0] | ||
|
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. you can limit in these cases for better performance: |
||
|
|
||
| # test long error stack | ||
| schema_any.jobs.reserve(table_name, key) | ||
| schema_any.jobs.error(table_name, key, "error message", long_error_stack) | ||
| error_stack = schema_any.jobs.fetch1("error_stack") | ||
| assert error_stack == long_error_stack, "error stacks do not agree" | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
Similar to #1129 (comment), this generator was exhausted by one test, causing failures for additional tests that required non-empty
SimpleSource.contents.