blob: 559a1873adddc9f31143d53bca1f4be8c867d7fc [file] [log] [blame]
Thomas Wouters89f507f2006-12-13 04:49:30 +00001import unittest
Tim Petersffc215a2001-02-26 21:14:49 +00002import __future__
3
4GOOD_SERIALS = ("alpha", "beta", "candidate", "final")
5
Tim Petersde642bd2001-08-17 19:49:02 +00006features = __future__.all_feature_names
Tim Petersaa320702001-08-18 20:18:49 +00007
Thomas Wouters89f507f2006-12-13 04:49:30 +00008class FutureTest(unittest.TestCase):
Tim Petersaa320702001-08-18 20:18:49 +00009
Thomas Wouters89f507f2006-12-13 04:49:30 +000010 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 Petersonc9c0f202009-06-30 23:06:06 +000016 self.assertTrue(
Thomas Wouters89f507f2006-12-13 04:49:30 +000017 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 Petersffc215a2001-02-26 21:14:49 +000023
Thomas Wouters89f507f2006-12-13 04:49:30 +000024 def test_attributes(self):
25 for feature in features:
26 value = getattr(__future__, feature)
Tim Petersffc215a2001-02-26 21:14:49 +000027
Thomas Wouters89f507f2006-12-13 04:49:30 +000028 optional = value.getOptionalRelease()
29 mandatory = value.getMandatoryRelease()
Tim Petersffc215a2001-02-26 21:14:49 +000030
Benjamin Petersonc9c0f202009-06-30 23:06:06 +000031 a = self.assertTrue
Thomas Wouters89f507f2006-12-13 04:49:30 +000032 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 Rossum3172c5d2007-10-16 18:12:55 +000040 a(isinstance(level, str),
Thomas Wouters89f507f2006-12-13 04:49:30 +000041 "%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 Petersde642bd2001-08-17 19:49:02 +000045
Thomas Wouters89f507f2006-12-13 04:49:30 +000046 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 Petersonbceae0c2009-07-02 21:55:39 +000054 # Make sure the compile accepts the flag.
55 compile("", "<test>", "exec", value.compiler_flag)
Thomas Wouters89f507f2006-12-13 04:49:30 +000056 a(isinstance(getattr(value, "compiler_flag"), int),
57 ".compiler_flag isn't int")
58
Benjamin Petersonbceae0c2009-07-02 21:55:39 +000059
Thomas Wouters89f507f2006-12-13 04:49:30 +000060if __name__ == "__main__":
Zachary Ware38c707e2015-04-13 15:00:43 -050061 unittest.main()