Пример #1
0
class TestNode(unittest.TestCase):
    def setUp(self):
        self.root = Node("", None)

        if sys.version_info[0] < 3:
            self._string_classes = [str, unicode]
        else:
            self._string_classes = [str]

    def test_scratch_creation(self):
        root = Node("", None)
        self.assertEqual(root, root)

    def test_find_node(self):
        r_n = os.path.abspath(os.getcwd())

        for f in self._string_classes:
            n = self.root.find_node(f(os.getcwd()))
            self.assertTrue(n)
            assert n.abspath() == r_n

    def test_make_node(self):
        r_n = os.path.abspath(os.getcwd())

        for f in self._string_classes:
            n = self.root.make_node(f(os.getcwd()))
            self.assertTrue(n)
            assert n.abspath() == r_n, "%s vs %s" % (n.abspath(), r_n)

    def test_serialization(self):
        """Test pickled/unpickle round trip."""
        n = self.root.find_node(os.getcwd())
        r_n = pickle.loads(pickle.dumps(n))
        self.assertEqual(n.name, r_n.name)
        self.assertEqual(n.abspath(), r_n.abspath())
        self.assertEqual(n.parent.abspath(), r_n.parent.abspath())
        self.assertEqual(
            [child.abspath() for child in getattr(n, "children", [])],
            [child.abspath() for child in getattr(n, "children", [])])

    def test_str_repr(self):
        d = tempfile.mkdtemp()
        try:
            r_n = os.path.abspath(os.path.join(d, "foo.txt"))
            node = self.root.make_node(r_n)
            self.assertEqual(str(node), "foo.txt")
            self.assertEqual(repr(node), r_n)
        finally:
            shutil.rmtree(d)

    def test_invalid_copy(self):
        self.assertRaises(NotImplementedError, lambda: copy.copy(self.root))
Пример #2
0
class TestNode(unittest.TestCase):
    def setUp(self):
        self.root = Node("", None)

        if sys.version_info[0] < 3:
            self._string_classes = [str, unicode]
        else:
            self._string_classes = [str]

    def test_scratch_creation(self):
        root = Node("", None)
        self.assertEqual(root, root)

    def test_find_node(self):
        r_n = os.path.abspath(os.getcwd())

        for f in self._string_classes:
            n = self.root.find_node(f(os.getcwd()))
            self.assertTrue(n)
            assert n.abspath() == r_n

    def test_make_node(self):
        r_n = os.path.abspath(os.getcwd())

        for f in self._string_classes:
            n = self.root.make_node(f(os.getcwd()))
            self.assertTrue(n)
            assert n.abspath() == r_n, "%s vs %s" % (n.abspath(), r_n)

    def test_serialization(self):
        """Test pickled/unpickle round trip."""
        n = self.root.find_node(os.getcwd())
        r_n = pickle.loads(pickle.dumps(n))
        self.assertEqual(n.name, r_n.name)
        self.assertEqual(n.abspath(), r_n.abspath())
        self.assertEqual(n.parent.abspath(), r_n.parent.abspath())
        self.assertEqual([child.abspath() for child in getattr(n, "children", [])],
                         [child.abspath() for child in getattr(n, "children", [])])

    def test_str_repr(self):
        d = tempfile.mkdtemp()
        try:
            r_n = os.path.abspath(os.path.join(d, "foo.txt"))
            node = self.root.make_node(r_n)
            self.assertEqual(str(node), "foo.txt")
            self.assertEqual(repr(node), r_n)
        finally:
            shutil.rmtree(d)

    def test_invalid_copy(self):
        self.assertRaises(NotImplementedError, lambda: copy.copy(self.root))
Пример #3
0
class TestNode(unittest.TestCase):
    def setUp(self):
        self.root = Node("", None)

        if sys.version_info[0] < 3:
            self._string_classes = [str, unicode]
        else:
            self._string_classes = [str]

    def test_scratch_creation(self):
        root = Node("", None)
        assert_equal(root.abspath(), get_root())

    def test_find_node(self):
        r_n = os.path.abspath(os.getcwd())

        for f in self._string_classes:
            n = self.root.find_node(f(os.getcwd()))
            assert_true(n)
            assert n.abspath() == r_n

    def test_make_node(self):
        r_n = os.path.abspath(os.getcwd())

        for f in self._string_classes:
            n = self.root.make_node(f(os.getcwd()))
            assert_true(n)
            assert n.abspath() == r_n, "%s vs %s" % (n.abspath(), r_n)
Пример #4
0
class TestNode(unittest.TestCase):
    def setUp(self):
        self.root = Node("", None)

        if sys.version_info[0] < 3:
            self._string_classes = [str, unicode]
        else:
            self._string_classes = [str]

    def test_scratch_creation(self):
        root = Node("", None)
        self.assertEqual(root, root)

    def test_find_node(self):
        r_n = os.path.abspath(os.getcwd())

        for f in self._string_classes:
            n = self.root.find_node(f(os.getcwd()))
            self.assertTrue(n)
            assert n.abspath() == r_n

    def test_make_node(self):
        r_n = os.path.abspath(os.getcwd())

        for f in self._string_classes:
            n = self.root.make_node(f(os.getcwd()))
            self.assertTrue(n)
            assert n.abspath() == r_n, "%s vs %s" % (n.abspath(), r_n)

    def test_serialization(self):
        """Test pickled/unpickle round trip."""
        n = self.root.find_node(os.getcwd())
        r_n = pickle.loads(pickle.dumps(n))
        self.assertEqual(n.name, r_n.name)
        self.assertEqual(n.abspath(), r_n.abspath())
        self.assertEqual(n.parent.abspath(), r_n.parent.abspath())
        self.assertEqual([child.abspath() for child in getattr(n, "children", [])],
                         [child.abspath() for child in getattr(n, "children", [])])
Пример #5
0
 def setUp(self):
     root = Node("", None)
     self.d_node = root.find_node(tempfile.mkdtemp())
     assert self.d_node is not None
Пример #6
0
 def setUp(self):
     root = Node("", None)
     self.d_node = root.find_node(tempfile.mkdtemp())
     assert self.d_node is not None