def setUp(self):
     self.factory = TreeNodeFactory()
     self.named_node_id = 'node-name'
     self.node_data1 = "created: 2012-09-18T12:12:12"
     self.node_data2 = "allow jim to create salaries wt 90"
     self.node_comment = "# This is a comment"
class TestTreeNodeFactory(unittest.TestCase):

    def setUp(self):
        self.factory = TreeNodeFactory()
        self.named_node_id = 'node-name'
        self.node_data1 = "created: 2012-09-18T12:12:12"
        self.node_data2 = "allow jim to create salaries wt 90"
        self.node_comment = "# This is a comment"

    def test_make_named_node(self):
        node1 = self.factory.make_node(" " * 4 + NAME_PREFIX +
                                       self.named_node_id)
        assert node1.__class__.__name__ == 'TreeNamedNode'
        assert node1._content == self.named_node_id
        assert node1.indent_level == 1
        node2 = self.factory.make_node(" " * 12 + NAME_PREFIX +
                                       self.named_node_id)
        assert node2.__class__.__name__ == 'TreeNamedNode'
        assert node2.node_id == self.named_node_id
        assert node2.indent_level == 3
        with pytest.raises(TreeParserError) as exc_info:
            self.factory.make_node(" " * 11 + NAME_PREFIX + self.named_node_id)
        assert exc_info.value.message == \
            'Bad line: ">>>>>>>>~~~...~node-name"'

    def test_make_data_node(self):
        node1 = self.factory.make_node(" " * 4 + DATA_PREFIX + self.node_data1)
        assert node1.__class__.__name__ == 'TreeDataNode'
        assert node1._content == self.node_data1
        assert node1.indent_level == 1
        node2 = self.factory.make_node(" " * 12 + DATA_PREFIX +
                                       self.node_data2)
        assert node2.__class__.__name__ == 'TreeDataNode'
        assert node2.data == self.node_data2
        assert node2.indent_level == 3
        with pytest.raises(TreeParserError) as exc_info:
            self.factory.make_node(" " * 11 + DATA_PREFIX + self.node_data2)
        assert exc_info.value.message.startswith(
            'Bad line: ">>>>>>>>~~~***~allow~jim~to~create')

    def test_make_comment_node(self):
        node1 = self.factory.make_node(" " * 4 + self.node_comment)
        assert node1.__class__.__name__ == 'TreeCommentString'
        assert node1._content == self.node_comment
        assert node1.indent_level == 0
        node2 = self.factory.make_node(" " * 12 + self.node_comment)
        assert node2.__class__.__name__ == 'TreeCommentString'
        assert node2.comment == self.node_comment
        assert node2.indent_level == 2
        # Can't have a comment line starting without any indent
        with pytest.raises(TreeParserError) as exc_info:
            self.factory.make_node(self.node_comment)
        assert exc_info.value.message == (
            'Bad indent level (-1) for '
            'TreeCommentString line "# This is a comment"'
        )

    def test_blank_line_in_data(self):
        assert self.factory.make_node("") is None