Python Unit Test subtle bug
<p>I'm new to Python and I've read the unit test documentation for python and I'm doing something different from the examples provided. I'm comparing sets. I don't know why my code keeps getting a failure. It seems like the code is written correctly. Can someone take a gander and see if they can resolve the problem? I will be eternally greatful!!</p>

<p>I'm trying to get better at unit testing so that's why I'm working this code out. </p>

<pre><code>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()
</code></pre>

<p>When I disable the "offending code piece" that is the asserts for the set comparison, the code behaves correctly but when I enable the code I get the following output: </p>

<pre><code>python UnitTester.py
  File "UnitTester.py", line 39
    if __name__ == '__main__':
                             ^
SyntaxError: invalid syntax
</code></pre>

<p>Any ideas greatly appreciated! Thanks. </p>

<p>You're simply missing a parentheses at the end of </p>

<pre><code>self.assertSetEqual(results['intersection'], set(["a"])
</code></pre>

<p>This confuses the interpreter. Change it to</p>

<pre><code>self.assertSetEqual(results['intersection'], set(["a"]))
</code></pre>

<p>In general, you might try to find an editor (or editor settings) that match parentheses, or warn about unmatched parentheses.</p>

python unit-testing