mirror of
https://github.com/python/cpython.git
synced 2025-09-15 13:16:12 +00:00
Port test___future__ to unittest.
This commit is contained in:
parent
8a7a9cf507
commit
d3973b578f
1 changed files with 51 additions and 47 deletions
|
@ -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__):
|
def test_names(self):
|
||||||
|
# Verify that all_feature_names appears correct.
|
||||||
|
given_feature_names = features[:]
|
||||||
|
for name in dir(__future__):
|
||||||
obj = getattr(__future__, name, None)
|
obj = getattr(__future__, name, None)
|
||||||
if obj is not None and isinstance(obj, __future__._Feature):
|
if obj is not None and isinstance(obj, __future__._Feature):
|
||||||
verify(name in given_feature_names,
|
self.assert_(
|
||||||
"%r should have been in all_feature_names" % name)
|
name in given_feature_names,
|
||||||
|
"%r should have been in all_feature_names" % name
|
||||||
|
)
|
||||||
given_feature_names.remove(name)
|
given_feature_names.remove(name)
|
||||||
verify(len(given_feature_names) == 0,
|
self.assertEqual(len(given_feature_names), 0,
|
||||||
"all_feature_names has too much: %r" % given_feature_names)
|
"all_feature_names has too much: %r" % given_feature_names)
|
||||||
del given_feature_names
|
|
||||||
|
|
||||||
for feature in features:
|
def test_attributes(self):
|
||||||
|
for feature in features:
|
||||||
value = getattr(__future__, feature)
|
value = getattr(__future__, feature)
|
||||||
if verbose:
|
|
||||||
print "Checking __future__ ", feature, "value", value
|
|
||||||
|
|
||||||
optional = value.getOptionalRelease()
|
optional = value.getOptionalRelease()
|
||||||
mandatory = value.getMandatoryRelease()
|
mandatory = value.getMandatoryRelease()
|
||||||
|
|
||||||
verify(type(optional) is TupleType, "optional isn't tuple")
|
a = self.assert_
|
||||||
verify(len(optional) == 5, "optional isn't 5-tuple")
|
e = self.assertEqual
|
||||||
major, minor, micro, level, serial = optional
|
def check(t, name):
|
||||||
verify(type(major) is IntType, "optional major isn't int")
|
a(isinstance(t, tuple), "%s isn't tuple" % name)
|
||||||
verify(type(minor) is IntType, "optional minor isn't int")
|
e(len(t), 5, "%s isn't 5-tuple" % name)
|
||||||
verify(type(micro) is IntType, "optional micro isn't int")
|
(major, minor, micro, level, serial) = t
|
||||||
verify(isinstance(level, basestring), "optional level isn't string")
|
a(isinstance(major, int), "%s major isn't int" % name)
|
||||||
verify(level in GOOD_SERIALS,
|
a(isinstance(minor, int), "%s minor isn't int" % name)
|
||||||
"optional level string has unknown value")
|
a(isinstance(micro, int), "%s micro isn't int" % name)
|
||||||
verify(type(serial) is IntType, "optional serial isn't int")
|
a(isinstance(level, basestring),
|
||||||
|
"%s level isn't string" % name)
|
||||||
|
a(level in GOOD_SERIALS,
|
||||||
|
"%s level string has unknown value" % name)
|
||||||
|
a(isinstance(serial, int), "%s serial isn't int" % name)
|
||||||
|
|
||||||
verify(type(mandatory) is TupleType or
|
check(optional, "optional")
|
||||||
mandatory is None, "mandatory isn't tuple or None")
|
|
||||||
if mandatory is not None:
|
if mandatory is not None:
|
||||||
verify(len(mandatory) == 5, "mandatory isn't 5-tuple")
|
check(mandatory, "mandatory")
|
||||||
major, minor, micro, level, serial = mandatory
|
a(optional < mandatory,
|
||||||
verify(type(major) is IntType, "mandatory major isn't int")
|
|
||||||
verify(type(minor) is IntType, "mandatory minor isn't int")
|
|
||||||
verify(type(micro) is IntType, "mandatory micro isn't int")
|
|
||||||
verify(isinstance(level, basestring), "mandatory level isn't string")
|
|
||||||
verify(level in GOOD_SERIALS,
|
|
||||||
"mandatory serial string has unknown value")
|
|
||||||
verify(type(serial) is IntType, "mandatory serial isn't int")
|
|
||||||
verify(optional < mandatory,
|
|
||||||
"optional not less than mandatory, and mandatory not None")
|
"optional not less than mandatory, and mandatory not None")
|
||||||
|
|
||||||
verify(hasattr(value, "compiler_flag"),
|
a(hasattr(value, "compiler_flag"),
|
||||||
"feature is missing a .compiler_flag attr")
|
"feature is missing a .compiler_flag attr")
|
||||||
verify(type(getattr(value, "compiler_flag")) is IntType,
|
a(isinstance(getattr(value, "compiler_flag"), int),
|
||||||
".compiler_flag isn't int")
|
".compiler_flag isn't int")
|
||||||
|
|
||||||
|
def test_main():
|
||||||
|
test_support.run_unittest(FutureTest)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
test_main()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue