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
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
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
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
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"
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"
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
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")
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)
def test_non_unicode(self): with pytest.raises(AssertionError): parse_line(b"herp: derp")
def test_no_space(self): with pytest.raises(LoadError): parse_line(u"herp:derp")
def test_bad_indentation(self): with pytest.raises(LoadError): parse_line(u" @option")
def test_metadata_node_id(self): with pytest.raises(LoadError): parse_line(u" @option#badid: derp")