def testsaveas(self):
        treepath = os.path.join(testtmp, "saveas")
        tree = treestate.treestate(treepath, 0)
        tree.insert("a", 1, 2, 3, 4, None)
        tree.setmetadata(b"1")
        tree.flush()

        tree.insert("b", 1, 2, 3, 4, None)
        tree.remove("a")
        treepath = "%s-savedas" % treepath
        tree.setmetadata(b"2")
        rootid = tree.saveas(treepath)

        tree = treestate.treestate(treepath, rootid)
        self.assertFalse("a" in tree)
        self.assertTrue("b" in tree)
        self.assertEqual(tree.getmetadata(), b"2")