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

    """Generate a test method for checking tree shapes.
    Counts the branches at each level of branching in a phylogenetic tree, 3
    clades deep.
    """
    fname = os.path.basename(source)
    def test_shape(self):
        trees = PhyloXMLIO.parse(source)
        for (tree, shape_expect) in zip(trees, shapes):
            self.assertEqual(len(tree.clade), len(shape_expect))
            for (clade, sub_expect) in zip(tree.clade, shape_expect):
                self.assertEqual(len(clade), sub_expect[0])
                for (subclade, len_expect) in zip(clade, sub_expect[1]):
                    self.assertEqual(len(subclade), len_expect)
    test_shape.__doc__ = ('Check    the    branching    structure    of    %s.' % fname)
    return test_shape