def test_search_text(): note1 = Note( "Joseph Conrad", "Modernist author.", attrs={ "birth": "1857", "death": "1924", "nationality": "British-Polish", "novels": ["Nostromo", "The Secret Agent"] }, ) note2 = Note( "Charles Dickens", "Famous Victorian author.", attrs={ "birth": "1812", "death": "1870", "nationality": "British", "novels": ["Great Expectations"] }, ) container = Container(notes=[note1, note2]) condition = NumberConditional(target="1850", condition="le") query = container.search_child_note_attrs(condition, attrs=["birth"]) assert len(query) == 1
def load_document(self, file): self.children = dict() with open(file, 'r') as infile: data = json.load(infile) for id, obj in data["backend"].items(): if obj["type"] == "note": note = Note.from_dict(obj) self.children[note.id] = note elif obj["type"] == "connection": connection = Connection.from_dict(obj) self.children[connection.id] = connection
def test_note_creation(): note1 = Note( "Joseph Conrad", "Modernist author.", attrs={ "birth": "1857", "death": "1924", "nationality": "British-Polish", "novels": ["Nostromo", "The Secret Agent"] }, ) assert note1.attrs["title"] == "Joseph Conrad" and note1.attrs[ "birth"] == "1857"
def CreateNote(self, request, context): note = Note( title=request.attrs["title"], text=request.attrs["text"], id=request.id, attrs=dict(request.attrs), parent_container=document.children[request.parent_container_id] if len(request.parent_container_id) > 0 else None) document.children[note.id] = note return tasks_pb2.NoteReply( id=note.id, attrs=note.attrs, parent_container_id=request.parent_container_id)
def test_prototype(): prototype = Note("Joseph Conrad", "Modernist author.", attrs={"birth": "1857", "death": "1924", "nationality": "British-Polish", "novels": ["Nostromo", "The Secret Agent"] }, ) inherited_attrs = {"title", "birth"} descendant = prototype.create_descendant(inherited_attrs=inherited_attrs) prototype.update_attr("death", "0") prototype.update_title("blah") prototype.update_attr("birth", "10") assert prototype.attrs["death"] != descendant.attrs["death"] assert prototype.attrs["birth"] == descendant.attrs["birth"] assert prototype.attrs["title"] == descendant.attrs["title"]
def create_notes_from_web_data(self, data, indices_dict): notes = list() for node in data: title = "" for ind in indices_dict["title"]: title += node[ind] text = "" for ind in indices_dict["text"]: text += node[ind] attrs = dict() for attr, val in indices_dict["attrs"].items(): attr_text = "" for ind in val: attr_text += node[ind] attrs[attr] = attr_text notes.append(Note(title=title, text=text, attrs=attrs)) return notes
def test_rule(): note = Note( "Joseph Conrad", "Modernist author.", attrs={ "birth": "1857", "death": "1924", "nationality": "British-Polish", "novels": ["Nostromo", "The Secret Agent"] }, ) container = Container(notes=[note]) rule = Rule(target="title", add_text="Author - ", effect_location="prepend") container.add_rule(rule) assert note.attrs["title"] == "Author - Joseph Conrad"
def create_note(ctx, title, text, attr_keys, attr_vals): attrs = dict(zip(attr_keys, attr_vals)) note = Note(title=title, text=text, attrs=attrs) print("Note created: {}".format(note.title)) ctx[note.id] = note