Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
test.test_zipimport_support.ZipSupportTests Class Reference

List of all members.

Public Member Functions

def setUp
def tearDown
def test_inspect_getsource_issue4223
def test_doctest_issue4197
def test_doctest_main_issue4197
def test_pdb_issue4201

Public Attributes

 path
 meta_path
 path_hooks

Detailed Description

Definition at line 55 of file test_zipimport_support.py.


Member Function Documentation

Definition at line 64 of file test_zipimport_support.py.

00064 
00065     def setUp(self):
00066         linecache.clearcache()
00067         zipimport._zip_directory_cache.clear()
00068         self.path = sys.path[:]
00069         self.meta_path = sys.meta_path[:]
00070         self.path_hooks = sys.path_hooks[:]
00071         sys.path_importer_cache.clear()

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 72 of file test_zipimport_support.py.

00072 
00073     def tearDown(self):
00074         sys.path[:] = self.path
00075         sys.meta_path[:] = self.meta_path
00076         sys.path_hooks[:] = self.path_hooks
00077         sys.path_importer_cache.clear()

Here is the caller graph for this function:

Definition at line 94 of file test_zipimport_support.py.

00094 
00095     def test_doctest_issue4197(self):
00096         # To avoid having to keep two copies of the doctest module's
00097         # unit tests in sync, this test works by taking the source of
00098         # test_doctest itself, rewriting it a bit to cope with a new
00099         # location, and then throwing it in a zip file to make sure
00100         # everything still works correctly
00101         test_src = inspect.getsource(test_doctest)
00102         test_src = test_src.replace(
00103                          "from test import test_doctest",
00104                          "import test_zipped_doctest as test_doctest")
00105         test_src = test_src.replace("test.test_doctest",
00106                                     "test_zipped_doctest")
00107         test_src = test_src.replace("test.sample_doctest",
00108                                     "sample_zipped_doctest")
00109         sample_src = inspect.getsource(sample_doctest)
00110         sample_src = sample_src.replace("test.test_doctest",
00111                                         "test_zipped_doctest")
00112         with temp_dir() as d:
00113             script_name = make_script(d, 'test_zipped_doctest',
00114                                             test_src)
00115             zip_name, run_name = make_zip_script(d, 'test_zip',
00116                                                 script_name)
00117             z = zipfile.ZipFile(zip_name, 'a')
00118             z.writestr("sample_zipped_doctest.py", sample_src)
00119             z.close()
00120             if verbose:
00121                 zip_file = zipfile.ZipFile(zip_name, 'r')
00122                 print ('Contents of %r:' % zip_name)
00123                 zip_file.printdir()
00124                 zip_file.close()
00125             os.remove(script_name)
00126             sys.path.insert(0, zip_name)
00127             import test_zipped_doctest
00128             try:
00129                 # Some of the doc tests depend on the colocated text files
00130                 # which aren't available to the zipped version (the doctest
00131                 # module currently requires real filenames for non-embedded
00132                 # tests). So we're forced to be selective about which tests
00133                 # to run.
00134                 # doctest could really use some APIs which take a text
00135                 # string or a file object instead of a filename...
00136                 known_good_tests = [
00137                     test_zipped_doctest.SampleClass,
00138                     test_zipped_doctest.SampleClass.NestedClass,
00139                     test_zipped_doctest.SampleClass.NestedClass.__init__,
00140                     test_zipped_doctest.SampleClass.__init__,
00141                     test_zipped_doctest.SampleClass.a_classmethod,
00142                     test_zipped_doctest.SampleClass.a_property,
00143                     test_zipped_doctest.SampleClass.a_staticmethod,
00144                     test_zipped_doctest.SampleClass.double,
00145                     test_zipped_doctest.SampleClass.get,
00146                     test_zipped_doctest.SampleNewStyleClass,
00147                     test_zipped_doctest.SampleNewStyleClass.__init__,
00148                     test_zipped_doctest.SampleNewStyleClass.double,
00149                     test_zipped_doctest.SampleNewStyleClass.get,
00150                     test_zipped_doctest.sample_func,
00151                     test_zipped_doctest.test_DocTest,
00152                     test_zipped_doctest.test_DocTestParser,
00153                     test_zipped_doctest.test_DocTestRunner.basics,
00154                     test_zipped_doctest.test_DocTestRunner.exceptions,
00155                     test_zipped_doctest.test_DocTestRunner.option_directives,
00156                     test_zipped_doctest.test_DocTestRunner.optionflags,
00157                     test_zipped_doctest.test_DocTestRunner.verbose_flag,
00158                     test_zipped_doctest.test_Example,
00159                     test_zipped_doctest.test_debug,
00160                     test_zipped_doctest.test_pdb_set_trace,
00161                     test_zipped_doctest.test_pdb_set_trace_nested,
00162                     test_zipped_doctest.test_testsource,
00163                     test_zipped_doctest.test_trailing_space_in_test,
00164                     test_zipped_doctest.test_DocTestSuite,
00165                     test_zipped_doctest.test_DocTestFinder,
00166                 ]
00167                 # These remaining tests are the ones which need access
00168                 # to the data files, so we don't run them
00169                 fail_due_to_missing_data_files = [
00170                     test_zipped_doctest.test_DocFileSuite,
00171                     test_zipped_doctest.test_testfile,
00172                     test_zipped_doctest.test_unittest_reportflags,
00173                 ]
00174                 for obj in known_good_tests:
00175                     _run_object_doctest(obj, test_zipped_doctest)
00176             finally:
00177                 del sys.modules["test_zipped_doctest"]

