Back to index

python3.2  3.2.2
Public Member Functions | Private Member Functions
test.test_cmd_line_script.CmdLineTest Class Reference

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_module_in_package
def test_module_in_package_in_zipfile
def test_module_in_subpackage_in_zipfile
def test_package
def test_package_compiled
def test_package_error
def test_package_recursion
def test_issue8202
def test_issue8202_dash_c_file_ignored
def test_issue8202_dash_m_file_ignored

Private Member Functions

def _check_output
def _check_script
def _check_import_error

Detailed Description

Definition at line 72 of file test_cmd_line_script.py.


Member Function Documentation

def test.test_cmd_line_script.CmdLineTest._check_import_error (   self,
  script_name,
  expected_msg,
  cmd_line_switches 
) [private]

Definition at line 109 of file test_cmd_line_script.py.

00109 
00110                             *cmd_line_switches):
00111         run_args = cmd_line_switches + (script_name,)
00112         rc, out, err = assert_python_failure(*run_args)
00113         if verbose > 1:
00114             print('Output from test script %r:' % script_name)
00115             print(err)
00116             print('Expected output: %r' % expected_msg)
00117         self.assertIn(expected_msg.encode('utf-8'), err)

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_cmd_line_script.CmdLineTest._check_output (   self,
  script_name,
  exit_code,
  data,
  expected_file,
  expected_argv0,
  expected_path0,
  expected_package 
) [private]

Definition at line 75 of file test_cmd_line_script.py.

00075 
00076                              expected_path0, expected_package):
00077         if verbose > 1:
00078             print("Output from test script %r:" % script_name)
00079             print(data)
00080         self.assertEqual(exit_code, 0)
00081         printed_file = '__file__==%a' % expected_file
00082         printed_package = '__package__==%r' % expected_package
00083         printed_argv0 = 'sys.argv[0]==%a' % expected_argv0
00084         printed_path0 = 'sys.path[0]==%a' % expected_path0
00085         printed_cwd = 'cwd==%a' % os.getcwd()
00086         if verbose > 1:
00087             print('Expected output:')
00088             print(printed_file)
00089             print(printed_package)
00090             print(printed_argv0)
00091             print(printed_cwd)
00092         self.assertIn(printed_file.encode('utf-8'), data)
00093         self.assertIn(printed_package.encode('utf-8'), data)
00094         self.assertIn(printed_argv0.encode('utf-8'), data)
00095         self.assertIn(printed_path0.encode('utf-8'), data)
00096         self.assertIn(printed_cwd.encode('utf-8'), data)

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_cmd_line_script.CmdLineTest._check_script (   self,
  script_name,
  expected_file,
  expected_argv0,
  expected_path0,
  expected_package,
  cmd_line_switches 
) [private]

Definition at line 100 of file test_cmd_line_script.py.

00100 
00101                             *cmd_line_switches):
00102         if not __debug__:
00103             cmd_line_switches += ('-' + 'O' * sys.flags.optimize,)
00104         run_args = cmd_line_switches + (script_name,)
00105         rc, out, err = assert_python_ok(*run_args)
00106         self._check_output(script_name, rc, out + err, expected_file,
00107                            expected_argv0, expected_path0, expected_package)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 118 of file test_cmd_line_script.py.

00118 
00119     def test_basic_script(self):
00120         with temp_dir() as script_dir:
00121             script_name = _make_test_script(script_dir, 'script')
00122             self._check_script(script_name, script_name, script_name,
00123                                script_dir, None)

Here is the call graph for this function:

Definition at line 133 of file test_cmd_line_script.py.

00133 
00134     def test_directory(self):
00135         with temp_dir() as script_dir:
00136             script_name = _make_test_script(script_dir, '__main__')
00137             self._check_script(script_dir, script_name, script_dir,
00138                                script_dir, '')

Here is the call graph for this function:

Definition at line 139 of file test_cmd_line_script.py.

00139 
00140     def test_directory_compiled(self):
00141         with temp_dir() as script_dir:
00142             script_name = _make_test_script(script_dir, '__main__')
00143             py_compile.compile(script_name, doraise=True)
00144             os.remove(script_name)
00145             pyc_file = support.make_legacy_pyc(script_name)
00146             self._check_script(script_dir, pyc_file, script_dir,
00147                                script_dir, '')

