@@ 50-61 (lines=12) @@ | ||
47 | outBytes = pictures.getBytes(for_=myImg) |
|
48 | self.assertEqual('/x10/x05/x5f', outBytes) |
|
49 | ||
50 | def test_Can_be_told_to_persist_picture_to_disk_now(self): |
|
51 | from niprov.pictures import PictureCache |
|
52 | myImg = Mock() |
|
53 | myImg.provenance = {'id':'007'} |
|
54 | pictures = PictureCache(sentinel.dependencies) |
|
55 | pictures.saveToDisk(for_=myImg) #shouldn't do anything |
|
56 | pictures.keep(io.BytesIO('/x10/x05/x5f'), for_=myImg) |
|
57 | pictures.saveToDisk(for_=myImg) |
|
58 | picfpath = os.path.expanduser('~/.niprov-snapshots/007.png') |
|
59 | self.assertTrue(os.path.isfile(picfpath)) |
|
60 | with open(picfpath) as picFile: |
|
61 | self.assertEqual(picFile.read(), '/x10/x05/x5f') |
|
62 | ||
63 | def test_If_pic_is_not_in_cache_but_on_filesystem_provides_that(self): |
|
64 | import niprov.pictures |
|
@@ 63-72 (lines=10) @@ | ||
60 | with open(picfpath) as picFile: |
|
61 | self.assertEqual(picFile.read(), '/x10/x05/x5f') |
|
62 | ||
63 | def test_If_pic_is_not_in_cache_but_on_filesystem_provides_that(self): |
|
64 | import niprov.pictures |
|
65 | myImg = Mock() |
|
66 | myImg.provenance = {'id':'007'} |
|
67 | pictures = niprov.pictures.PictureCache(sentinel.dependencies) |
|
68 | pictures.keep(io.BytesIO('/x10/x05/x5f'), for_=myImg) |
|
69 | pictures.saveToDisk(for_=myImg) |
|
70 | niprov.pictures._CACHE = {} # reset cache |
|
71 | picfpath = os.path.expanduser('~/.niprov-snapshots/007.png') |
|
72 | self.assertEqual(picfpath, pictures.getFilepath(for_=myImg)) |
|
73 | ||
74 | def test_Keep_accepts_bsonBinary(self): |
|
75 | from niprov.pictures import PictureCache |
|
@@ 29-37 (lines=9) @@ | ||
26 | newPicture = pictures.new() |
|
27 | self.assertTrue(hasattr(newPicture, 'write')) |
|
28 | ||
29 | def test_Stored_picture_can_be_retrieved_as_filepath(self): |
|
30 | from niprov.pictures import PictureCache |
|
31 | myImg = Mock() |
|
32 | myImg.provenance = {'id':'007'} |
|
33 | pictures = PictureCache(sentinel.dependencies) |
|
34 | self.assertIsNone(pictures.getFilepath(for_=myImg)) |
|
35 | pictures.keep(io.BytesIO('/x10/x05/x5f'), for_=myImg) |
|
36 | picfpath = os.path.expanduser('~/.niprov-snapshots/007.png') |
|
37 | self.assertEqual(picfpath, pictures.getFilepath(for_=myImg)) |
|
38 | ||
39 | def test_Stored_picture_can_be_retrieved_as_bytes(self): |
|
40 | from niprov.pictures import PictureCache |