저는 Python을 처음 접했고 Python 용 유닛 테스트 문서를 읽었으며 제공된 예제와 다른 것을하고 있습니다. 나는 세트를 비교하고있다. 나는 왜 내 코드가 계속 실패 하는지를 모른다. 코드가 올바르게 작성된 것 같습니다. 누군가가 방황을해서 문제를 해결할 수 있는지 알아볼 수 있습니까? 나는 영원히 위대 할 것이다 !!Python Unit Test 미묘한 버그
나는 단위 테스트를 더 잘하기 위해 노력하고 있으므로이 코드를 작업하고 있습니다.
import unittest
def determineIntersections(listingData, carList):
listingDataKeys = []
for key in listingData:
listingDataKeys.append(key)
carListKeys = []
for car in carList:
carListKeys.append(car[0])
intersection = set(carListKeys).intersection(set(listingDataKeys))
difference = set(carListKeys).symmetric_difference(set(listingDataKeys))
resultList = {'intersection' : intersection,
'difference' : difference}
return resultList
class TestHarness(unittest.TestCase):
def test_determineIntersections(self):
listingData = {"a": "", "b": "", "c": "", "d": ""}
carList = {"a": "", "e": "", "f": ""}
results = determineIntersections(listingData, carList)
print results['intersection']
print results['difference']
self.assertEqual(len(results['intersection']), 1)
self.assertSetEqual(results['intersection'], set(["a"]) # offending code piece
self.assertEqual(results['difference'], set(["b", "c", "d", "e", "f"])) # offending code piece
if __name__ == '__main__':
unittest.main()
나는 코드가 제대로 작동 단,이 설정 비교를 위해 주장 인 "잘못된 코드 조각을"사용하지 않으면 나는 다음과 같은 출력 얻을 코드를 사용할 때 :
python UnitTester.py
File "UnitTester.py", line 39
if __name__ == '__main__':
^
SyntaxError: invalid syntax
어떤 아이디어 대단히 감사합니다! 감사.
줄 끝에 괄호가 누락되었습니다. –