|
1
|
|
|
#!/usr/bin/python |
|
2
|
|
|
# -*- coding: UTF-8 -*- |
|
3
|
|
|
from mock import Mock, sentinel, patch |
|
4
|
|
|
from tests.ditest import DependencyInjectionTestBase |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
class FileMediumTests(DependencyInjectionTestBase): |
|
8
|
|
|
|
|
9
|
|
|
def test_Writes_formattedProvenance_to_file(self): |
|
10
|
|
|
from niprov.mediumfile import FileMedium |
|
11
|
|
|
medium = FileMedium(self.dependencies) |
|
12
|
|
|
out = medium.export('Once upon a time..', self.format) |
|
13
|
|
|
self.assertEqual('Once upon a time..', |
|
14
|
|
|
self.filesys.write.call_args[0][1]) |
|
15
|
|
|
|
|
16
|
|
|
def test_Comes_up_with_filename(self): |
|
17
|
|
|
from niprov.mediumfile import FileMedium |
|
18
|
|
|
self.clock.getNowString.return_value = 'hammertime' |
|
19
|
|
|
medium = FileMedium(self.dependencies) |
|
20
|
|
|
out = medium.export('provstr', self.format) |
|
21
|
|
|
self.filesys.write.assert_called_with('provenance_hammertime.txt', |
|
22
|
|
|
'provstr') |
|
23
|
|
|
|
|
24
|
|
|
def test_Returns_filename(self): |
|
25
|
|
|
from niprov.mediumfile import FileMedium |
|
26
|
|
|
self.clock.getNowString.return_value = 'hammertime' |
|
27
|
|
|
medium = FileMedium(self.dependencies) |
|
28
|
|
|
out = medium.export('provstr', self.format) |
|
29
|
|
|
self.assertEqual('provenance_hammertime.txt', out) |
|
30
|
|
|
|
|
31
|
|
|
def test_Reports_filename_to_listener(self): |
|
32
|
|
|
from niprov.mediumfile import FileMedium |
|
33
|
|
|
self.clock.getNowString.return_value = 'hammertime' |
|
34
|
|
|
medium = FileMedium(self.dependencies) |
|
35
|
|
|
out = medium.export('provstr', self.format) |
|
36
|
|
|
self.listener.exportedToFile.assert_called_with( |
|
37
|
|
|
'provenance_hammertime.txt') |
|
38
|
|
|
|
|
39
|
|
|
def test_Specific_extension_for_format(self): |
|
40
|
|
|
from niprov.mediumfile import FileMedium |
|
41
|
|
|
self.clock.getNowString.return_value = 'hammertime' |
|
42
|
|
|
medium = FileMedium(self.dependencies) |
|
43
|
|
|
fmt = Mock() |
|
44
|
|
|
fmt.fileExtension = 'prv' |
|
45
|
|
|
out = medium.export('provstr', fmt) |
|
46
|
|
|
self.listener.exportedToFile.assert_called_with( |
|
47
|
|
|
'provenance_hammertime.prv') |
|
48
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
def test_For_PictureCache_format_simply_provides_filename(self): |
|
51
|
|
|
from niprov.mediumfile import FileMedium |
|
52
|
|
|
from niprov.pictures import PictureCache |
|
53
|
|
|
medium = FileMedium(self.dependencies) |
|
54
|
|
|
fmt = PictureCache(Mock()) |
|
55
|
|
|
out = medium.export('provstr', fmt) |
|
56
|
|
|
self.listener.exportedToFile.assert_called_with('provstr') |
|
57
|
|
|
self.assertEqual(out, 'provstr') |
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
|