Esempio n. 1
0
 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))
Esempio n. 2
0
 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))
Esempio n. 3
0
 def test_Can_be_told_to_persist_picture_to_disk_now(self):
     from niprov.pictures import PictureCache
     myImg = Mock()
     myImg.provenance = {'id': '007'}
     pictures = PictureCache(sentinel.dependencies)
     pictures.saveToDisk(for_=myImg)  #shouldn't do anything
     pictures.keep(io.BytesIO('/x10/x05/x5f'), for_=myImg)
     pictures.saveToDisk(for_=myImg)
     picfpath = os.path.expanduser('~/.niprov-snapshots/007.png')
     self.assertTrue(os.path.isfile(picfpath))
     with open(picfpath) as picFile:
         self.assertEqual(picFile.read(), '/x10/x05/x5f')
Esempio n. 4
0
 def test_Can_be_told_to_persist_picture_to_disk_now(self):
     from niprov.pictures import PictureCache
     myImg = Mock()
     myImg.provenance = {'id':'007'}
     pictures = PictureCache(sentinel.dependencies)
     pictures.saveToDisk(for_=myImg) #shouldn't do anything
     pictures.keep(io.BytesIO('/x10/x05/x5f'), for_=myImg)
     pictures.saveToDisk(for_=myImg)
     picfpath = os.path.expanduser('~/.niprov-snapshots/007.png')
     self.assertTrue(os.path.isfile(picfpath))
     with open(picfpath) as picFile:
         self.assertEqual(picFile.read(), '/x10/x05/x5f')