Here is the call graph for this function:

Definition at line 148 of file test_cmd_line_script.py.

00148 
00149     def test_directory_error(self):
00150         with temp_dir() as script_dir:
00151             msg = "can't find '__main__' module in %r" % script_dir
00152             self._check_import_error(script_dir, msg)

Here is the call graph for this function:

Definition at line 235 of file test_cmd_line_script.py.

00235 
00236     def test_issue8202(self):
00237         # Make sure package __init__ modules see "-m" in sys.argv0 while
00238         # searching for the module to execute
00239         with temp_dir() as script_dir:
00240             with support.temp_cwd(path=script_dir):
00241                 pkg_dir = os.path.join(script_dir, 'test_pkg')
00242                 make_pkg(pkg_dir, "import sys; print('init_argv0==%r' % sys.argv[0])")
00243                 script_name = _make_test_script(pkg_dir, 'script')
00244                 rc, out, err = assert_python_ok('-m', 'test_pkg.script')
00245                 if verbose > 1:
00246                     print(data)
00247                 expected = "init_argv0==%r" % '-m'
00248                 self.assertIn(expected.encode('utf-8'), out)
00249                 self._check_output(script_name, rc, out,
00250                                    script_name, script_name, '', 'test_pkg')

Here is the call graph for this function:

Definition at line 251 of file test_cmd_line_script.py.

00251 
00252     def test_issue8202_dash_c_file_ignored(self):
00253         # Make sure a "-c" file in the current directory
00254         # does not alter the value of sys.path[0]
00255         with temp_dir() as script_dir:
00256             with support.temp_cwd(path=script_dir):
00257                 with open("-c", "w") as f:
00258                     f.write("data")
00259                     rc, out, err = assert_python_ok('-c',
00260                         'import sys; print("sys.path[0]==%r" % sys.path[0])')
00261                     if verbose > 1:
00262                         print(out)
00263                     expected = "sys.path[0]==%r" % ''
00264                     self.assertIn(expected.encode('utf-8'), out)

Here is the call graph for this function:

Definition at line 265 of file test_cmd_line_script.py.

00265 
00266     def test_issue8202_dash_m_file_ignored(self):
00267         # Make sure a "-m" file in the current directory
00268         # does not alter the value of sys.path[0]
00269         with temp_dir() as script_dir:
00270             script_name = _make_test_script(script_dir, 'other')
00271             with support.temp_cwd(path=script_dir):
00272                 with open("-m", "w") as f:
00273                     f.write("data")
00274                     rc, out, err = assert_python_ok('-m', 'other')
00275                     self._check_output(script_name, rc, out,
00276                                       script_name, script_name, '', '')

Here is the call graph for this function:

Definition at line 173 of file test_cmd_line_script.py.

00173 
00174     def test_module_in_package(self):
00175         with temp_dir() as script_dir:
00176             pkg_dir = os.path.join(script_dir, 'test_pkg')
00177             make_pkg(pkg_dir)
00178             script_name = _make_test_script(pkg_dir, 'script')
00179             launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg.script')
00180             self._check_script(launch_name, script_name, script_name, script_dir, 'test_pkg')

Here is the call graph for this function:

Definition at line 181 of file test_cmd_line_script.py.

00181 
00182     def test_module_in_package_in_zipfile(self):
00183         with temp_dir() as script_dir:
00184             zip_name, run_name = _make_test_zip_pkg(script_dir, 'test_zip', 'test_pkg', 'script')
00185             launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg.script', zip_name)
00186             self._check_script(launch_name, run_name, run_name, zip_name, 'test_pkg')

Here is the call graph for this function:

Definition at line 187 of file test_cmd_line_script.py.

00187 
00188     def test_module_in_subpackage_in_zipfile(self):
00189         with temp_dir() as script_dir:
00190             zip_name, run_name = _make_test_zip_pkg(script_dir, 'test_zip', 'test_pkg', 'script', depth=2)
00191             launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg.test_pkg.script', zip_name)
00192             self._check_script(launch_name, run_name, run_name, zip_name, 'test_pkg.test_pkg')

