Пример #1
0
 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)
Пример #2
0
 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)
Пример #3
0
 def test_Keep_accepts_bsonBinary(self):
     from niprov.pictures import PictureCache
     myImg = Mock()
     myImg.provenance = {'id': '007'}
     pictures = PictureCache(sentinel.dependencies)
     pictures.keep(bson.Binary('/x10/x05/x5f'), for_=myImg)
     self.assertEqual('/x10/x05/x5f', pictures.getBytes(for_=myImg))
Пример #4
0
 def test_For_PictureCache_format_simply_provides_filename(self):
     from niprov.mediumfile import FileMedium
     from niprov.pictures import PictureCache
     medium = FileMedium(self.dependencies)
     fmt = PictureCache(Mock())
     out = medium.export('provstr', fmt)
     self.listener.exportedToFile.assert_called_with('provstr')
     self.assertEqual(out, 'provstr')
Пример #5
0
 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))
Пример #6
0
 def test_Stored_picture_can_be_retrieved_as_bytes(self):
     from niprov.pictures import PictureCache
     myImg = Mock()
     myImg.provenance = {'id': '007'}
     pictures = PictureCache(sentinel.dependencies)
     newPicture = pictures.new()
     newPicture.write('/x10/x05/x5f')
     pictures.keep(newPicture, for_=myImg)
     outBytes = pictures.getBytes(for_=myImg)
     self.assertEqual('/x10/x05/x5f', outBytes)
Пример #7
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')
Пример #8
0
 def create(self, formatName):
     if formatName == 'json':
         return JsonFormat(self.dependencies)
     if formatName == 'xml':
         return XmlFormat(self.dependencies)
     if formatName == 'narrated':
         return NarratedFormat()
     if formatName == 'simple':
         return SimpleFormat()
     if formatName == 'dict':
         return DictFormat()
     if formatName == 'object':
         return ObjectFormat()
     if formatName == 'picture':
         return PictureCache(self.dependencies)
     raise ValueError('Unknown format: ' + str(formatName))
Пример #9
0
 def test_Provides_new_picture_file_handle(self):
     from niprov.pictures import PictureCache
     pictures = PictureCache(sentinel.dependencies)
     newPicture = pictures.new()
     self.assertTrue(hasattr(newPicture, 'write'))