def test_verify_compress(self): data = dict() data['compress'] = '' ply2.verify(data) data['compress'] = None ply2.verify(data) data['compress'] = 'gzip' ply2.verify(data) data['compress'] = 'bzip2' ply2.verify(data) data['compress'] = 'elephant' with self.assertRaises(ValueError): ply2.verify(data)
def test_verify_keys(self): data = dict() ply2.verify(data) data['format'] = 'ascii' ply2.verify(data) data['meta'] = dict() ply2.verify(data) data['penguin'] = 'flying' with self.assertRaises(KeyError): ply2.verify(data)
def test_verify_type(self): data = dict() data['type'] = 'image' with self.assertRaises(TypeError): ply2.verify(data) data['type'] = [] ply2.verify(data) data['type'].append('image') ply2.verify(data) data['type'].append('cabbage\n') with self.assertRaises(ValueError): ply2.verify(data) data['type'] = ['Its dead jim'] with self.assertRaises(ValueError): ply2.verify(data)
def test_verify_format(self): data = dict() data['format'] = 'ascii' ply2.verify(data) data['format'] = 'binary_little_endian' ply2.verify(data) data['format'] = 'carrier pigeon' with self.assertRaises(ValueError): ply2.verify(data)
def test_create(self): for binary in [False, True]: for compress in [0, 1, 2]: data = ply2.create(binary, compress) ply2.verify(data)
def test_verify_element_advanced(self): data = dict() data['element'] = dict() data['element']['people'] = dict() data['element']['people']['name'] = numpy.zeros(3, dtype=numpy.object) with self.assertRaises(AttributeError): ply2.verify(data) data['element']['people']['name'][0] = 'The Joker' data['element']['people']['name'][1] = 6 data['element']['people']['name'][2] = u'Poison Ivy' with self.assertRaises(TypeError): ply2.verify(data) data['element']['people']['name'][1] = 'Bane' ply2.verify(data) data['element']['people']['image'] = numpy.zeros(3, dtype=numpy.object) data['element']['people']['image'][0] = numpy.random.rand( 96, 64).astype(numpy.float32) data['element']['people']['image'][1] = numpy.random.rand( 96, 64).astype(numpy.float32) data['element']['people']['image'][2] = numpy.random.rand( 96, 64).astype(numpy.float32) ply2.verify(data) data['element']['people']['image'][1] = numpy.random.rand( 64, 64).astype(numpy.float32) ply2.verify(data) data['element']['people']['image'][1] = numpy.random.rand(12).astype( numpy.float32) with self.assertRaises(TypeError): ply2.verify(data) data['element']['people']['image'][1] = numpy.random.rand( 48, 32).astype(numpy.float64) with self.assertRaises(TypeError): ply2.verify(data) data['element']['people']['image'][1] = 'Insert image here' with self.assertRaises(AttributeError): ply2.verify(data)
def test_verify_element(self): data = dict() data['element'] = dict() data['element']['pixel'] = dict() ply2.verify(data) data['element']['pixel']['red'] = numpy.zeros((8, 8), dtype=numpy.uint8) ply2.verify(data) data['element']['pixel']['green'] = 'green' with self.assertRaises(TypeError): ply2.verify(data) data['element']['pixel']['green'] = numpy.zeros((8, 8), dtype=numpy.complex) with self.assertRaises(TypeError): ply2.verify(data) data['element']['pixel']['green'] = numpy.zeros((4, 8), dtype=numpy.uint8) with self.assertRaises(RuntimeError): ply2.verify(data) data['element']['pixel']['green'] = numpy.zeros((8, 8), dtype=numpy.uint8) ply2.verify(data) data['element'][None] = dict() with self.assertRaises(TypeError): ply2.verify(data) del data['element'][None] data['element']['pet alien'] = dict() with self.assertRaises(KeyError): ply2.verify(data) del data['element']['pet alien'] data['element']['pixel']['burnt amber'] = numpy.ones((8, 8), dtype=numpy.uint8) with self.assertRaises(KeyError): ply2.verify(data) del data['element']['pixel']['burnt amber'] data['element']['pixel']['ochre\n'] = numpy.ones((8, 8), dtype=numpy.uint8) with self.assertRaises(KeyError): ply2.verify(data) del data['element']['pixel']['ochre\n'] data['element']['pixel']['depth'] = numpy.ones((8, 8), dtype=numpy.float32) data['element']['pixel']['index'] = numpy.ones((8, 8), dtype=numpy.int32) ply2.verify(data)
def test_verify_meta(self): data = dict() data['meta'] = dict() data['meta']['author'] = 'Cthulhu' ply2.verify(data) data['meta']['scaryness'] = 5 ply2.verify(data) data['meta']['age'] = 4.561e67 ply2.verify(data) data['meta'][42] = 42 with self.assertRaises(TypeError): ply2.verify(data) del data['meta'][42] data['meta']['dance moves'] = 3 with self.assertRaises(KeyError): ply2.verify(data) del data['meta']['dance moves'] data['meta']['awesomness_distribution'] = (5.3, 6.2) with self.assertRaises(TypeError): ply2.verify(data) del data['meta']['awesomness_distribution'] ply2.verify(data) # Just to make sure that none of the above are passing because an earlier failure wasn't succesfully removed.
def test_verify_element_advanced(self): data = dict() data['element'] = dict() data['element']['people'] = dict() data['element']['people']['name'] = numpy.zeros(3, dtype=numpy.object) with self.assertRaises(AttributeError): ply2.verify(data) data['element']['people']['name'][0] = 'The Joker' data['element']['people']['name'][1] = 6 data['element']['people']['name'][2] = u'Poison Ivy' with self.assertRaises(TypeError): ply2.verify(data) data['element']['people']['name'][1] = 'Bane' ply2.verify(data) data['element']['people']['image'] = numpy.zeros(3, dtype=numpy.object) data['element']['people']['image'][0] = numpy.random.rand(96, 64).astype(numpy.float32) data['element']['people']['image'][1] = numpy.random.rand(96, 64).astype(numpy.float32) data['element']['people']['image'][2] = numpy.random.rand(96, 64).astype(numpy.float32) ply2.verify(data) data['element']['people']['image'][1] = numpy.random.rand(64, 64).astype(numpy.float32) ply2.verify(data) data['element']['people']['image'][1] = numpy.random.rand(12).astype(numpy.float32) with self.assertRaises(TypeError): ply2.verify(data) data['element']['people']['image'][1] = numpy.random.rand(48, 32).astype(numpy.float64) with self.assertRaises(TypeError): ply2.verify(data) data['element']['people']['image'][1] = 'Insert image here' with self.assertRaises(AttributeError): ply2.verify(data)
def test_verify_comment(self): data = dict() data['comment'] = 'I am a cabbage' with self.assertRaises(TypeError): ply2.verify(data) data['comment'] = dict() ply2.verify(data) data['comment'][0] = 'Bring out yer dead!' ply2.verify(data) data['comment'][2] = 'Bring out yer dead!' with self.assertRaises(KeyError): ply2.verify(data) data['comment'][1] = 'Bring out yer dead!' ply2.verify(data) data['comment'][3] = 'Bring out yer dead!\n' with self.assertRaises(ValueError): ply2.verify(data)
def test_verify_meta(self): data = dict() data['meta'] = dict() data['meta']['author'] = 'Cthulhu' ply2.verify(data) data['meta']['scaryness'] = 5 ply2.verify(data) data['meta']['age'] = 4.561e67 ply2.verify(data) data['meta'][42] = 42 with self.assertRaises(TypeError): ply2.verify(data) del data['meta'][42] data['meta']['dance moves'] = 3 with self.assertRaises(KeyError): ply2.verify(data) del data['meta']['dance moves'] data['meta']['awesomness_distribution'] = (5.3, 6.2) with self.assertRaises(TypeError): ply2.verify(data) del data['meta']['awesomness_distribution'] ply2.verify( data ) # Just to make sure that none of the above are passing because an earlier failure wasn't succesfully removed.