blob: 2b35a531afd5e7baae7d95fcec05f9824b69876a [file] [log] [blame]
Guido van Rossumc3a787e2002-06-04 05:52:47 +00001# Test the module type
2
Barry Warsaw04f357c2002-07-23 19:04:11 +00003from test.test_support import verify, vereq, verbose, TestFailed
Guido van Rossumc3a787e2002-06-04 05:52:47 +00004
5import sys
6module = type(sys)
7
8# An uninitialized module has no __dict__ or __name__, and __doc__ is None
9foo = module.__new__(module)
10verify(foo.__dict__ is None)
11try:
12 s = foo.__name__
13except AttributeError:
14 pass
15else:
16 raise TestFailed, "__name__ = %s" % repr(s)
Guido van Rossumbdabecc2002-06-04 06:06:54 +000017vereq(foo.__doc__, module.__doc__)
Guido van Rossumc3a787e2002-06-04 05:52:47 +000018
19# Regularly initialized module, no docstring
20foo = module("foo")
21vereq(foo.__name__, "foo")
22vereq(foo.__doc__, None)
23vereq(foo.__dict__, {"__name__": "foo", "__doc__": None})
24
25# ASCII docstring
26foo = module("foo", "foodoc")
27vereq(foo.__name__, "foo")
28vereq(foo.__doc__, "foodoc")
29vereq(foo.__dict__, {"__name__": "foo", "__doc__": "foodoc"})
30
31# Unicode docstring
32foo = module("foo", u"foodoc\u1234")
33vereq(foo.__name__, "foo")
34vereq(foo.__doc__, u"foodoc\u1234")
35vereq(foo.__dict__, {"__name__": "foo", "__doc__": u"foodoc\u1234"})
36
37# Reinitialization should not replace the __dict__
38foo.bar = 42
39d = foo.__dict__
40foo.__init__("foo", "foodoc")
41vereq(foo.__name__, "foo")
42vereq(foo.__doc__, "foodoc")
43vereq(foo.bar, 42)
44vereq(foo.__dict__, {"__name__": "foo", "__doc__": "foodoc", "bar": 42})
45verify(foo.__dict__ is d)
46
47if verbose:
48 print "All OK"