Here is the call graph for this function:

Definition at line 178 of file test_zipimport_support.py.

00178 
00179     def test_doctest_main_issue4197(self):
00180         test_src = textwrap.dedent("""\
00181                     class Test:
00182                         ">>> 'line 2'"
00183                         pass
00184 
00185                     import doctest
00186                     doctest.testmod()
00187                     """)
00188         pattern = 'File "%s", line 2, in %s'
00189         with temp_dir() as d:
00190             script_name = make_script(d, 'script', test_src)
00191             rc, out, err = assert_python_ok(script_name)
00192             expected = pattern % (script_name, "__main__.Test")
00193             if verbose:
00194                 print ("Expected line", expected)
00195                 print ("Got stdout:")
00196                 print (ascii(out))
00197             self.assertIn(expected.encode('utf-8'), out)
00198             zip_name, run_name = make_zip_script(d, "test_zip",
00199                                                 script_name, '__main__.py')
00200             rc, out, err = assert_python_ok(zip_name)
00201             expected = pattern % (run_name, "__main__.Test")
00202             if verbose:
00203                 print ("Expected line", expected)
00204                 print ("Got stdout:")
00205                 print (ascii(out))
00206             self.assertIn(expected.encode('utf-8'), out)

Here is the call graph for this function:

Definition at line 78 of file test_zipimport_support.py.

00078 
00079     def test_inspect_getsource_issue4223(self):
00080         test_src = "def foo(): pass\n"
00081         with temp_dir() as d:
00082             init_name = make_script(d, '__init__', test_src)
00083             name_in_zip = os.path.join('zip_pkg',
00084                                        os.path.basename(init_name))
00085             zip_name, run_name = make_zip_script(d, 'test_zip',
00086                                                 init_name, name_in_zip)
00087             os.remove(init_name)
00088             sys.path.insert(0, zip_name)
00089             import zip_pkg
00090             try:
00091                 self.assertEqual(inspect.getsource(zip_pkg.foo), test_src)
00092             finally:
00093                 del sys.modules["zip_pkg"]

Here is the call graph for this function:

Definition at line 207 of file test_zipimport_support.py.

00207 
00208     def test_pdb_issue4201(self):
00209         test_src = textwrap.dedent("""\
00210                     def f():
00211                         pass
00212 
00213                     import pdb
00214                     pdb.Pdb(nosigint=True).runcall(f)
00215                     """)
00216         with temp_dir() as d:
00217             script_name = make_script(d, 'script', test_src)
00218             p = spawn_python(script_name)
00219             p.stdin.write(b'l\n')
00220             data = kill_python(p)
00221             self.assertIn(script_name.encode('utf-8'), data)
00222             zip_name, run_name = make_zip_script(d, "test_zip",
00223                                                 script_name, '__main__.py')
00224             p = spawn_python(zip_name)
00225             p.stdin.write(b'l\n')
00226             data = kill_python(p)
00227             self.assertIn(run_name.encode('utf-8'), data)
00228 

Here is the call graph for this function:


Member Data Documentation

Definition at line 68 of file test_zipimport_support.py.

Definition at line 67 of file test_zipimport_support.py.

Definition at line 69 of file test_zipimport_support.py.


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