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
|
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
|
+
-
-
+
+
+
+
+
+
-
+
-
-
-
+
+
+
+
|
zOption = re.compile("^__([a-zA-Z0-9]+)__ ")
spHere, _ = os.path.split(__file__)
spfParsingTest = os.path.join(spHere, "gc_test.txt")
if not os.path.exists(spfParsingTest):
print(f"No file <gc_test.txt> in <{spHere}>")
return
with open(spfParsingTest, "r", encoding="utf-8") as hSrc:
nUnexpectedErrors = 0
nError = 0
for sLine in ( s for s in hSrc if not s.startswith("#") and s.strip() ):
nTestWithExpectedError = 0
nTestWithExpectedErrorAndSugg = 0
for i, sLine in enumerate( s for s in hSrc if not s.startswith("#") and s.strip() ):
sLineNum = sLine[:10].strip()
sLine = sLine[10:].strip()
sOption = None
m = zOption.search(sLine)
if m:
sLine = sLine[m.end():]
sOption = m.group(1)
if "->>" in sLine:
sErrorText, sExceptedSuggs = self._splitTestLine(sLine)
nTestWithExpectedErrorAndSugg += 1
else:
sErrorText = sLine.strip()
sExceptedSuggs = ""
sExpectedErrors = self._getExpectedErrors(sErrorText)
if sExpectedErrors.strip() != "":
nTestWithExpectedError += 1
sTextToCheck = sErrorText.replace("}}", "").replace("{{", "")
sFoundErrors, sListErr, sFoundSuggs = self._getFoundErrors(sTextToCheck, sOption)
# tests
if sExpectedErrors != sFoundErrors:
print("\n# Line num: " + sLineNum + \
"\n> to check: " + _fuckBackslashUTF8(sTextToCheck) + \
"\n expected: " + sExpectedErrors + \
"\n found: " + sFoundErrors + \
"\n errors: \n" + sListErr)
nError += 1
nUnexpectedErrors += 1
elif sExceptedSuggs:
if sExceptedSuggs != sFoundSuggs:
print("\n# Line num: " + sLineNum + \
"\n> to check: " + _fuckBackslashUTF8(sTextToCheck) + \
"\n expected: " + sExceptedSuggs + \
"\n found: " + sFoundSuggs + \
"\n errors: \n" + sListErr)
nError += 1
if nError:
print("Unexpected errors:", nError)
nUnexpectedErrors += 1
print("Tests with expected errors:", nTestWithExpectedError, " and suggestions:", nTestWithExpectedErrorAndSugg, ":", str(nTestWithExpectedErrorAndSugg/nTestWithExpectedError*100), "%")
if nUnexpectedErrors:
print("Unexpected errors:", nUnexpectedErrors)
# untested rules
aUntestedRules = set()
for _, sOpt, sLineId, sRuleId in gc_engine.listRules():
sRuleId = sRuleId.rstrip("0123456789")
if sOpt != "@@@@" and sRuleId not in self._aTestedRules and not re.search("^[0-9]+[sp]$|^[pd]_", sRuleId):
aUntestedRules.add(f"{sLineId}/{sRuleId}")
if aUntestedRules:
|
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
-
+
|
aGramErrs = [ dMsgErr for dMsgErr in sorted(aGramErrs, key=lambda d: d["nStart"]) if self._zRuleEnd.sub("", dMsgErr["sRuleId"]) != self._zRuleEnd.sub("", dErr["sRuleId"]) ]
aSpellErrs = self._oSpellChecker.parseParagraph(re.sub("‹[^›]+›", lambda m: " " * len(m.group(0)), dErr["sMessage"]))
if aGramErrs or aSpellErrs or "<start>" in dErr["sMessage"] or "<end>" in dErr["sMessage"]:
print("\n# Error in: <" + dErr["sMessage"] + ">\n " + dErr["sLineId"] + " / " + dErr["sRuleId"])
for dMsgErr in aGramErrs:
print(" error: {sLineId} / {sRuleId} at {nStart}:{nEnd}".format(**dMsgErr))
for dMsgErr in aSpellErrs:
print(" spelling mistake: <{sValue}> at {nStart}:{nEnd}".format(**dMsgErr))
print(" spelling mistake: <{sValue}> at {nStart}:{nEnd}".format(**dMsgErr))
return sRes, sListErr, "|||".join(lAllSugg)
def _getExpectedErrors (self, sLine):
sRes = " " * len(sLine)
for i, m in enumerate(self._zError.finditer(sLine)):
nStart = m.start() - (4 * i)
nEnd = m.end() - (4 * (i+1))
|