def test_Stored_picture_can_be_retrieved_as_filepath(self): from niprov.pictures import PictureCache myImg = Mock() myImg.provenance = {'id': '007'} pictures = PictureCache(sentinel.dependencies) self.assertIsNone(pictures.getFilepath(for_=myImg)) pictures.keep(io.BytesIO('/x10/x05/x5f'), for_=myImg) picfpath = os.path.expanduser('~/.niprov-snapshots/007.png') self.assertEqual(picfpath, pictures.getFilepath(for_=myImg))
def test_Stored_picture_can_be_retrieved_as_filepath(self): from niprov.pictures import PictureCache myImg = Mock() myImg.provenance = {'id':'007'} pictures = PictureCache(sentinel.dependencies) self.assertIsNone(pictures.getFilepath(for_=myImg)) pictures.keep(io.BytesIO('/x10/x05/x5f'), for_=myImg) picfpath = os.path.expanduser('~/.niprov-snapshots/007.png') self.assertEqual(picfpath, pictures.getFilepath(for_=myImg))
def test_Serialize(self): from niprov.pictures import PictureCache pictures = PictureCache(sentinel.dependencies) pictures.getFilepath = Mock() fpath = pictures.serializeSingle(sentinel.img) pictures.getFilepath.assert_called_with(for_=sentinel.img) self.assertEqual(pictures.getFilepath(), fpath)
def test_If_pic_is_not_in_cache_but_on_filesystem_provides_that(self): import niprov.pictures myImg = Mock() myImg.provenance = {'id': '007'} pictures = niprov.pictures.PictureCache(sentinel.dependencies) pictures.keep(io.BytesIO('/x10/x05/x5f'), for_=myImg) pictures.saveToDisk(for_=myImg) niprov.pictures._CACHE = {} # reset cache picfpath = os.path.expanduser('~/.niprov-snapshots/007.png') self.assertEqual(picfpath, pictures.getFilepath(for_=myImg))
def test_If_pic_is_not_in_cache_but_on_filesystem_provides_that(self): import niprov.pictures myImg = Mock() myImg.provenance = {'id':'007'} pictures = niprov.pictures.PictureCache(sentinel.dependencies) pictures.keep(io.BytesIO('/x10/x05/x5f'), for_=myImg) pictures.saveToDisk(for_=myImg) niprov.pictures._CACHE = {} # reset cache picfpath = os.path.expanduser('~/.niprov-snapshots/007.png') self.assertEqual(picfpath, pictures.getFilepath(for_=myImg))