Back to index

python3.2  3.2.2
Public Member Functions | Static Public Attributes | Private Member Functions
test.test_runpy.RunPathTest Class Reference
Collaboration diagram for test.test_runpy.RunPathTest:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def test_basic_script
def test_script_compiled
def test_directory
def test_directory_compiled
def test_directory_error
def test_zipfile
def test_zipfile_compiled
def test_zipfile_error
def test_main_recursion_error
def test_encoding

Static Public Attributes

string test_source

Private Member Functions

def _make_test_script
def _check_script
def _check_import_error

Detailed Description

Unit tests for runpy.run_path

Definition at line 290 of file test_runpy.py.


Member Function Documentation

def test.test_runpy.RunPathTest._check_import_error (   self,
  script_name,
  msg 
) [private]

Definition at line 330 of file test_runpy.py.

00330 
00331     def _check_import_error(self, script_name, msg):
00332         msg = re.escape(msg)
00333         self.assertRaisesRegex(ImportError, msg, run_path, script_name)

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_runpy.RunPathTest._check_script (   self,
  script_name,
  expected_name,
  expected_file,
  expected_argv0,
  expected_package 
) [private]

Definition at line 321 of file test_runpy.py.

00321 
00322                             expected_argv0, expected_package):
00323         result = run_path(script_name)
00324         self.assertEqual(result["__name__"], expected_name)
00325         self.assertEqual(result["__file__"], expected_file)
00326         self.assertEqual(result["__cached__"], None)
00327         self.assertIn("argv0", result)
00328         self.assertEqual(result["argv0"], expected_argv0)
00329         self.assertEqual(result["__package__"], expected_package)

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_runpy.RunPathTest._make_test_script (   self,
  script_dir,
  script_basename,
  source = None 
) [private]

Definition at line 315 of file test_runpy.py.

00315 
00316     def _make_test_script(self, script_dir, script_basename, source=None):
00317         if source is None:
00318             source = self.test_source
00319         return make_script(script_dir, script_basename, source)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 334 of file test_runpy.py.

00334 
00335     def test_basic_script(self):
00336         with temp_dir() as script_dir:
00337             mod_name = 'script'
00338             script_name = self._make_test_script(script_dir, mod_name)
00339             self._check_script(script_name, "<run_path>", script_name,
00340                                script_name, None)

Here is the call graph for this function:

Definition at line 350 of file test_runpy.py.

00350 
00351     def test_directory(self):
00352         with temp_dir() as script_dir:
00353             mod_name = '__main__'
00354             script_name = self._make_test_script(script_dir, mod_name)
00355             self._check_script(script_dir, "<run_path>", script_name,
00356                                script_dir, '')

Here is the call graph for this function:

Definition at line 357 of file test_runpy.py.

00357 
00358     def test_directory_compiled(self):
00359         with temp_dir() as script_dir:
00360             mod_name = '__main__'
00361             script_name = self._make_test_script(script_dir, mod_name)
00362             compiled_name = py_compile.compile(script_name, doraise=True)
00363             os.remove(script_name)
00364             legacy_pyc = make_legacy_pyc(script_name)
00365             self._check_script(script_dir, "<run_path>", legacy_pyc,
00366                                script_dir, '')

Here is the call graph for this function:

Definition at line 367 of file test_runpy.py.

00367 
00368     def test_directory_error(self):
00369         with temp_dir() as script_dir:
00370             mod_name = 'not_main'
00371             script_name = self._make_test_script(script_dir, mod_name)
00372             msg = "can't find '__main__' module in %r" % script_dir
00373             self._check_import_error(script_dir, msg)

Here is the call graph for this function:

Definition at line 408 of file test_runpy.py.

00408 
00409     def test_encoding(self):
00410         with temp_dir() as script_dir:
00411             filename = os.path.join(script_dir, 'script.py')
00412             with open(filename, 'w', encoding='latin1') as f:
00413                 f.write("""
00414 #coding:latin1
00415 "non-ASCII: h\xe9"
00416 """)
00417             result = run_path(filename)
00418             self.assertEqual(result['__doc__'], "non-ASCII: h\xe9")
00419 

Here is the call graph for this function:

Definition at line 398 of file test_runpy.py.

00398 
00399     def test_main_recursion_error(self):
00400         with temp_dir() as script_dir, temp_dir() as dummy_dir:
00401             mod_name = '__main__'
00402             source = ("import runpy\n"
00403                       "runpy.run_path(%r)\n") % dummy_dir
00404             script_name = self._make_test_script(script_dir, mod_name, source)
00405             zip_name, fname = make_zip_script(script_dir, 'test_zip', script_name)
00406             msg = "recursion depth exceeded"
00407             self.assertRaisesRegex(RuntimeError, msg, run_path, zip_name)

Here is the call graph for this function:

Definition at line 341 of file test_runpy.py.

00341 
00342     def test_script_compiled(self):
00343         with temp_dir() as script_dir:
00344             mod_name = 'script'
00345             script_name = self._make_test_script(script_dir, mod_name)
00346             compiled_name = py_compile.compile(script_name, doraise=True)
00347             os.remove(script_name)
00348             self._check_script(compiled_name, "<run_path>", compiled_name,
00349                                compiled_name, None)

Here is the call graph for this function:

Definition at line 374 of file test_runpy.py.

00374 
00375     def test_zipfile(self):
00376         with temp_dir() as script_dir:
00377             mod_name = '__main__'
00378             script_name = self._make_test_script(script_dir, mod_name)
00379             zip_name, fname = make_zip_script(script_dir, 'test_zip', script_name)
00380             self._check_script(zip_name, "<run_path>", fname, zip_name, '')

Here is the call graph for this function:

Definition at line 381 of file test_runpy.py.

00381 
00382     def test_zipfile_compiled(self):
00383         with temp_dir() as script_dir:
00384             mod_name = '__main__'
00385             script_name = self._make_test_script(script_dir, mod_name)
00386             compiled_name = py_compile.compile(script_name, doraise=True)
00387             zip_name, fname = make_zip_script(script_dir, 'test_zip',
00388                                               compiled_name)
00389             self._check_script(zip_name, "<run_path>", fname, zip_name, '')

Here is the call graph for this function:

Definition at line 390 of file test_runpy.py.

00390 
00391     def test_zipfile_error(self):
00392         with temp_dir() as script_dir:
00393             mod_name = 'not_main'
00394             script_name = self._make_test_script(script_dir, mod_name)
00395             zip_name, fname = make_zip_script(script_dir, 'test_zip', script_name)
00396             msg = "can't find '__main__' module in %r" % zip_name
00397             self._check_import_error(zip_name, msg)

Here is the call graph for this function:


Member Data Documentation

Initial value:
"""\
# Script may be run with optimisation enabled, so don't rely on assert
# statements being executed
def assertEqual(lhs, rhs):
if lhs != rhs:
    raise AssertionError('%r != %r' % (lhs, rhs))
def assertIs(lhs, rhs):
if lhs is not rhs:
    raise AssertionError('%r is not %r' % (lhs, rhs))
# Check basic code execution
result = ['Top level assignment']
def f():
result.append('Lower level reference')
f()
assertEqual(result, ['Top level assignment', 'Lower level reference'])
# Check the sys module
import sys
assertIs(globals(), sys.modules[__name__].__dict__)
argv0 = sys.argv[0]
"""

Definition at line 294 of file test_runpy.py.


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