-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
131 lines (105 loc) · 5.91 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# ############################################################################
# Repertory converter / parser / importer for OOREP (https://www.oorep.com/)
# Copyright (c) 2021 Andreas Bauer <[email protected]>
# License: GPL v3.0 (or higher)
import parser
from parser import *
import converter
import unittest
glob_filenames = ['SKRep3.txt']
glob_repertoryAbbrev = 'bogsk-de'
completeInputFiles = []
for filename in glob_filenames:
with open(filename, encoding='utf-8-sig') as f:
lines = [line.rstrip() for line in f]
completeInputFiles.extend(lines)
class SimpleParser(unittest.TestCase):
def test(self):
print("*** Remedy(ies)Parser: ")
print(RemedyParser.remedy.parse('RUTA')) # This is 4-valued
print(RemedyParser.remedy.parse('Ruta')) # This is 1-valued
print(RemedyParser.remedy.parse('Ars.'))
print(RemedyParser.remedy.parse('Ars-alb.'))
print(RemedyParser.remedy.parse('Ars. (3)'))
print(RemediesParser.remedies.parse('Ars. (3) Ruta Ars-i. (2) BRY.'))
print("*** RubricTextParser: ")
print(RubricTextParser.rubricText.parse('= Zeit'))
print(RubricTextParser.rubricText.parse('== agg. (vgl. Dünnschiss)'))
print("*** RubricParser: ")
print(RubricParser.rubric.parse('= Zeit.'))
print(RubricParser.rubric.parse('== agg. (vgl. Dünnschiss): Ars. Ruta Ars-i. (2)'))
print(RubricParser.rubric.parse('==== agg. (vgl. Dünnschiss): Ars. (3) Ruta Ars-i. (2) Sulph.'))
print(RubricParser.rubric.parse('=== agg.: Aran. Ars. (3) Cact. Cedr. Chin. (3)'))
print(RubricParser.rubric.parse('== Atmen, tief, agg.: Acon. (2) Arn. Bor. (2) BRY. Calc. Caust. Kali-c. (2) Phos. (2) Ran-b. Rhus-t. Rumx. Sabin. Sang. Spig. Squil. Sulph.'))
print(RubricParser.rubric.parse('=== amel.: Asaf. (2) Bism. (2) Calc. (2) Cycl. (2) Mur-ac. (2) Thuj. (2)'))
print(RubricParser.rubric.parse('=== agg.: Acon. (2) Bell. Bry. (3) Cad-s. Cham. COCC. Ferr. Ign. Merc-i-f. (2) Nat-m. Nux-v. Op. Phos. Phyt. (2) Puls. Rhus-t. Sil. Sulph. Verat-v. Vib.'))
print(RubricParser.rubric.parse('=== links, nach: Apis, BELL. Caust. LYC. MERC-I-F. Phos. Sabad. Sang. Sul-ac.'))
class CompleteParser(unittest.TestCase):
tmpAllRubrics = []
@classmethod
def setUpClass(cls):
cls.tmpAllRubrics = parser.getAllRubricsFromFileContents(completeInputFiles)
def test_outputOfParsedFile(self):
for rubric in self.tmpAllRubrics:
print(str(rubric.index).zfill(4) + " [" + str(rubric.parentIndex).zfill(4) + "] ", end='')
for i in range(1, rubric.depth):
print(" ", end='')
print(rubric)
def test_getFullpathsOfParsedRubrics(self):
for rubric in self.tmpAllRubrics:
print(rubric.getFullPath(self.tmpAllRubrics))
class ConvertersRemedy(unittest.TestCase):
repertoryAbbrev = glob_repertoryAbbrev
allRubricsFromFile = []
@classmethod
def setUpClass(cls):
cls.allRubricsFromFile = parser.getAllRubricsFromFileContents(completeInputFiles)
def test_getTable(self):
tableRemedy = converter.getCompleteRemedyTable(self.__class__.allRubricsFromFile, self.__class__.repertoryAbbrev)
print("#tableRemedy: " + str(len(tableRemedy)))
class ConvertersRubric(unittest.TestCase):
repertoryAbbrev = glob_repertoryAbbrev
allRubricsFromFile = []
tableRemedy: list[converter.TableRowRemedy] = []
@classmethod
def setUpClass(cls):
cls.allRubricsFromFile = parser.getAllRubricsFromFileContents(completeInputFiles)
cls.tableRemedy = converter.getCompleteRemedyTable(cls.allRubricsFromFile, cls.repertoryAbbrev)
def test_getTable(self):
tableRubric = converter.getCompleteRubricTable(self.__class__.allRubricsFromFile, self.__class__.repertoryAbbrev)
print("#tableRubric: " + str(len(tableRubric)))
class ConvertersRubricRemedy(unittest.TestCase):
repertoryAbbrev = glob_repertoryAbbrev
allRubricsFromFile = []
tableRemedy: list[converter.TableRowRemedy] = []
tableRubric: list[converter.TableRowRubric] = []
@classmethod
def setUpClass(cls):
cls.allRubricsFromFile = parser.getAllRubricsFromFileContents(completeInputFiles)
cls.tableRemedy = converter.getCompleteRemedyTable(cls.allRubricsFromFile, cls.repertoryAbbrev)
cls.tableRubric = converter.getCompleteRubricTable(cls.allRubricsFromFile, cls.repertoryAbbrev)
def test_getTable(self):
tableRubricRemedy = converter.getCompleteRubricRemedyTable(self.__class__.tableRemedy, self.__class__.tableRubric, self.__class__.allRubricsFromFile)
print("#tableRubricRemedy: " + str(len(tableRubricRemedy)))
class Consistency(unittest.TestCase):
repertoryAbbrev = glob_repertoryAbbrev
allRubricsFromFile = []
tableRemedy: list[converter.TableRowRemedy] = []
tableRubric: list[converter.TableRowRubric] = []
@classmethod
def setUpClass(cls):
cls.allRubricsFromFile = parser.getAllRubricsFromFileContents(completeInputFiles)
cls.tableRemedy = converter.getCompleteRemedyTable(cls.allRubricsFromFile, cls.repertoryAbbrev)
cls.tableRubric = converter.getCompleteRubricTable(cls.allRubricsFromFile, cls.repertoryAbbrev)
def test_sameSizeAsRawData(self):
self.assertTrue(len(self.tableRubric) == len(self.allRubricsFromFile))
def test_samePathsAsRawData(self):
for i in range(0, len(self.allRubricsFromFile)):
self.assertTrue(self.allRubricsFromFile[i].text == self.tableRubric[i].path)
def test_extractedRemediesSameAsInRawData(self):
extractedRawRemedyAbbrevs = set()
for rubric in self.allRubricsFromFile:
extractedRawRemedyAbbrevs.update(map((lambda remedy: remedy.abbrev), rubric.remedies))
tableRemedies = list(map((lambda r: r.nameabbrev), self.tableRemedy))
for remedyAbbrev in extractedRawRemedyAbbrevs:
self.assertTrue(remedyAbbrev in tableRemedies)