コード例 #1
0
ファイル: userinterface.py プロジェクト: kidaa/tree-of-life
def _makenode(string):
    indent, is_metadata, nodeid, node_type, text = parse_line(string)
    if is_metadata:
        raise InvalidInputError("metadata not allowed")
    if indent > 0:
        raise InvalidInputError("plz 2 not indent")
    return node_type, text
コード例 #2
0
 def test_metadata_notext(self):
     line = u"    @option\xfc"
     indent, is_metadata, node_id, node_type, text = parse_line(line)
     assert indent == 1
     assert is_metadata
     assert node_id is None
     assert node_type == u"option\xfc"
     assert text is None
コード例 #3
0
 def test_empty_line_indent(self):
     line = u"      "
     indent, is_metadata, node_id, node_type, text = parse_line(line)
     assert indent == 0
     assert not is_metadata
     assert node_id is None
     assert node_type == u""
     assert text is None
コード例 #4
0
 def test_notext_id(self):
     line = u"        minor\xfc tasks#abcde"
     indent, is_metadata, node_id, node_type, text = parse_line(line)
     assert indent == 2
     assert not is_metadata
     assert node_id == u"abcde"
     assert node_type == u"minor\xfc tasks"
     assert text is None
コード例 #5
0
 def test_basic_nodeid(self):
     line = u"\xfccategory#asdfg: \xfcpersonal \xfcprojects"
     indent, is_metadata, node_id, node_type, text = parse_line(line)
     assert indent == 0
     assert not is_metadata
     assert node_id == u"asdfg"
     assert node_type == u"\xfccategory"
     assert text == u"\xfcpersonal \xfcprojects"
コード例 #6
0
 def test_indent_id(self):
     line = u"    \xfcproject#hjklo: \xfctodo \xfctracker"
     indent, is_metadata, node_id, node_type, text = parse_line(line)
     assert indent == 1
     assert not is_metadata
     assert node_id == u"hjklo"
     assert node_type == u"\xfcproject"
     assert text == u"\xfctodo \xfctracker"
コード例 #7
0
ファイル: misc.py プロジェクト: kidaa/tree-of-life
    def unarchive(cls, node, parent):
        if node.node_type not in ("archived", "unarchive", "unarchived"):
            newnode = node.copy(parent=parent, children=False, nodeid=node.id)
        else:
            indent, ismetadata, nodeid, node_type, text = parse_line(node.text)
            assert not indent
            assert not ismetadata
            if node_type == "archived":
                indent, ismetadata, nodeid, node_type, text = parse_line(text)
                assert not indent
                assert not ismetadata

            newnode = node.root.nodecreator.create(node_type, text, parent,
                    nodeid=nodeid)
            for option, value, show in node.option_values():
                if show and option != "_af":
                    newnode.setoption(option, value)

        for child in list(node.children):
            child = child.detach()
            newnode.addchild(cls.unarchive(child, parent=newnode))

        return newnode
コード例 #8
0
    def test_bad_node_id(self):
        with pytest.raises(LoadError):
            parse_line(u"    option#longid: derp")
        with pytest.raises(LoadError):
            parse_line(u"    option#shrt: derp")

        with pytest.raises(LoadError):
            # invalid characters
            parse_line(u"    option#-----: derp")
コード例 #9
0
ファイル: misc.py プロジェクト: kidaa/tree-of-life
 def __init__(self, node_type, text, *a, **kw):
     if kw.get("nodeid", None) is None and text:
         _, _, nodeid, _, _ = parse_line(text)
         kw["nodeid"] = nodeid
     GenericNode.__init__(self, node_type, text, *a, **kw)
コード例 #10
0
 def test_non_unicode(self):
     with pytest.raises(AssertionError):
         parse_line(b"herp: derp")
コード例 #11
0
 def test_no_space(self):
     with pytest.raises(LoadError):
         parse_line(u"herp:derp")
コード例 #12
0
 def test_bad_indentation(self):
     with pytest.raises(LoadError):
         parse_line(u"  @option")
コード例 #13
0
 def test_metadata_node_id(self):
     with pytest.raises(LoadError):
         parse_line(u"    @option#badid: derp")