def test__get_sources_c_prim_with_partial_data(self): db_add_objects(Word, [ other_word_2, ]) db_add_objects(Type, types) result = Word.get_by_id(3813)._get_sources_c_prim() assert len(result) == 5
def test_e_year(self): """Test year conversion""" db_add_objects(Word, words) word = Word.get_by_id(3911) result = word.e_year assert result == "1988 (?)"
def test_relationship_appeared_words(self): db_add_objects(Word, changed_words) db_add_objects(Event, changed_events) event = Event.get_by_id(5) assert isinstance(event.deprecated_words, list) assert len(event.deprecated_words) == 4
def test_grammar(self): db_add_objects(Definition, definitions) d = Definition.get_by_id(13527) assert d.grammar == "(4v)" d = Definition.get_by_id(13529) assert d.grammar == "(a)"
def test_export(self): """Test Definition.export() method""" db_add_objects(Word, words) db_add_objects(Definition, definitions) definition = Definition.get_by_id(13527) result = definition.export() assert result == "7191@1@@4v@K «test»/«examine» B for P with test V.@@K-BPV"
def test_e_usedin_empty(self): """Test used_in conversion if no cpx""" db_add_object(Word, word_2) db_add_objects(Type, types) word = Word.get_by_id(3813) result = word.e_usedin assert result == str()
def test_derivatives(self): db_add_objects(Word, words) db_connect_words(connect_words) p1 = Word.get_by_id(3813) assert isinstance(p1.derivatives, BaseQuery) assert p1.derivatives.count() == 3
def test_link_keys_from_definition_body(self): db_add_objects(Key, keys) d = dar(Definition, definition_1) assert d.keys.count() == 0 d.link_keys_from_definition_body() assert d.keys.count() == 2 assert sorted([k.word for k in d.keys]) == sorted(["test", "examine"])
def test_definitions_relationship(self): word = dar(Word, word_1) definitions_to_add = [ d for d in definitions if d["word_id"] == word.id ] db_add_objects(Definition, definitions_to_add) assert word._definitions.count() == len(definitions_to_add) == 5 assert isinstance(word._definitions[0], Definition)
def test_parents(self): db_add_objects(Word, words) db_connect_words(connect_words) result = Word.get_by_id(7316).parents assert len(result.all()) == 2 assert isinstance(result, BaseQuery) assert isinstance(result[0], Word)
def test_e_affixes(self): """Test affix conversion""" db_add_objects(Word, words) db_connect_words(connect_words) db_add_objects(Type, types) word = Word.get_by_id(3813) result = word.e_affixes assert result == "kak kao"
def test_link_key_from_str(self): db_add_objects(Key, keys) d = dar(Definition, definition_2) assert d.keys.count() == 0 key_to_add = "tester" d.link_key_from_str(key_to_add) assert d.keys.count() == 1 assert d.keys.first().word == key_to_add
def test_relationship_definitions(self): db_add_objects(Key, keys) db_add_objects(Definition, definitions) db_connect_keys(connect_keys) key = Key.get_by_id(12474) assert isinstance(key.definitions, BaseQuery) assert len(key.definitions.all()) == 5 assert [d.id for d in key.definitions ] == [13521, 13523, 13524, 13527, 13531]
def test_add_children(self): db_add_objects(Word, words) cmp = Word.get_by_id(word_1.get("id")) assert cmp._parents.count() == 0 for p in [word_2, word_3]: prim = Word.get_by_id(p.get("id")) prim.add_children([cmp, ]) assert cmp._parents.count() == 2
def test_affixes(self): db_add_objects(Word, words) db_add_objects(Type, types) db_connect_words(connect_words) result = Word.get_by_id(3813).affixes assert len(result.all()) == 2 assert isinstance(result, BaseQuery) assert isinstance(result[0], Word)
def test_link_keys_from_list_of_str(self): db_add_objects(Definition, definitions) db_add_objects(Key, keys) keys_to_add = ["test", "examine"] d = Definition.get_by_id(13527) assert d.keys.count() == 0 d.link_keys_from_list_of_str(keys_to_add) assert d.keys.count() == 2 assert sorted([k.word for k in d.keys]) == sorted(keys_to_add)
def test_add_authors(self): db_add_objects(Word, words) db_add_objects(Author, authors) word = Word.get_by_id(7316) assert word.authors.count() == 0 local_authors = Author.get_all() word.add_authors(local_authors) assert word.authors.count() == 2 assert isinstance(word.authors[0], Author)
def test_relationship_words(self): db_add_objects(Type, types) db_add_objects(Word, words) test_type = Type.by("Little").first() assert len(test_type.words) == 3 test_type = Type.by("C-Prim").first() assert len(test_type.words) == 2 test_type = Type.by("Cpx").first() assert len(test_type.words) == 1
def test_authors_relationship(self): db_add_objects(Word, words) db_add_objects(Author, authors) db_connect_authors(connect_authors) word = Word.get_by_id(7316) author = Author.get_by_id(29) assert word.authors.count() == 1 assert word.authors[0] == author assert word.authors.first() == author assert isinstance(word.authors.all(), list) assert len(word.authors.all()) == 1
def test_by(self): db_add_objects(Type, types) test_type = Type.by("Little").first() assert test_type.type == "Afx" test_type = Type.by("Little") assert test_type[0].type == "Afx" test_type = Type.by("2-Cpx").first() assert test_type.group == "Cpx" test_type = Type.by("Predicate").count() assert test_type == 2
def test__get_sources_c_prim(self): db_add_objects(Word, words) db_add_objects(Type, types) result = Word.get_by_id(3813)._get_sources_c_prim() assert len(result) == 5 assert isinstance(result, list) assert isinstance(result[0], WordSource) afx = Word.get_by_id(3802) result = afx._get_sources_c_prim() assert result is None
def test_uniqueness(self): db_add_objects(Key, [ un_key_1, un_key_2, ]) result = [k.word for k in Key.get_all()] assert result == [ "examine", "examine", ] with pytest.raises(sqlalchemy.exc.IntegrityError) as _: assert isinstance(dar(Key, un_key_3), Key)
def test_add_author(self): db_add_objects(Word, words) db_add_objects(Author, authors) word = Word.get_by_id(7316) author = Author.get_by_id(29) assert word.authors.count() == 0 word.add_author(author) assert word.authors.count() == 1 assert word.authors[0] == author word.add_author(author) assert word.authors.count() == 1
def test_e_usedin(self): """Test used_in conversion""" db_add_objects(Word, words) db_connect_words(connect_words) db_add_objects(Type, types) word1 = Word.get_by_id(3813) result = word1.e_usedin assert result == "prukao" word2 = Word.get_by_id(7316) result = word2.e_usedin assert result == ""
def test_event_relationship(self, item): db_add_objects(Event, all_events) word = dar(Word, item) event_start_from_db = Event.get_by_id(word.event_start_id) assert isinstance(event_start_from_db, Event) assert event_start_from_db == word.event_start if word.event_end_id: event_end_from_db = Event.get_by_id(word.event_end_id) assert isinstance(event_end_from_db, Event) assert event_end_from_db == word.event_start else: assert word.event_end is None
def test_html_meaning(self): db_add_objects(Word, words) db_add_objects(Type, types) db_add_objects(Author, authors) db_add_objects(Definition, definitions) db_connect_authors(connect_authors) db_connect_words(connect_words) word = Word.get_by_id(7315) expected_result_ultra = """<m> <t><afx>pru</afx> <o><3/4E prove | 2/4C sh yen | 3/6S prueba | 2/5R proba | 2/5F epreuve | 2/5G probe | 2/6J tameshi></o> <tec>49% C-Prim L4 1975 1.9</tec></t> <ds> <dl>(3n) V is a <k>test</k>/<k>examination</k> for property B in any member of class F. [V‍-‍BF]</dl> <dl>(vt) <k>test</k>, test for … a property … in a member of ….</dl> <dl><du>fu —</du> (a) <k>testable</k>, of classes with -able members.</dl> <dl><du>nu —</du> (a) <k>testable</k>, of testable properties.</dl> </ds> <us>Used In: <use><cpx>prukao</cpx></use></us> </m>""" result = word.html_meaning(style="ultra") assert result == expected_result_ultra expected_result_normal = """<div class="meaning" id="7315"> <div class="technical"><span class="m_afx">pru</span> <span class="m_origin"><3/4E prove | 2/4C sh yen | 3/6S prueba | 2/5R proba | 2/5F epreuve | 2/5G probe | 2/6J tameshi></span> <span class="m_technical"><span class="m_match">49%</span> <span class="m_type">C-Prim</span> <span class="m_author">L4</span> <span class="m_year">1975</span> <span class="m_rank">1.9</span></span></div> <div class="definitions"> <div class="definition log" id=13523><span class="dg">(3n)</span> <span class="db">V is a <k>test</k>/<k>examination</k> for property B in any member of class F.</span> <span class="dt">[V‍-‍BF]</span></div> <div class="definition log" id=13524><span class="dg">(vt)</span> <span class="db"><k>test</k>, test for … a property … in a member of ….</span></div> <div class="definition log" id=13525><span class="du">fu —</span> <span class="dg">(a)</span> <span class="db"><k>testable</k>, of classes with -able members.</span></div> <div class="definition log" id=13526><span class="du">nu —</span> <span class="dg">(a)</span> <span class="db"><k>testable</k>, of testable properties.</span></div> </div> <div class="used_in">Used In: <span class="m_use"><a class="m_cpx">prukao</a></span></div> </div>""" result = word.html_meaning(style="normal") assert result == expected_result_normal
def test_add_child(self): db_add_objects(Word, words) cmp = Word.get_by_id(word_1.get("id")) assert cmp._parents.count() == 0 for p in [word_2, word_3]: prim = Word.get_by_id(p.get("id")) result = prim.add_child(cmp) assert result == cmp.name assert cmp._parents.count() == 2 prim = Word.get_by_id(word_3.get("id")) prim.add_child(cmp) assert cmp._parents.count() == 2
def test_relationship_contribution(self): db_add_objects(Author, authors) db_add_objects(Word, words) db_connect_authors(connect_authors) test_author = Author.get_by_id(29) assert len(test_author.contribution) == 3 assert isinstance(test_author.contribution, list) assert [w.name for w in test_author.contribution ] == ['kakto', 'pruci', 'prukao'] test_author = Author.get_by_id(13) assert len(test_author.contribution) == 3 assert [w.name for w in test_author.contribution] == ['kak', 'kao', 'pru']
def test_by_name(self): db_add_objects(Word, doubled_words) db_add_objects(Event, events) result = Word.by_name("duo").count() assert result == 2 result = Word.by_name("duo").all() assert isinstance(result, list) assert isinstance(result[0], Word) result = sorted([w.type_id for w in result]) assert result == [2, 17] result = Word.by_name("duo").first() assert isinstance(result, Word)
def test_by_event(self): db_add_objects(Word, changed_words + words) db_add_objects(Event, all_events) result = Word.get_all() assert len(result) == 13 result = Word.by_event(1).all() assert len(result) == 10 result = Word.by_event(5).all() assert len(result) == 9 result = Word.by_event().all() assert len(result) == 9