0001 # Test the module type 0002 0003 from test.test_support import verify, vereq, verbose, TestFailed 0004 0005 import sys 0006 module = type(sys) 0007 0008 # An uninitialized module has no __dict__ or __name__, and __doc__ is None 0009 foo = module.__new__(module) 0010 verify(foo.__dict__ is None) 0011 try: 0012 s = foo.__name__ 0013 except AttributeError: 0014 pass 0015 else: 0016 raise TestFailed, "__name__ = %s" % repr(s) 0017 vereq(foo.__doc__, module.__doc__) 0018 0019 # Regularly initialized module, no docstring 0020 foo = module("foo") 0021 vereq(foo.__name__, "foo") 0022 vereq(foo.__doc__, None) 0023 vereq(foo.__dict__, {"__name__": "foo", "__doc__": None}) 0024 0025 # ASCII docstring 0026 foo = module("foo", "foodoc") 0027 vereq(foo.__name__, "foo") 0028 vereq(foo.__doc__, "foodoc") 0029 vereq(foo.__dict__, {"__name__": "foo", "__doc__": "foodoc"}) 0030 0031 # Unicode docstring 0032 foo = module("foo", u"foodoc\u1234") 0033 vereq(foo.__name__, "foo") 0034 vereq(foo.__doc__, u"foodoc\u1234") 0035 vereq(foo.__dict__, {"__name__": "foo", "__doc__": u"foodoc\u1234"}) 0036 0037 # Reinitialization should not replace the __dict__ 0038 foo.bar = 42 0039 d = foo.__dict__ 0040 foo.__init__("foo", "foodoc") 0041 vereq(foo.__name__, "foo") 0042 vereq(foo.__doc__, "foodoc") 0043 vereq(foo.bar, 42) 0044 vereq(foo.__dict__, {"__name__": "foo", "__doc__": "foodoc", "bar": 42}) 0045 verify(foo.__dict__ is d) 0046 0047 if verbose: 0048 print "All OK" 0049
Generated by PyXR 0.9.4