Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 1 | import unittest |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 2 | from test import support |
Tim Peters | ffc215a | 2001-02-26 21:14:49 +0000 | [diff] [blame] | 3 | import __future__ |
| 4 | |
| 5 | GOOD_SERIALS = ("alpha", "beta", "candidate", "final") |
| 6 | |
Tim Peters | de642bd | 2001-08-17 19:49:02 +0000 | [diff] [blame] | 7 | features = __future__.all_feature_names |
Tim Peters | aa32070 | 2001-08-18 20:18:49 +0000 | [diff] [blame] | 8 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 9 | class FutureTest(unittest.TestCase): |
Tim Peters | aa32070 | 2001-08-18 20:18:49 +0000 | [diff] [blame] | 10 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 11 | def test_names(self): |
| 12 | # Verify that all_feature_names appears correct. |
| 13 | given_feature_names = features[:] |
| 14 | for name in dir(__future__): |
| 15 | obj = getattr(__future__, name, None) |
| 16 | if obj is not None and isinstance(obj, __future__._Feature): |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 17 | self.assertTrue( |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 18 | name in given_feature_names, |
| 19 | "%r should have been in all_feature_names" % name |
| 20 | ) |
| 21 | given_feature_names.remove(name) |
| 22 | self.assertEqual(len(given_feature_names), 0, |
| 23 | "all_feature_names has too much: %r" % given_feature_names) |
Tim Peters | ffc215a | 2001-02-26 21:14:49 +0000 | [diff] [blame] | 24 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 25 | def test_attributes(self): |
| 26 | for feature in features: |
| 27 | value = getattr(__future__, feature) |
Tim Peters | ffc215a | 2001-02-26 21:14:49 +0000 | [diff] [blame] | 28 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 29 | optional = value.getOptionalRelease() |
| 30 | mandatory = value.getMandatoryRelease() |
Tim Peters | ffc215a | 2001-02-26 21:14:49 +0000 | [diff] [blame] | 31 | |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 32 | a = self.assertTrue |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 33 | e = self.assertEqual |
| 34 | def check(t, name): |
| 35 | a(isinstance(t, tuple), "%s isn't tuple" % name) |
| 36 | e(len(t), 5, "%s isn't 5-tuple" % name) |
| 37 | (major, minor, micro, level, serial) = t |
| 38 | a(isinstance(major, int), "%s major isn't int" % name) |
| 39 | a(isinstance(minor, int), "%s minor isn't int" % name) |
| 40 | a(isinstance(micro, int), "%s micro isn't int" % name) |
Guido van Rossum | 3172c5d | 2007-10-16 18:12:55 +0000 | [diff] [blame] | 41 | a(isinstance(level, str), |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 42 | "%s level isn't string" % name) |
| 43 | a(level in GOOD_SERIALS, |
| 44 | "%s level string has unknown value" % name) |
| 45 | a(isinstance(serial, int), "%s serial isn't int" % name) |
Tim Peters | de642bd | 2001-08-17 19:49:02 +0000 | [diff] [blame] | 46 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 47 | check(optional, "optional") |
| 48 | if mandatory is not None: |
| 49 | check(mandatory, "mandatory") |
| 50 | a(optional < mandatory, |
| 51 | "optional not less than mandatory, and mandatory not None") |
| 52 | |
| 53 | a(hasattr(value, "compiler_flag"), |
| 54 | "feature is missing a .compiler_flag attr") |
Benjamin Peterson | bceae0c | 2009-07-02 21:55:39 +0000 | [diff] [blame] | 55 | # Make sure the compile accepts the flag. |
| 56 | compile("", "<test>", "exec", value.compiler_flag) |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 57 | a(isinstance(getattr(value, "compiler_flag"), int), |
| 58 | ".compiler_flag isn't int") |
| 59 | |
Benjamin Peterson | bceae0c | 2009-07-02 21:55:39 +0000 | [diff] [blame] | 60 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 61 | def test_main(): |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 62 | support.run_unittest(FutureTest) |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 63 | |
| 64 | if __name__ == "__main__": |
| 65 | test_main() |