|
1
|
|
|
from mock import Mock, sentinel |
|
2
|
|
|
from tests.ditest import DependencyInjectionTestBase |
|
3
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
class FormatTests(DependencyInjectionTestBase): |
|
6
|
|
|
|
|
7
|
|
|
def test_If_serialize_called_with_list_calls_serializeList(self): |
|
8
|
|
|
from niprov.format import Format |
|
9
|
|
|
exp = Format() |
|
10
|
|
|
exp.serializeList = Mock() |
|
11
|
|
|
out = exp.serialize([sentinel.p1, sentinel.p2]) |
|
12
|
|
|
exp.serializeList.assert_called_with([sentinel.p1, sentinel.p2]) |
|
13
|
|
|
self.assertEqual(out, exp.serializeList()) |
|
14
|
|
|
|
|
15
|
|
|
def test_If_serialize_called_with_item_calls_serializeSingle(self): |
|
16
|
|
|
from niprov.format import Format |
|
17
|
|
|
exp = Format() |
|
18
|
|
|
exp.serializeSingle = Mock() |
|
19
|
|
|
out = exp.serialize(sentinel.p1) |
|
20
|
|
|
exp.serializeSingle.assert_called_with(sentinel.p1) |
|
21
|
|
|
self.assertEqual(out, exp.serializeSingle()) |
|
22
|
|
|
|
|
23
|
|
|
def test_If_called_with_dict_calls_serializeStatistics(self): |
|
24
|
|
|
from niprov.format import Format |
|
25
|
|
|
exp = Format() |
|
26
|
|
|
exp.serializeStatistics = Mock() |
|
27
|
|
|
out = exp.serialize({'a':'b'}) |
|
28
|
|
|
exp.serializeStatistics.assert_called_with({'a':'b'}) |
|
29
|
|
|
self.assertEqual(out, exp.serializeStatistics()) |
|
30
|
|
|
|
|
31
|
|
|
def test_If_created_with_pipeline_calls_serializePipeline(self): |
|
32
|
|
|
from niprov.format import Format |
|
33
|
|
|
from niprov.pipeline import Pipeline |
|
34
|
|
|
exp = Format(dependencies=self.dependencies) |
|
35
|
|
|
exp.serializePipeline = Mock() |
|
36
|
|
|
pipe = Pipeline([]) |
|
37
|
|
|
out = exp.serialize(pipe) |
|
38
|
|
|
#self.pipelineFactory.forFile.assert_called_with(img) |
|
39
|
|
|
exp.serializePipeline.assert_called_with(pipe) |
|
40
|
|
|
self.assertEqual(out, exp.serializePipeline()) |
|
41
|
|
|
|
|
42
|
|
|
def test_If_created_with_iterable_calls_serializeList(self): |
|
43
|
|
|
from niprov.format import Format |
|
44
|
|
|
exp = Format() |
|
45
|
|
|
exp.serializeList = Mock() |
|
46
|
|
|
exp.serializeSingle = Mock() |
|
47
|
|
|
class MockQuery(object): |
|
48
|
|
|
def __iter__(self): |
|
49
|
|
|
pass |
|
50
|
|
|
query = MockQuery() |
|
51
|
|
|
out = exp.serialize(query) |
|
52
|
|
|
exp.serializeList.assert_called_with(query) |
|
53
|
|
|
self.assertEqual(out, exp.serializeList()) |
|
54
|
|
|
|
|
55
|
|
|
|