def test_write(self): """Parse, rewrite and retest an example file.""" infile = open(filename, 'rb') t1 = next(CDAOIO.Parser(infile).parse()) infile.close() outfile = open(DUMMY, 'w+b') CDAOIO.write([t1], outfile) outfile.close() t2 = next(CDAOIO.Parser(open(DUMMY, 'rb')).parse()) def assert_property(prop_name): p1 = sorted([getattr(n, prop_name) for n in t1.get_terminals()]) p2 = sorted([getattr(n, prop_name) for n in t2.get_terminals()]) self.assertEqual(p1, p2) for prop_name in ('name', 'branch_length', 'confidence'): assert_property(prop_name)
def test_write(self): """Parse, rewrite and retest an example file.""" infile = open(filename, "rb") t1 = CDAOIO.Parser(infile).parse().next() infile.close() outfile = open(DUMMY, "w+b") CDAOIO.write([t1], outfile) outfile.close() t2 = CDAOIO.Parser(open(DUMMY, "rb")).parse().next() def assert_property(prop_name): p1 = sorted([getattr(n, prop_name) for n in t1.get_terminals()]) p2 = sorted([getattr(n, prop_name) for n in t2.get_terminals()]) self.assertEqual(p1, p2) for prop_name in ("name", "branch_length", "confidence"): assert_property(prop_name)
def test_write(self): """Parse, rewrite and retest an example file.""" with open(filename) as infile: t1 = next(CDAOIO.Parser(infile).parse()) with open(DUMMY, 'w') as outfile: CDAOIO.write([t1], outfile) with open(DUMMY) as infile: t2 = next(CDAOIO.Parser(infile).parse()) for prop_name in ('name', 'branch_length', 'confidence'): p1 = [getattr(n, prop_name) for n in t1.get_terminals()] p2 = [getattr(n, prop_name) for n in t2.get_terminals()] if p1 == p2: pass else: # Can't sort lists with None on Python 3 ... self.assertFalse(None in p1, "Bad input values for %s: %r" % (prop_name, p1)) self.assertFalse(None in p2, "Bad output values for %s: %r" % (prop_name, p2)) self.assertEqual(sorted(p1), sorted(p2))
def test_write(self): """Parse, rewrite and retest an example file.""" with open(filename) as infile: t1 = next(CDAOIO.Parser(infile).parse()) with open(DUMMY, "w") as outfile: CDAOIO.write([t1], outfile) with open(DUMMY) as infile: t2 = next(CDAOIO.Parser(infile).parse()) for prop_name in ("name", "branch_length", "confidence"): p1 = [getattr(n, prop_name) for n in t1.get_terminals()] p2 = [getattr(n, prop_name) for n in t2.get_terminals()] if p1 == p2: pass else: # Can't sort lists with None on Python 3 ... self.assertNotIn(None, p1, f"Bad input values for {prop_name}: {p1!r}") self.assertNotIn(None, p2, f"Bad output values for {prop_name}: {p2!r}") self.assertEqual(sorted(p1), sorted(p2))