Port test___future__ to unittest.

This commit is contained in:
Walter Dörwald 2006-10-22 08:59:41 +00:00
parent 8a7a9cf507
commit d3973b578f

View file

@ -1,59 +1,63 @@
#! /usr/bin/env python #! /usr/bin/env python
from test.test_support import verbose, verify import unittest
from types import TupleType, StringType, IntType from test import test_support
import __future__ import __future__
GOOD_SERIALS = ("alpha", "beta", "candidate", "final") GOOD_SERIALS = ("alpha", "beta", "candidate", "final")
features = __future__.all_feature_names features = __future__.all_feature_names
# Verify that all_feature_names appears correct. class FutureTest(unittest.TestCase):
given_feature_names = features[:]
for name in dir(__future__):
obj = getattr(__future__, name, None)
if obj is not None and isinstance(obj, __future__._Feature):
verify(name in given_feature_names,
"%r should have been in all_feature_names" % name)
given_feature_names.remove(name)
verify(len(given_feature_names) == 0,
"all_feature_names has too much: %r" % given_feature_names)
del given_feature_names
for feature in features: def test_names(self):
value = getattr(__future__, feature) # Verify that all_feature_names appears correct.
if verbose: given_feature_names = features[:]
print "Checking __future__ ", feature, "value", value for name in dir(__future__):
obj = getattr(__future__, name, None)
if obj is not None and isinstance(obj, __future__._Feature):
self.assert_(
name in given_feature_names,
"%r should have been in all_feature_names" % name
)
given_feature_names.remove(name)
self.assertEqual(len(given_feature_names), 0,
"all_feature_names has too much: %r" % given_feature_names)
optional = value.getOptionalRelease() def test_attributes(self):
mandatory = value.getMandatoryRelease() for feature in features:
value = getattr(__future__, feature)
verify(type(optional) is TupleType, "optional isn't tuple") optional = value.getOptionalRelease()
verify(len(optional) == 5, "optional isn't 5-tuple") mandatory = value.getMandatoryRelease()
major, minor, micro, level, serial = optional
verify(type(major) is IntType, "optional major isn't int")
verify(type(minor) is IntType, "optional minor isn't int")
verify(type(micro) is IntType, "optional micro isn't int")
verify(isinstance(level, basestring), "optional level isn't string")
verify(level in GOOD_SERIALS,
"optional level string has unknown value")
verify(type(serial) is IntType, "optional serial isn't int")
verify(type(mandatory) is TupleType or a = self.assert_
mandatory is None, "mandatory isn't tuple or None") e = self.assertEqual
if mandatory is not None: def check(t, name):
verify(len(mandatory) == 5, "mandatory isn't 5-tuple") a(isinstance(t, tuple), "%s isn't tuple" % name)
major, minor, micro, level, serial = mandatory e(len(t), 5, "%s isn't 5-tuple" % name)
verify(type(major) is IntType, "mandatory major isn't int") (major, minor, micro, level, serial) = t
verify(type(minor) is IntType, "mandatory minor isn't int") a(isinstance(major, int), "%s major isn't int" % name)
verify(type(micro) is IntType, "mandatory micro isn't int") a(isinstance(minor, int), "%s minor isn't int" % name)
verify(isinstance(level, basestring), "mandatory level isn't string") a(isinstance(micro, int), "%s micro isn't int" % name)
verify(level in GOOD_SERIALS, a(isinstance(level, basestring),
"mandatory serial string has unknown value") "%s level isn't string" % name)
verify(type(serial) is IntType, "mandatory serial isn't int") a(level in GOOD_SERIALS,
verify(optional < mandatory, "%s level string has unknown value" % name)
"optional not less than mandatory, and mandatory not None") a(isinstance(serial, int), "%s serial isn't int" % name)
verify(hasattr(value, "compiler_flag"), check(optional, "optional")
"feature is missing a .compiler_flag attr") if mandatory is not None:
verify(type(getattr(value, "compiler_flag")) is IntType, check(mandatory, "mandatory")
".compiler_flag isn't int") a(optional < mandatory,
"optional not less than mandatory, and mandatory not None")
a(hasattr(value, "compiler_flag"),
"feature is missing a .compiler_flag attr")
a(isinstance(getattr(value, "compiler_flag"), int),
".compiler_flag isn't int")
def test_main():
test_support.run_unittest(FutureTest)
if __name__ == "__main__":
test_main()