-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtest_proofreading_schema.py
98 lines (75 loc) · 2.36 KB
/
test_proofreading_schema.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import pytest
from emannotationschemas.schemas.proofreading import (
CompartmentProofreadStatus,
ProofreadStatus,
ProofreadingBoolStatusUser,
)
from marshmallow import ValidationError
good_base_data = {
"pt": {"position": [1, 2, 3]},
"valid_id": 1234567,
"status": "clean",
}
bad_base_data = {
"pt": {"position": [1, 2, 3]},
"valid_id": 1234567,
"status": "some_nonsense",
}
good_comp_data = {
"pt": {"position": [1, 2, 3]},
"valid_id": 1234567,
"status_axon": "clean",
"status_dendrite": "extended",
}
bad_comp_data = {
"pt": {"position": [1, 2, 3]},
"valid_id": 1234567,
"status_dendrite": "clean",
}
good_booluser_data = {
"pt": {"position": [1, 2, 3]},
"valid_id": 1234567,
"proofread": True,
"user_id": 42,
}
bad_booluser_data_1 = {
"pt": {"position": [1, 2, 3]},
"valid_id": 1234567,
"user_id": 42,
}
bad_booluser_data_2 = {
"pt": {"position": [1, 2, 3]},
"valid_id": 1234567,
"proofread": True,
}
def annotation_import(item):
item["supervoxel_id"] = None
item.pop("rootId", None)
def test_proofreading_validation():
schema = ProofreadStatus(context={"bsp_fn": annotation_import})
result = schema.load(good_base_data)
assert result["status"] == "clean"
with pytest.raises(ValidationError):
schema.load(bad_base_data)
def test_compartment_proofreading_validation():
schema = CompartmentProofreadStatus(context={"bsp_fn": annotation_import})
result = schema.load(good_comp_data)
assert result["status_dendrite"] == "extended"
with pytest.raises(ValidationError):
schema.load(bad_comp_data)
def test_bool_proofreading_user_validation_1():
schema = ProofreadingBoolStatusUser(context={"bsp_fn": annotation_import})
result = schema.load(good_booluser_data)
assert result["proofread"]
with pytest.raises(ValidationError):
schema.load(bad_booluser_data_1)
with pytest.raises(ValidationError):
schema.load(bad_booluser_data_2)
def test_bool_proofreading_user_validation_2():
schema = ProofreadingBoolStatusUser(context={"bsp_fn": annotation_import})
result = schema.load(good_booluser_data)
assert result["user_id"] == 42
with pytest.raises(ValidationError):
schema.load(bad_booluser_data_1)
with pytest.raises(ValidationError):
schema.load(bad_booluser_data_2)