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