def test_tiling(self): a = make_random_data() w, h = 3, 4 s = list(calc_features(a, self.name, w=w, h=h)) self.assertEqual(len(s), 6) r = [to_avro(_) for _ in s] for i in xrange(6): for k in 'img_path', 'series', 'z', 'c', 't': r[i][k] = getattr(self, k) try: [pyavroc_emu.AvroSerializer(Signatures).serialize(_) for _ in r] except AvroException as e: self.fail("Could not serialize record: %s" % e) for i in xrange(6): self.assertEquals(r[i]["version"], s[i].feature_set_version) self.assertEquals(r[i]["name"], self.name) fmap = dict(izip(s[i].feature_names, s[i].values)) for fname, (vname, idx) in FEATURE_NAMES.iteritems(): v = fmap.get(fname) if v is None: self.assertEqual(len(r[i][vname]), 0) else: self.assertEqual(r[i][vname][idx], v) self.assertEqual( (r[0]["x"], r[0]["y"], r[0]["w"], r[0]["h"]), (0, 0, 3, 4)) self.assertEqual( (r[1]["x"], r[1]["y"], r[1]["w"], r[1]["h"]), (3, 0, 3, 4)) self.assertEqual( (r[2]["x"], r[2]["y"], r[2]["w"], r[2]["h"]), (6, 0, 2, 4)) self.assertEqual( (r[3]["x"], r[3]["y"], r[3]["w"], r[3]["h"]), (0, 4, 3, 2)) self.assertEqual( (r[4]["x"], r[4]["y"], r[4]["w"], r[4]["h"]), (3, 4, 3, 2)) self.assertEqual( (r[5]["x"], r[5]["y"], r[5]["w"], r[5]["h"]), (6, 4, 2, 2))
def runTest(self): for name, record in self.record_map.iteritems(): schema_str = getattr(schema, name) serializer = pyavroc_emu.AvroSerializer(schema_str) rec_bytes = serializer.serialize(record) deserializer = pyavroc_emu.AvroDeserializer(schema_str) self.assertEqual(deserializer.deserialize(rec_bytes), record)
def test_no_tiling(self): a = make_random_data() for long in False, True: all_sigs = list(calc_features(a, self.name, long=long)) self.assertEqual(len(all_sigs), 1) sigs = all_sigs[0] rec = to_avro(sigs) for k in 'img_path', 'series', 'z', 'c', 't': rec[k] = getattr(self, k) try: pyavroc_emu.AvroSerializer(Signatures).serialize(rec) except AvroException as e: self.fail("Could not serialize record: %s" % e) self.assertEquals(rec["version"], sigs.feature_set_version) self.assertEquals(rec["name"], self.name) self.assertEquals((rec["x"], rec["y"]), (0, 0)) self.assertEquals((rec["h"], rec["w"]), a.shape) fmap = dict(izip(sigs.feature_names, sigs.values)) for fname, (vname, idx) in FEATURE_NAMES.iteritems(): v = fmap.get(fname) if v is None: assert not long self.assertEqual(len(rec[vname]), 0) else: self.assertEqual(rec[vname][idx], v)