/Lib/test/test___future__.py

http://unladen-swallow.googlecode.com/ · Python · 63 lines · 50 code · 11 blank · 2 comment · 6 complexity · 4c4209303c2fc6fb52e3c858c89d517a MD5 · raw file

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