human
Complete this python program:
def _test_write_factory(source):
assistant
#Here is the Python code you requested.

    """Tests for serialization of objects to CDAO format.
    Modifies the globally defined filenames in order to run the other parser
    tests on files (re)generated by CDAOIO\s own writer.
    """
    filename = os.path.join('CDAO/', source)
    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:
                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))
    test_write.__doc__ = ('Write    and    re-parse    the    phylogenies    in    %s.' % source)
    return test_write