ยปCore Development>Code coverage>Lib/test/test___future__.py

Python code coverage for Lib/test/test___future__.py

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