Here is the call graph for this function:

Definition at line 193 of file test_cmd_line_script.py.

00193 
00194     def test_package(self):
00195         with temp_dir() as script_dir:
00196             pkg_dir = os.path.join(script_dir, 'test_pkg')
00197             make_pkg(pkg_dir)
00198             script_name = _make_test_script(pkg_dir, '__main__')
00199             launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg')
00200             self._check_script(launch_name, script_name,
00201                                script_name, script_dir, 'test_pkg')

Here is the call graph for this function:

Definition at line 202 of file test_cmd_line_script.py.

00202 
00203     def test_package_compiled(self):
00204         with temp_dir() as script_dir:
00205             pkg_dir = os.path.join(script_dir, 'test_pkg')
00206             make_pkg(pkg_dir)
00207             script_name = _make_test_script(pkg_dir, '__main__')
00208             compiled_name = py_compile.compile(script_name, doraise=True)
00209             os.remove(script_name)
00210             pyc_file = support.make_legacy_pyc(script_name)
00211             launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg')
00212             self._check_script(launch_name, pyc_file,
00213                                pyc_file, script_dir, 'test_pkg')

Here is the call graph for this function:

Definition at line 214 of file test_cmd_line_script.py.

00214 
00215     def test_package_error(self):
00216         with temp_dir() as script_dir:
00217             pkg_dir = os.path.join(script_dir, 'test_pkg')
00218             make_pkg(pkg_dir)
00219             msg = ("'test_pkg' is a package and cannot "
00220                    "be directly executed")
00221             launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg')
00222             self._check_import_error(launch_name, msg)

Here is the call graph for this function:

Definition at line 223 of file test_cmd_line_script.py.

00223 
00224     def test_package_recursion(self):
00225         with temp_dir() as script_dir:
00226             pkg_dir = os.path.join(script_dir, 'test_pkg')
00227             make_pkg(pkg_dir)
00228             main_dir = os.path.join(pkg_dir, '__main__')
00229             make_pkg(main_dir)
00230             msg = ("Cannot use package as __main__ module; "
00231                    "'test_pkg' is a package and cannot "
00232                    "be directly executed")
00233             launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg')
00234             self._check_import_error(launch_name, msg)

Here is the call graph for this function:

Definition at line 124 of file test_cmd_line_script.py.

00124 
00125     def test_script_compiled(self):
00126         with temp_dir() as script_dir:
00127             script_name = _make_test_script(script_dir, 'script')
00128             py_compile.compile(script_name, doraise=True)
00129             os.remove(script_name)
00130             pyc_file = support.make_legacy_pyc(script_name)
00131             self._check_script(pyc_file, pyc_file,
00132                                pyc_file, script_dir, None)

Here is the call graph for this function:

Definition at line 153 of file test_cmd_line_script.py.

00153 
00154     def test_zipfile(self):
00155         with temp_dir() as script_dir:
00156             script_name = _make_test_script(script_dir, '__main__')
00157             zip_name, run_name = make_zip_script(script_dir, 'test_zip', script_name)
00158             self._check_script(zip_name, run_name, zip_name, zip_name, '')

Here is the call graph for this function:

Definition at line 159 of file test_cmd_line_script.py.

00159 
00160     def test_zipfile_compiled(self):
00161         with temp_dir() as script_dir:
00162             script_name = _make_test_script(script_dir, '__main__')
00163             compiled_name = py_compile.compile(script_name, doraise=True)
00164             zip_name, run_name = make_zip_script(script_dir, 'test_zip', compiled_name)
00165             self._check_script(zip_name, run_name, zip_name, zip_name, '')

Here is the call graph for this function:

Definition at line 166 of file test_cmd_line_script.py.

00166 
00167     def test_zipfile_error(self):
00168         with temp_dir() as script_dir:
00169             script_name = _make_test_script(script_dir, 'not_main')
00170             zip_name, run_name = make_zip_script(script_dir, 'test_zip', script_name)
00171             msg = "can't find '__main__' module in %r" % zip_name
00172             self._check_import_error(zip_name, msg)

Here is the call graph for this function:


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