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