blob: 9ae4ce40ad47d84331cb759e605d52c328775495 [file] [log] [blame]
Benjamin Peterson90f5ba52010-03-11 22:53:45 +00001#! /usr/bin/env python3
Thomas Wouters89f507f2006-12-13 04:49:30 +00002import unittest
Benjamin Petersonee8712c2008-05-20 21:35:26 +00003from test import support
Tim Petersffc215a2001-02-26 21:14:49 +00004import __future__
5
6GOOD_SERIALS = ("alpha", "beta", "candidate", "final")
7
Tim Petersde642bd2001-08-17 19:49:02 +00008features = __future__.all_feature_names
Tim Petersaa320702001-08-18 20:18:49 +00009
Thomas Wouters89f507f2006-12-13 04:49:30 +000010class FutureTest(unittest.TestCase):
Tim Petersaa320702001-08-18 20:18:49 +000011
Thomas Wouters89f507f2006-12-13 04:49:30 +000012 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 Petersonc9c0f202009-06-30 23:06:06 +000018 self.assertTrue(
Thomas Wouters89f507f2006-12-13 04:49:30 +000019 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 Petersffc215a2001-02-26 21:14:49 +000025
Thomas Wouters89f507f2006-12-13 04:49:30 +000026 def test_attributes(self):
27 for feature in features:
28 value = getattr(__future__, feature)
Tim Petersffc215a2001-02-26 21:14:49 +000029
Thomas Wouters89f507f2006-12-13 04:49:30 +000030 optional = value.getOptionalRelease()
31 mandatory = value.getMandatoryRelease()
Tim Petersffc215a2001-02-26 21:14:49 +000032
Benjamin Petersonc9c0f202009-06-30 23:06:06 +000033 a = self.assertTrue
Thomas Wouters89f507f2006-12-13 04:49:30 +000034 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 Rossum3172c5d2007-10-16 18:12:55 +000042 a(isinstance(level, str),
Thomas Wouters89f507f2006-12-13 04:49:30 +000043 "%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 Petersde642bd2001-08-17 19:49:02 +000047
Thomas Wouters89f507f2006-12-13 04:49:30 +000048 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 Petersonbceae0c2009-07-02 21:55:39 +000056 # Make sure the compile accepts the flag.
57 compile("", "<test>", "exec", value.compiler_flag)
Thomas Wouters89f507f2006-12-13 04:49:30 +000058 a(isinstance(getattr(value, "compiler_flag"), int),
59 ".compiler_flag isn't int")
60
Benjamin Petersonbceae0c2009-07-02 21:55:39 +000061
Thomas Wouters89f507f2006-12-13 04:49:30 +000062def test_main():
Benjamin Petersonee8712c2008-05-20 21:35:26 +000063 support.run_unittest(FutureTest)
Thomas Wouters89f507f2006-12-13 04:49:30 +000064
65if __name__ == "__main__":
66 test_main()