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