-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #179 from dylanmcreynolds/projections
Add projections schema to start doc
- Loading branch information
Showing
3 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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,62 @@ | ||
import event_model | ||
import pytest | ||
from jsonschema.exceptions import ValidationError | ||
|
||
|
||
def test_projection_start_doc(): | ||
run_bundle = event_model.compose_run(uid="42", metadata={"projections": valid_projections}) | ||
start_doc = run_bundle.start_doc | ||
assert start_doc['projections'] == valid_projections | ||
|
||
|
||
def test_projection_schema(): | ||
start_doc['projections'] = valid_projections | ||
event_model.schema_validators[event_model.DocumentNames.start].validate(start_doc) | ||
|
||
with pytest.raises(ValidationError): | ||
start_doc['projections'] = invalid_projections | ||
event_model.schema_validators[event_model.DocumentNames.start].validate(start_doc) | ||
|
||
|
||
valid_projections = [ | ||
{ | ||
"name": "test", | ||
"version": "42.0.0", | ||
"configuration": {}, | ||
"projection": { | ||
'entry/instrument/detector/data': { | ||
'type': 'linked', | ||
'location': 'event', | ||
'stream': 'primary', | ||
'field': 'ccd', | ||
}, | ||
'/entry/instrument/wavelength': { | ||
'type': 'calculated', | ||
'calculation': { | ||
'callable': 'pizza.order:slice', | ||
'kwargs': {'toppings': 'cheese'} | ||
} | ||
} | ||
}, | ||
} | ||
] | ||
|
||
invalid_projections = [ | ||
{ | ||
"name": "test", | ||
"version": "42.0.0", | ||
"configuration": {}, | ||
"projection": { | ||
'entry/instrument/detector/data': { | ||
'location': 'THIS IS NOT VALID', | ||
'stream': 'primary', | ||
'field': 'ccd', | ||
}, | ||
}, | ||
} | ||
] | ||
|
||
start_doc = { | ||
"uid": "abc", | ||
"time": 0, | ||
} |