Back to index

python3.2  3.2.2
Public Member Functions
test.test_module.ModuleTests Class Reference

List of all members.

Public Member Functions

def test_uninitialized
def test_no_docstring
def test_ascii_docstring
def test_unicode_docstring
def test_reinit
def test_dont_clear_dict
def test_clear_dict_in_ref_cycle

Detailed Description

Definition at line 8 of file test_module.py.


Member Function Documentation

Definition at line 29 of file test_module.py.

00029 
00030     def test_ascii_docstring(self):
00031         # ASCII docstring
00032         foo = ModuleType("foo", "foodoc")
00033         self.assertEqual(foo.__name__, "foo")
00034         self.assertEqual(foo.__doc__, "foodoc")
00035         self.assertEqual(foo.__dict__,
00036                          {"__name__": "foo", "__doc__": "foodoc"})

Here is the call graph for this function:

Definition at line 68 of file test_module.py.

00068 
00069     def test_clear_dict_in_ref_cycle(self):
00070         destroyed = []
00071         m = ModuleType("foo")
00072         m.destroyed = destroyed
00073         s = """class A:
00074     def __del__(self):
00075         destroyed.append(1)
00076 a = A()"""
00077         exec(s, m.__dict__)
00078         del m
00079         gc_collect()
00080         self.assertEqual(destroyed, [1])

Here is the call graph for this function:

Definition at line 59 of file test_module.py.

00059 
00060     def test_dont_clear_dict(self):
00061         # See issue 7140.
00062         def f():
00063             foo = ModuleType("foo")
00064             foo.bar = 4
00065             return foo
00066         gc_collect()
00067         self.assertEqual(f().__dict__["bar"], 4)

Here is the call graph for this function:

Definition at line 22 of file test_module.py.

00022 
00023     def test_no_docstring(self):
00024         # Regularly initialized module, no docstring
00025         foo = ModuleType("foo")
00026         self.assertEqual(foo.__name__, "foo")
00027         self.assertEqual(foo.__doc__, None)
00028         self.assertEqual(foo.__dict__, {"__name__": "foo", "__doc__": None})

Here is the call graph for this function:

Definition at line 45 of file test_module.py.

00045 
00046     def test_reinit(self):
00047         # Reinitialization should not replace the __dict__
00048         foo = ModuleType("foo", "foodoc\u1234")
00049         foo.bar = 42
00050         d = foo.__dict__
00051         foo.__init__("foo", "foodoc")
00052         self.assertEqual(foo.__name__, "foo")
00053         self.assertEqual(foo.__doc__, "foodoc")
00054         self.assertEqual(foo.bar, 42)
00055         self.assertEqual(foo.__dict__,
00056               {"__name__": "foo", "__doc__": "foodoc", "bar": 42})
00057         self.assertTrue(foo.__dict__ is d)

Here is the call graph for this function:

Definition at line 37 of file test_module.py.

00037 
00038     def test_unicode_docstring(self):
00039         # Unicode docstring
00040         foo = ModuleType("foo", "foodoc\u1234")
00041         self.assertEqual(foo.__name__, "foo")
00042         self.assertEqual(foo.__doc__, "foodoc\u1234")
00043         self.assertEqual(foo.__dict__,
00044                          {"__name__": "foo", "__doc__": "foodoc\u1234"})

Here is the call graph for this function:

Definition at line 9 of file test_module.py.

00009 
00010     def test_uninitialized(self):
00011         # An uninitialized module has no __dict__ or __name__,
00012         # and __doc__ is None
00013         foo = ModuleType.__new__(ModuleType)
00014         self.assertTrue(foo.__dict__ is None)
00015         self.assertRaises(SystemError, dir, foo)
00016         try:
00017             s = foo.__name__
00018             self.fail("__name__ = %s" % repr(s))
00019         except AttributeError:
00020             pass
00021         self.assertEqual(foo.__doc__, ModuleType.__doc__)

Here is the call graph for this function:


The documentation for this class was generated from the following file: