Skip to content

Commit

Permalink
more readable output from tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Håkon Bogen committed Aug 5, 2014
1 parent 8651bb5 commit 123f607
Showing 1 changed file with 52 additions and 3 deletions.
55 changes: 52 additions & 3 deletions tests.py
Expand Up @@ -4,7 +4,8 @@

import format


#from difflib_data import *
import sys
o = []


Expand All @@ -20,6 +21,43 @@ def stringsAreEqual(self,a,b,fileName):
try:
self.assertEqual(a,b)
print("TEST OK for " + fileName)
except AssertionError:
d = difflib.Differ()
lineNum = 0
diffs = difflib.context_diff(a, b,n=14)
print("TEST failed for " + fileName)

#print '\n'.join(diffs)
for line in diffs:
line = line.strip(" ")
sys.stdout.write(line)
print(" ")
#for line in diffs:
# split off the code
#code = line[:2]
#if the line is in both files or just b, increment the line number.
# if code in (" ", "+ "):
# lineNum += 1
# if this line is only in b, print the line number and the text on the line
# if code == "+ ":
# print "%d: %s" % (lineNum, line[2:].strip())
#for char in result:
# char = char + " "
# if "+" in char:
# print("added " + char)
# elif "-" in char:
# print("removed " + char)
print("####### Tried to format the code from " + fileName + " #########")
print(a.replace(" ","_"))
print("####### It did not match what the file said was correct formatting: #########")
print(b.replace(" ","_"))
print("#######END")
lineNum = 0

def stringsAreNotEqual(self,a,b,fileName):
try:
self.assertNotEqual(a,b)
print("should not be equal-test OK for " + fileName)
except AssertionError:
d = difflib.Differ()
result = list(d.compare(a, b))
Expand All @@ -31,7 +69,7 @@ def stringsAreEqual(self,a,b,fileName):
print("removed " + char)
print("####### Tried to format the code from " + fileName + " #########")
print(a.replace(" ","_"))
print("####### It did not match what the file said was correct formatting: #########")
print("####### It should not match: #########")
print(b.replace(" ","_"))
print("#######END")
#print('{} => {}'.format(a,b))
Expand Down Expand Up @@ -67,7 +105,18 @@ def testSpaces(self):
fileReader = format.FileReader(file)
testCases = fileReader.compareTestCasesInReadFile()
self.stringsAreEqual(testCases[0],testCases[1],fileName)

def testFailingTests(self):
for fileName in self.pathForInTestCaseSubFolder("shouldFail"):
file = open(os.path.abspath(fileName), "r")
fileReader = format.FileReader(file)
testCases = fileReader.compareTestCasesInReadFile()
self.stringsAreNotEqual(testCases[0],testCases[1],fileName)
def testClosures(self):
for fileName in self.pathForInTestCaseSubFolder("closures"):
file = open(os.path.abspath(fileName), "r")
fileReader = format.FileReader(file)
testCases = fileReader.compareTestCasesInReadFile()
self.stringsAreEqual(testCases[0],testCases[1],fileName)
#def testIndentation2(self):
# file = open("SwiftFormatter/indentTest.test", "r")
# fileReader = reader.FileReader(file)
Expand Down

0 comments on commit 123f607

Please sign in to comment.