def test_is_file(self): node = Node('any', NodeKind.FILE) self.assertTrue(node.is_file()) node = FileNode('any') self.assertTrue(node.is_file()) self.assertRaises(AttributeError, getattr, node, 'nodes')
def test_is_file(self): node = Node('any', NodeKind.FILE) assert node.is_file() node = FileNode('any') assert node.is_file() with pytest.raises(AttributeError): node.nodes
def test_is_dir(self): node = Node('any_dir', NodeKind.DIR) self.assertTrue(node.is_dir()) node = DirNode('any_dir') self.assertTrue(node.is_dir()) self.assertRaises(NodeError, getattr, node, 'content')
def test_is_dir(self): node = Node('any_dir', NodeKind.DIR) assert node.is_dir() node = DirNode('any_dir') assert node.is_dir() with pytest.raises(NodeError): node.content
def test_parent_path_new(self, node_path, expected_parent_path): """ Tests if node's parent path are properly computed. """ node = Node(node_path, NodeKind.DIR) parent_path = node.get_parent_path() assert (parent_path.endswith('/') or node.is_root() and parent_path == '') assert parent_path == expected_parent_path
def _test_parent_path(self, node_path, expected_parent_path): """ Tests if node's parent path are properly computed. """ node = Node(node_path, NodeKind.DIR) parent_path = node.get_parent_path() self.assertTrue(parent_path.endswith('/') or \ node.is_root() and parent_path == '') self.assertEqual(parent_path, expected_parent_path, "Node's path is %r and parent path is %r but should be %r" % (node.path, parent_path, expected_parent_path))
def test_name(self): node = Node('', NodeKind.DIR) self.assertEqual(node.name, '') node = Node('path', NodeKind.FILE) self.assertEqual(node.name, 'path') node = Node('path/', NodeKind.DIR) self.assertEqual(node.name, 'path') node = Node('some/path', NodeKind.FILE) self.assertEqual(node.name, 'path') node = Node('some/path/', NodeKind.DIR) self.assertEqual(node.name, 'path')
def test_kind_setter(self): node = Node('', NodeKind.DIR) with pytest.raises(NodeError): node.kind = NodeKind.FILE
def test_root_node_cannot_be_file(self): with pytest.raises(NodeError): Node('', NodeKind.FILE)
def test_name_root(self): node = Node('', NodeKind.DIR) assert node.name == ''
def test_name(self, path, kind): node = Node(path, kind) assert node.name == 'path'
def test_init_wrong_paths(self, path, kind): """ Cannot innitialize Node objects with path with slash at the beginning. """ with pytest.raises(NodeError): Node(path, kind)
def test_kind_setter(self): node = Node('', NodeKind.DIR) self.assertRaises(NodeError, setattr, node, 'kind', NodeKind.FILE)