OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # |
| 3 # Copyright 2012 Google Inc. |
| 4 # |
| 5 # Permission is hereby granted, free of charge, to any person obtaining a |
| 6 # copy of this software and associated documentation files (the |
| 7 # "Software"), to deal in the Software without restriction, including |
| 8 # without limitation the rights to use, copy, modify, merge, publish, dis- |
| 9 # tribute, sublicense, and/or sell copies of the Software, and to permit |
| 10 # persons to whom the Software is furnished to do so, subject to the fol- |
| 11 # lowing conditions: |
| 12 # |
| 13 # The above copyright notice and this permission notice shall be included |
| 14 # in all copies or substantial portions of the Software. |
| 15 # |
| 16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 17 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- |
| 18 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT |
| 19 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 20 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 22 # IN THE SOFTWARE. |
| 23 |
| 24 """Unit tests for PluralityCheckableIterator""" |
| 25 |
| 26 import unittest |
| 27 |
| 28 from plurality_checkable_iterator import PluralityCheckableIterator |
| 29 |
| 30 class PluralityCheckableIteratorTests(unittest.TestCase): |
| 31 |
| 32 def GetSuiteDescription(self): |
| 33 return 'Unit tests for PluralityCheckableIterator' |
| 34 |
| 35 @classmethod |
| 36 def SetUpClass(cls): |
| 37 """Creates class level artifacts useful to multiple tests.""" |
| 38 pass |
| 39 |
| 40 @classmethod |
| 41 def TearDownClass(cls): |
| 42 """Cleans up any artifacts created by SetUpClass.""" |
| 43 pass |
| 44 |
| 45 def TestPluralityCheckableIteratorWith0Elems(self): |
| 46 """Tests empty PluralityCheckableIterator.""" |
| 47 input_list = range(0) |
| 48 it = iter(input_list) |
| 49 pcit = PluralityCheckableIterator(it) |
| 50 self.assertTrue(pcit.is_empty()) |
| 51 self.assertFalse(pcit.has_plurality()) |
| 52 output_list = list(pcit) |
| 53 self.assertEqual(input_list, output_list) |
| 54 |
| 55 def TestPluralityCheckableIteratorWith1Elem(self): |
| 56 """Tests PluralityCheckableIterator with 1 element.""" |
| 57 input_list = range(1) |
| 58 it = iter(input_list) |
| 59 pcit = PluralityCheckableIterator(it) |
| 60 self.assertFalse(pcit.is_empty()) |
| 61 self.assertFalse(pcit.has_plurality()) |
| 62 output_list = list(pcit) |
| 63 self.assertEqual(input_list, output_list) |
| 64 |
| 65 def TestPluralityCheckableIteratorWith2Elems(self): |
| 66 """Tests PluralityCheckableIterator with 2 elements.""" |
| 67 input_list = range(2) |
| 68 it = iter(input_list) |
| 69 pcit = PluralityCheckableIterator(it) |
| 70 self.assertFalse(pcit.is_empty()) |
| 71 self.assertTrue(pcit.has_plurality()) |
| 72 output_list = list(pcit) |
| 73 self.assertEqual(input_list, output_list) |
| 74 |
| 75 def TestPluralityCheckableIteratorWith3Elems(self): |
| 76 """Tests PluralityCheckableIterator with 3 elements.""" |
| 77 input_list = range(3) |
| 78 it = iter(input_list) |
| 79 pcit = PluralityCheckableIterator(it) |
| 80 self.assertFalse(pcit.is_empty()) |
| 81 self.assertTrue(pcit.has_plurality()) |
| 82 output_list = list(pcit) |
| 83 self.assertEqual(input_list, output_list) |
| 84 |
| 85 if __name__ == '__main__': |
| 86 test_loader = unittest.TestLoader() |
| 87 test_loader.testMethodPrefix = 'Test' |
| 88 suite = test_loader.loadTestsFromTestCase(PluralityCheckableIteratorTests) |
| 89 # Seems like there should be a cleaner way to find the test_class. |
| 90 test_class = suite.__getattribute__('_tests')[0] |
| 91 # We call SetUpClass() and TearDownClass() ourselves because we |
| 92 # don't assume the user has Python 2.7 (which supports classmethods |
| 93 # that do it, with camelCase versions of these names). |
| 94 try: |
| 95 print 'Setting up %s...' % test_class.GetSuiteDescription() |
| 96 test_class.SetUpClass() |
| 97 print 'Running %s...' % test_class.GetSuiteDescription() |
| 98 unittest.TextTestRunner(verbosity=2).run(suite) |
| 99 finally: |
| 100 print 'Cleaning up after %s...' % test_class.GetSuiteDescription() |
| 101 test_class.TearDownClass() |
| 102 print '' |
OLD | NEW |