Back to index

python3.2  3.2.2
Public Member Functions | Static Public Attributes
test.test_runpy.RunModuleCodeTest Class Reference

List of all members.

Public Member Functions

def test_run_code
def test_run_module_code

Static Public Attributes

list expected_result = ["Top level assignment", "Lower level reference"]
tuple test_source

Detailed Description

Unit tests for runpy._run_code and runpy._run_module_code

Definition at line 22 of file test_runpy.py.


Member Function Documentation

Definition at line 43 of file test_runpy.py.

00043 
00044     def test_run_code(self):
00045         saved_argv0 = sys.argv[0]
00046         d = _run_code(self.test_source, {})
00047         self.assertEqual(d["result"], self.expected_result)
00048         self.assertIs(d["__name__"], None)
00049         self.assertIs(d["__file__"], None)
00050         self.assertIs(d["__cached__"], None)
00051         self.assertIs(d["__loader__"], None)
00052         self.assertIs(d["__package__"], None)
00053         self.assertIs(d["run_argv0"], saved_argv0)
00054         self.assertNotIn("run_name", d)
00055         self.assertIs(sys.argv[0], saved_argv0)

Here is the call graph for this function:

Definition at line 56 of file test_runpy.py.

00056 
00057     def test_run_module_code(self):
00058         initial = object()
00059         name = "<Nonsense>"
00060         file = "Some other nonsense"
00061         loader = "Now you're just being silly"
00062         package = '' # Treat as a top level module
00063         d1 = dict(initial=initial)
00064         saved_argv0 = sys.argv[0]
00065         d2 = _run_module_code(self.test_source,
00066                               d1,
00067                               name,
00068                               file,
00069                               loader,
00070                               package)
00071         self.assertNotIn("result", d1)
00072         self.assertIs(d2["initial"], initial)
00073         self.assertEqual(d2["result"], self.expected_result)
00074         self.assertEqual(d2["nested"]["x"], 1)
00075         self.assertIs(d2["__name__"], name)
00076         self.assertTrue(d2["run_name_in_sys_modules"])
00077         self.assertTrue(d2["module_in_sys_modules"])
00078         self.assertIs(d2["__file__"], file)
00079         self.assertIs(d2["__cached__"], None)
00080         self.assertIs(d2["run_argv0"], file)
00081         self.assertIs(d2["__loader__"], loader)
00082         self.assertIs(d2["__package__"], package)
00083         self.assertIs(sys.argv[0], saved_argv0)
00084         self.assertNotIn(name, sys.modules)
00085 

Here is the call graph for this function:


Member Data Documentation

list test.test_runpy.RunModuleCodeTest.expected_result = ["Top level assignment", "Lower level reference"] [static]

Definition at line 25 of file test_runpy.py.

Initial value:
(
        "# Check basic code execution\n"
        "result = ['Top level assignment']\n"
        "def f():\n"
        "    result.append('Lower level reference')\n"
        "f()\n"
        "# Check the sys module\n"
        "import sys\n"
        "run_argv0 = sys.argv[0]\n"
        "run_name_in_sys_modules = __name__ in sys.modules\n"
        "if run_name_in_sys_modules:\n"
        "   module_in_sys_modules = globals() is sys.modules[__name__].__dict__\n"
        "# Check nested operation\n"
        "import runpy\n"
        "nested = runpy._run_module_code('x=1\\n', mod_name='<run>')\n"
    )

Definition at line 26 of file test_runpy.py.


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