Mercurial > p > roundup > code
comparison test/test_misc.py @ 6654:5986ddd0d2e7
Check version_check.
Version check should also exclude 3.0-3.5 or there abouts, so get code
coverage first.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Mon, 02 May 2022 14:46:29 -0400 |
| parents | 3b945aee0919 |
| children | 3129d73e8535 |
comparison
equal
deleted
inserted
replaced
| 6653:7545d3a3a307 | 6654:5986ddd0d2e7 |
|---|---|
| 1 # misc tests | 1 # misc tests |
| 2 | 2 |
| 3 import unittest | 3 import unittest |
| 4 import roundup.anypy.cmp_ | 4 import roundup.anypy.cmp_ |
| 5 import sys | |
| 6 from roundup.anypy.strings import StringIO # define StringIO | |
| 5 from roundup.cgi.accept_language import parse | 7 from roundup.cgi.accept_language import parse |
| 6 | 8 |
| 7 class AcceptLanguageTest(unittest.TestCase): | 9 class AcceptLanguageTest(unittest.TestCase): |
| 8 def testParse(self): | 10 def testParse(self): |
| 9 self.assertEqual(parse("da, en-gb;q=0.8, en;q=0.7"), | 11 self.assertEqual(parse("da, en-gb;q=0.8, en;q=0.7"), |
| 28 self.assertEqual(parse("en,"), ['en']) | 30 self.assertEqual(parse("en,"), ['en']) |
| 29 | 31 |
| 30 class CmpTest(unittest.TestCase): | 32 class CmpTest(unittest.TestCase): |
| 31 def testCmp(self): | 33 def testCmp(self): |
| 32 roundup.anypy.cmp_._test() | 34 roundup.anypy.cmp_._test() |
| 35 | |
| 36 class VersionCheck(unittest.TestCase): | |
| 37 def test_Version_Check(self): | |
| 38 | |
| 39 # test for valid versions | |
| 40 from roundup.version_check import VERSION_NEEDED | |
| 41 self.assertEqual((2, 7), VERSION_NEEDED) | |
| 42 del(sys.modules['roundup.version_check']) | |
| 43 | |
| 44 | |
| 45 # fake an invalid version | |
| 46 real_ver = sys.version_info | |
| 47 sys.version_info = (2, 1) | |
| 48 | |
| 49 # exit is called on failure, but that breaks testing so | |
| 50 # just return and discard the exit code. | |
| 51 real_exit = sys.exit | |
| 52 sys.exit = lambda code: code | |
| 53 | |
| 54 # error case uses print(), capture and check | |
| 55 capturedOutput = StringIO() | |
| 56 sys.stdout = capturedOutput | |
| 57 from roundup.version_check import VERSION_NEEDED | |
| 58 sys.stdout = sys.__stdout__ | |
| 59 self.assertIn("Roundup requires Python 2.7", capturedOutput.getvalue()) | |
| 60 | |
| 61 # reset to valid values for future tests | |
| 62 sys.exit = real_exit | |
| 63 sys.version_info = real_ver | |
| 64 | |
| 65 |
