def test_error_on_bad_record(self): with self.assertRaises(ValueError): NexusMaker([ Record(Word="leg", Item="", Cognacy="2") # no language ]) with self.assertRaises(ValueError): NexusMaker([ Record(Language="French", Item="", Cognacy="2") # no word ])
def test_is_loan(self): assert not Record(Loan="").is_loan assert not Record(Loan=None).is_loan assert Record(Loan="L").is_loan assert Record(Loan="English").is_loan assert Record(Loan=True).is_loan assert Record(Loan="B").is_loan assert Record(Loan="S").is_loan assert Record(Loan="X").is_loan assert Record(Loan="x").is_loan
def test_error_on_cognates_with_loans(self): """Test that we generate an error if a loan word enters .cognates()""" n = NexusMaker(TESTDATA) n.data.append( Record(Language="D", Word="eye", Item="", Cognacy="1", Loan=True)) with self.assertRaises(ValueError): n.cognates
def test_simple(self): r = Record(ID=1, WID=2, LID=3, Language='English', Word='Hand', Item='hand', Annotation='?', Cognacy=None, Loan="L") assert r.ID == 1 assert r.WID == 2 assert r.LID == 3 assert r.Language == 'English' assert r.Word == 'Hand' assert r.Item == 'hand' assert r.Annotation == '?' assert r.Loan == "L" assert r.Cognacy == None
def test_get_token(self): r = Record(ID=1, WID=2, LID=3, Language='English', Word='Hand', Item='hand', Annotation='?', Cognacy=None, Loan="L") assert r.get_taxon() == "English_3" r = Record(ID=1, WID=2, LID=None, Language='English', Word='Hand', Item='hand', Annotation='?', Cognacy=None, Loan="L") assert r.get_taxon() == "English"
40167 006 Mopan 00026 Ulrich_and_Ulrich cloud muyal 6c 23136 024 Kiche 00004 Kaufman_1976 cloud suutZ' 2 23137 024 Kiche 00009 Campbell_1971b cloud suutZ' 2 23138 024 Kiche 00022 Mayers_ed_1966 cloud sutZ' 2 23139 024 Kiche 00061 Stoll_1884 cloud su'tZ 2 50386 024 Kiche 00086 Kaufman_2003 cloud mayuul 6 50389 024 Kiche 00086 Kaufman_2003 cloud mayuy 6b 53557 036 Popti 00086 Kaufman_2003 cloud xhmoyxi 6d 53558 036 Popti 00086 Kaufman_2003 cloud asun 1 """ HEADER = [ 'ID', "LID", "Language", "SID", "Source", "Word", "Item", "Cognacy", "Loan" ] COMPLEX_TESTDATA = [ Record(**dict(zip(HEADER, r.split('\t')))) for r in RECORDS.split("\n") if len(r.strip()) ] EXPECTED_COGNATES = { ('cloud', '1'): { 'Tojolabal_012', 'Chuj_013', 'Mocho_017', 'Jakalteko_014', 'Qanjobal_016', 'Akateco_015', 'Tuzanteco_037', 'Popti_036' }, ('cloud', '2'): { 'Achi_025', 'Kaqchikel_022', 'Poqomam_029', 'Sakapulteko_026', 'Ixil_021', 'Kiche_024', 'Poqomchi_030', 'Tzutujil_023', 'Uspanteko_028' }, ('cloud', '2b'): {'Qanjobal_016'}, ('cloud', '3'): {'Awakateko_020'},
import sys import unittest from nexusmaker import Record from nexusmaker import NexusMaker, NexusMakerAscertained, NexusMakerAscertainedWords TESTDATA = [ Record(Language="A", Word="eye", Item="", Cognacy="1"), Record(Language="A", Word="leg", Item="", Cognacy="1"), Record(Language="A", Word="arm", Item="", Cognacy="1"), Record(Language="B", Word="eye", Item="", Cognacy="1"), Record(Language="B", Word="leg", Item="", Cognacy="2"), Record(Language="B", Word="arm", Item="", Cognacy="2"), Record(Language="C", Word="eye", Item="", Cognacy="1"), # No Record for C 'leg' Record(Language="C", Word="arm", Item="", Cognacy="3"), Record(Language="D", Word="eye", Item="", Cognacy="1", Loan=True), Record(Language="D", Word="leg", Item="", Cognacy="1"), Record(Language="D", Word="leg", Item="", Cognacy="2"), Record(Language="D", Word="arm", Item="", Cognacy="2,3"), ] class TestNexusMakerInternals(unittest.TestCase): def test_error_on_non_record(self): with self.assertRaises(ValueError): NexusMaker(['1']) def test_error_on_bad_record(self): with self.assertRaises(ValueError): NexusMaker([
import unittest from nexusmaker import NexusMaker, Record TESTDATA = [ Record(Language="A", Word="eye", Item="", Cognacy="1"), Record(Language="B", Word="eye", Item="", Cognacy="1"), Record(Language="C", Word="eye", Item="", Cognacy="2"), Record(Language="D", Word="eye", Item="", Cognacy="2"), Record(Language="E", Word="eye", Item="", Cognacy=""), ] class TestBugUniquesAndAmbig(unittest.TestCase): """ Fix Bug caused by lru_cache on ._is_missing_for_word that made unique sites occur as single ones in blocks of missing states. """ def setUp(self): self.maker = NexusMaker(data=TESTDATA) self.nex = self.maker.make() def test_cognate_sets(self): assert ('eye', '1') in self.maker.cognates assert ('eye', '2') in self.maker.cognates assert ('eye', 'u_1') in self.maker.cognates assert sorted(self.maker.cognates[('eye', '1')]) == ['A', 'B'] assert sorted(self.maker.cognates[('eye', '2')]) == ['C', 'D'] assert sorted(self.maker.cognates[('eye', 'u_1')]) == ['E'] def test_is_missing_for_word(self):
Iaai-471 125865 five thabyŋ Lamogai-67 83796 five elmé 1 Lamogai-67 83881 hand mulǵu 45 Lamogai-67 83882 hand melsé 45 Lamogai-67 83883 hand milpí 45 Lamogai-67 83884 hand melép 45 Lamogai-67 83885 hand milpú 45 Lamogai-67 83886 hand meylá 45 Lamogai-67 83887 hand melsék 45 Lamogai-67 83942 leg kaip 1 Lamogai-67 83943 leg kaŋgú 1 """ RECORDS = [r.split("\t") for r in RECORDS.split("\n") if len(r)] COMPLEX_TESTDATA = [ Record(Language=r[0], Word=r[2], Item=r[3], Cognacy=r[4]) for r in RECORDS ] EXPECTED_COGNATES = { ('five', '1'): { 'Aiwoo-501', 'Banoni-4', 'Dehu-196', 'Eton-1088', 'Hiw-639', 'Lamogai-67' }, ('leg', '86'): {'Aiwoo-501'}, ('hand', '1'): {'Aiwoo-501', 'Banoni-4', 'Hiw-639'}, ('hand', '64'): {'Banoni-4'}, ('hand', '66'): {'Aiwoo-501'}, ('leg', '95'): {'Eton-1088'}, ('hand', '78'): {'Hiw-639'}, ('leg', '17'): {'Hiw-639'}, ('hand', '14'): {'Iaai-471'},