Ejemplo n.º 1
0
def runTests(fileName):
    redirects = {}
    articleTitles = {}
    testCount = 0
    failedCount = 0
    for test in iterTests(fileName):
        orig = test.orig
        expected = test.expected
        converted = articleconvert.convertArticle(test.name, orig)
        expected = arsutils.normalizeNewlines(expected)
        converted = arsutils.normalizeNewlines(converted)
        if converted != expected:
            failedCount += 1
            test.setConverted(converted)
            failedList.append(test)
            sys.stdout.write("-")
        else:
            sys.stdout.write(".")
        noLinks = articleconvert.removeInvalidLinks(converted, redirects,
                                                    articleTitles)
        testCount += 1
    print
    print "Total  tests: %d" % testCount
    print "Failed tests: %d" % failedCount
    dumpFailed()
    diffFirstFailed()
Ejemplo n.º 2
0
def runTests(fileName):
    redirects = {}
    articleTitles = {}
    testCount = 0
    failedCount = 0
    for test in iterTests(fileName):
        orig = test.orig
        expected = test.expected
        converted = articleconvert.convertArticle(test.name,orig)
        expected  = arsutils.normalizeNewlines(expected)
        converted = arsutils.normalizeNewlines(converted)
        if converted != expected:
            failedCount += 1
            test.setConverted(converted)
            failedList.append(test)
            sys.stdout.write("-")
        else:
            sys.stdout.write(".")
        noLinks = articleconvert.removeInvalidLinks(converted,redirects,articleTitles)
        testCount += 1
    print
    print "Total  tests: %d" % testCount
    print "Failed tests: %d" % failedCount
    dumpFailed()
    diffFirstFailed()
Ejemplo n.º 3
0
def showDiffRandom(fileName):
    # at this point shows the diff of the first article
    article = getRandomArticle(fileName)
    title = article.getTitle()
    convertedArticle = None
    if wikipediasql.fConvertedCacheExists(fileName):
        convertedArticle = findConvertedArticle(fileName,title)

    if not convertedArticle:
        print "didn't find article '%s' in the converted cache" % title
    origTxt = article.getText()
    origTxt = arsutils.normalizeNewlines(origTxt)
    if convertedArticle:
        converted = arsutils.normalizeNewlines(convertedArticle.getText())
        arsutils.showTxtDiff(origTxt, converted)
    else:
        converted = articleconvert.convertArticle(article.getTitle(), article.getText())
        converted = arsutils.normalizeNewlines(converted)
        arsutils.showTxtDiff(origTxt,converted)
Ejemplo n.º 4
0
def showDiffRandom(fileName):
    # at this point shows the diff of the first article
    article = getRandomArticle(fileName)
    title = article.getTitle()
    convertedArticle = None
    if wikipediasql.fConvertedCacheExists(fileName):
        convertedArticle = findConvertedArticle(fileName, title)

    if not convertedArticle:
        print "didn't find article '%s' in the converted cache" % title
    origTxt = article.getText()
    origTxt = arsutils.normalizeNewlines(origTxt)
    if convertedArticle:
        converted = arsutils.normalizeNewlines(convertedArticle.getText())
        arsutils.showTxtDiff(origTxt, converted)
    else:
        converted = articleconvert.convertArticle(article.getTitle(),
                                                  article.getText())
        converted = arsutils.normalizeNewlines(converted)
        arsutils.showTxtDiff(origTxt, converted)
Ejemplo n.º 5
0
def showDiffTitle(fileName, title, fSave=False, fForceConvert=False):
    article = findOrigArticle(fileName, title)
    if not article:
        print "couldn't find article with the title %s" % title
        return
    origTxt = article.getText()
    origTxt = arsutils.normalizeNewlines(origTxt)

    if fForceConvert:
        convertedTxt = articleconvert.convertArticle(article.getTitle(),
                                                     article.getText())
    else:
        title = article.getTitle(
        )  # re-get the title in case this was a redirect
        convertedArticle = None
        if wikipediasql.fConvertedCacheExists(fileName):
            convertedArticle = findConvertedArticle(fileName, title)
        else:
            print "Converted cache for '%s' doesn't exist" % fileName
            sys.exit(0)

        if None == convertedArticle:
            print "didn't find converted article, generating it myself"
            convertedTxt = articleconvert.convertArticle(
                article.getTitle(), article.getText())
        else:
            convertedTxt = convertedArticle.getText()

    convertedTxt = arsutils.normalizeNewlines(convertedTxt)
    if fSave:
        title = article.getTitle()
        title = title.replace(" ", "_")
        fo = open("%s_orig.txt" % title, "wb")
        fo.write(origTxt)
        fo.close()
        fo = open("%s_conv.txt" % title, "wb")
        fo.write(convertedTxt)
        fo.close()
    arsutils.showTxtDiff(origTxt, convertedTxt)
Ejemplo n.º 6
0
def showDiffTitle(fileName,title,fSave=False,fForceConvert=False):
    article = findOrigArticle(fileName,title)
    if not article:
        print "couldn't find article with the title %s" % title
        return
    origTxt = article.getText()
    origTxt = arsutils.normalizeNewlines(origTxt)

    if fForceConvert:
        convertedTxt = articleconvert.convertArticle(article.getTitle(), article.getText())
    else:
        title = article.getTitle() # re-get the title in case this was a redirect
        convertedArticle = None
        if wikipediasql.fConvertedCacheExists(fileName):
            convertedArticle = findConvertedArticle(fileName,title)
        else:
            print "Converted cache for '%s' doesn't exist" % fileName
            sys.exit(0)

        if None == convertedArticle:
            print "didn't find converted article, generating it myself"
            convertedTxt = articleconvert.convertArticle(article.getTitle(), article.getText())
        else:
            convertedTxt = convertedArticle.getText()

    convertedTxt = arsutils.normalizeNewlines(convertedTxt)
    if fSave:
        title = article.getTitle()
        title = title.replace(" ", "_")
        fo = open("%s_orig.txt" % title, "wb")
        fo.write(origTxt)
        fo.close()
        fo = open("%s_conv.txt" % title, "wb")
        fo.write(convertedTxt)
        fo.close()
    arsutils.showTxtDiff(origTxt, convertedTxt)