|
1
|
|
|
from mock import Mock, patch, call |
|
2
|
|
|
from tests.ditest import DependencyInjectionTestBase |
|
3
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
class FormatFactoryTests(DependencyInjectionTestBase): |
|
6
|
|
|
|
|
7
|
|
|
def setUp(self): |
|
8
|
|
|
super(FormatFactoryTests, self).setUp() |
|
9
|
|
|
|
|
10
|
|
|
def test_Provides_json(self): |
|
11
|
|
|
from niprov.formatfactory import FormatFactory |
|
12
|
|
|
from niprov.formatjson import JsonFormat |
|
13
|
|
|
factory = FormatFactory() |
|
14
|
|
|
self.assertIsInstance(factory.create('json'), JsonFormat) |
|
15
|
|
|
|
|
16
|
|
|
def test_Provides_xml(self): |
|
17
|
|
|
from niprov.formatfactory import FormatFactory |
|
18
|
|
|
from niprov.formatxml import XmlFormat |
|
19
|
|
|
factory = FormatFactory() |
|
20
|
|
|
self.assertIsInstance(factory.create('xml'), XmlFormat) |
|
21
|
|
|
|
|
22
|
|
|
def test_Provides_narrated(self): |
|
23
|
|
|
from niprov.formatfactory import FormatFactory |
|
24
|
|
|
from niprov.formatnarrated import NarratedFormat |
|
25
|
|
|
factory = FormatFactory() |
|
26
|
|
|
self.assertIsInstance(factory.create('narrated'), NarratedFormat) |
|
27
|
|
|
|
|
28
|
|
|
def test_Provides_simple(self): |
|
29
|
|
|
from niprov.formatfactory import FormatFactory |
|
30
|
|
|
from niprov.formatsimple import SimpleFormat |
|
31
|
|
|
factory = FormatFactory() |
|
32
|
|
|
self.assertIsInstance(factory.create('simple'), SimpleFormat) |
|
33
|
|
|
|
|
34
|
|
|
def test_Provides_dict(self): |
|
35
|
|
|
from niprov.formatfactory import FormatFactory |
|
36
|
|
|
from niprov.formatdict import DictFormat |
|
37
|
|
|
factory = FormatFactory() |
|
38
|
|
|
self.assertIsInstance(factory.create('dict'), DictFormat) |
|
39
|
|
|
|
|
40
|
|
|
def test_Provides_object(self): |
|
41
|
|
|
from niprov.formatfactory import FormatFactory |
|
42
|
|
|
from niprov.formatobject import ObjectFormat |
|
43
|
|
|
factory = FormatFactory() |
|
44
|
|
|
self.assertIsInstance(factory.create('object'), ObjectFormat) |
|
45
|
|
|
|
|
46
|
|
|
def test_Provides_picture(self): |
|
47
|
|
|
from niprov.formatfactory import FormatFactory |
|
48
|
|
|
from niprov.pictures import PictureCache |
|
49
|
|
|
factory = FormatFactory() |
|
50
|
|
|
self.assertIsInstance(factory.create('picture'), PictureCache) |
|
51
|
|
|
|
|
52
|
|
|
def test_Raises_exception_on_unknown_name(self): |
|
53
|
|
|
from niprov.formatfactory import FormatFactory |
|
54
|
|
|
factory = FormatFactory() |
|
55
|
|
|
with self.assertRaisesRegexp(ValueError, 'Unknown format: hexameter'): |
|
56
|
|
|
factory.create('hexameter') |
|
57
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
|