1 | n/a | import unittest |
---|
2 | n/a | import __future__ |
---|
3 | n/a | |
---|
4 | n/a | GOOD_SERIALS = ("alpha", "beta", "candidate", "final") |
---|
5 | n/a | |
---|
6 | n/a | features = __future__.all_feature_names |
---|
7 | n/a | |
---|
8 | n/a | class FutureTest(unittest.TestCase): |
---|
9 | n/a | |
---|
10 | n/a | def test_names(self): |
---|
11 | n/a | # Verify that all_feature_names appears correct. |
---|
12 | n/a | given_feature_names = features[:] |
---|
13 | n/a | for name in dir(__future__): |
---|
14 | n/a | obj = getattr(__future__, name, None) |
---|
15 | n/a | if obj is not None and isinstance(obj, __future__._Feature): |
---|
16 | n/a | self.assertTrue( |
---|
17 | n/a | name in given_feature_names, |
---|
18 | n/a | "%r should have been in all_feature_names" % name |
---|
19 | n/a | ) |
---|
20 | n/a | given_feature_names.remove(name) |
---|
21 | n/a | self.assertEqual(len(given_feature_names), 0, |
---|
22 | n/a | "all_feature_names has too much: %r" % given_feature_names) |
---|
23 | n/a | |
---|
24 | n/a | def test_attributes(self): |
---|
25 | n/a | for feature in features: |
---|
26 | n/a | value = getattr(__future__, feature) |
---|
27 | n/a | |
---|
28 | n/a | optional = value.getOptionalRelease() |
---|
29 | n/a | mandatory = value.getMandatoryRelease() |
---|
30 | n/a | |
---|
31 | n/a | a = self.assertTrue |
---|
32 | n/a | e = self.assertEqual |
---|
33 | n/a | def check(t, name): |
---|
34 | n/a | a(isinstance(t, tuple), "%s isn't tuple" % name) |
---|
35 | n/a | e(len(t), 5, "%s isn't 5-tuple" % name) |
---|
36 | n/a | (major, minor, micro, level, serial) = t |
---|
37 | n/a | a(isinstance(major, int), "%s major isn't int" % name) |
---|
38 | n/a | a(isinstance(minor, int), "%s minor isn't int" % name) |
---|
39 | n/a | a(isinstance(micro, int), "%s micro isn't int" % name) |
---|
40 | n/a | a(isinstance(level, str), |
---|
41 | n/a | "%s level isn't string" % name) |
---|
42 | n/a | a(level in GOOD_SERIALS, |
---|
43 | n/a | "%s level string has unknown value" % name) |
---|
44 | n/a | a(isinstance(serial, int), "%s serial isn't int" % name) |
---|
45 | n/a | |
---|
46 | n/a | check(optional, "optional") |
---|
47 | n/a | if mandatory is not None: |
---|
48 | n/a | check(mandatory, "mandatory") |
---|
49 | n/a | a(optional < mandatory, |
---|
50 | n/a | "optional not less than mandatory, and mandatory not None") |
---|
51 | n/a | |
---|
52 | n/a | a(hasattr(value, "compiler_flag"), |
---|
53 | n/a | "feature is missing a .compiler_flag attr") |
---|
54 | n/a | # Make sure the compile accepts the flag. |
---|
55 | n/a | compile("", "<test>", "exec", value.compiler_flag) |
---|
56 | n/a | a(isinstance(getattr(value, "compiler_flag"), int), |
---|
57 | n/a | ".compiler_flag isn't int") |
---|
58 | n/a | |
---|
59 | n/a | |
---|
60 | n/a | if __name__ == "__main__": |
---|
61 | n/a | unittest.main() |
---|