def checkBadInput(self): badInputFilePath = os.path.join(common.getTestsPath(), u"{}.bad".format(self.path)) for line in self.iterFileLines(badInputFilePath): if self.passes(line): common.error(u"O corrector aceptou «{}».".format(line)) common.details(self.analyze(line)) self.errors += 1
def loadTestList(): tests = [] testsPath = common.getTestsPath() for jsonFilePath in findJsonFilePaths(testsPath): testPath = common.getFirstPathRelativeToSecondPathIfWithin(jsonFilePath[:-5], testsPath) tests.append(SpellingTest(testPath)) return tests
def loadTestList(): tests = [] testsPath = common.getTestsPath() for jsonFilePath in findJsonFilePaths(testsPath): testPath = common.getFirstPathRelativeToSecondPathIfWithin( jsonFilePath[:-5], testsPath) tests.append(SpellingTest(testPath)) return tests
def checkGoodInput(self): goodInputFilePath = os.path.join(common.getTestsPath(), u"{}.good".format(self.path)) for line in self.iterFileLines(goodInputFilePath): if not self.passes(line): common.error(u"O corrector non aceptou «{}».".format(line)) details = self.analyze(line) common.details(details) self.errors += 1
def config(self): if self._config is None: import json try: with codecs.open(os.path.join(common.getTestsPath(), self.path + u".json"), "r", "utf-8") as fileObject: self._config = json.load(fileObject) except ValueError: self._config = {} defaultModules = ["rag/gl", "norma"] if "aff" not in self._config: self._config["aff"] = defaultModules if "dic" not in self._config: self._config["dic"] = defaultModules if "rep" not in self._config: self._config["rep"] = defaultModules return self._config
def config(self): if self._config is None: import json try: with codecs.open( os.path.join(common.getTestsPath(), self.path + u".json"), "r", "utf-8") as fileObject: self._config = json.load(fileObject) except ValueError: self._config = {} defaultModules = ["rag/gl", "norma"] if "aff" not in self._config: self._config["aff"] = defaultModules if "dic" not in self._config: self._config["dic"] = defaultModules if "rep" not in self._config: self._config["rep"] = defaultModules return self._config
import os, sys import codecs, locale import common, spellchecker, spelling, syntax # See http://stackoverflow.com/a/4546129/939364 sys.stdout = codecs.getwriter(locale.getpreferredencoding())(sys.stdout) def loadBuiltInTestList(): builtInTests = [] builtInTests.extend(spelling.loadTestList()) builtInTests.extend(syntax.loadTestList()) return builtInTests # Program starts. testsPath = common.getTestsPath() builtInTests = loadBuiltInTestList() with spellchecker.Manager() as spellCheckerManager: for parameter in [parameter.decode('UTF-8') for parameter in sys.argv[1:]]: testPath = common.getFirstPathRelativeToSecondPathIfWithin(parameter, testsPath) executedTests = 0 for test in builtInTests: if test.path.startswith(testPath): print u":: Executando «{path}»…".format(path=test.path) test.run(spellCheckerManager) executedTests += 1 if executedTests == 0: print u":: Non existe ningunha proba para «{path}».".format(path=testPath)