# # It has been a long time since wrote Python tests. Oops. # # In a real version of this would probably write a bunch of # table driven tests with descriptions, but it's midnight so you # get basic functionality being confirmed. isn't narrowly # adhering to each test tests exactly one new behavior, either. import unittest import testresults class TestResultsType(unittest.TestCase): def test_single(self): "Test that a single case with two tests returns the right results" tr = testresults.TestResults() r = list(tr.appendTestRun([("ghi", "passed"), ("abc", "failed")])) # Our API contract is that within a single run, new test # names are sorted alphabetically. self.assertEqual(r, [("abc", "failed"), ("ghi", "passed")]) def test_repeat(self): "Test that repeatedly doing something works." tr = testresults.TestResults() r = list(tr.appendTestRun([("ghi", "passed"), ("abc", "failed")])) self.assertEqual(r, [("abc", "failed"), ("ghi", "passed")]) # If we repeat exactly the same tests we should get the same # results. r = list(tr.appendTestRun([("ghi", "passed"), ("abc", "failed")])) self.assertEqual(r, [("abc", "failed"), ("ghi", "passed")]) def test_state_change(self): "Test that a re-run test changes state in the second occurrence." tr = testresults.TestResults() r = list(tr.appendTestRun([("abc", "failed")])) self.assertEqual(r, [("abc", "failed")]) r = list(tr.appendTestRun([("abc", "passed")])) self.assertEqual(r, [("abc", "passed")]) def test_test_differents(self): "Test that adding a new test and omitting an old test works." tr = testresults.TestResults() _ = list(tr.appendTestRun([("ghi", "passed")])) r = list(tr.appendTestRun([("abc", "failed")])) # Across multiple runs, new test cases are not sorted alphabetically # against old ones, so "ghi" is first. self.assertEqual(r, [("ghi", None), ("abc", "failed")])