mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 07:31:38 +00:00 
			
		
		
		
	Merged revisions 67790 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r67790 | nick.coghlan | 2008-12-15 21:41:05 +1000 (Mon, 15 Dec 2008) | 1 line Issue #4197: Fix the remaining part of the doctest-in-zipfile problem by giving linecache access to the module globals when available ........
This commit is contained in:
		
							parent
							
								
									8f9cd6a935
								
							
						
					
					
						commit
						386220068c
					
				
					 2 changed files with 42 additions and 3 deletions
				
			
		| 
						 | 
					@ -813,6 +813,14 @@ def find(self, obj, name=None, module=None, globs=None, extraglobs=None):
 | 
				
			||||||
        # given object's docstring.
 | 
					        # given object's docstring.
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            file = inspect.getsourcefile(obj) or inspect.getfile(obj)
 | 
					            file = inspect.getsourcefile(obj) or inspect.getfile(obj)
 | 
				
			||||||
 | 
					            if module is not None:
 | 
				
			||||||
 | 
					                # Supply the module globals in case the module was
 | 
				
			||||||
 | 
					                # originally loaded via a PEP 302 loader and
 | 
				
			||||||
 | 
					                # file is not a valid filesystem path
 | 
				
			||||||
 | 
					                source_lines = linecache.getlines(file, module.__dict__)
 | 
				
			||||||
 | 
					            else:
 | 
				
			||||||
 | 
					                # No access to a loader, so assume it's a normal
 | 
				
			||||||
 | 
					                # filesystem path
 | 
				
			||||||
                source_lines = linecache.getlines(file)
 | 
					                source_lines = linecache.getlines(file)
 | 
				
			||||||
            if not source_lines:
 | 
					            if not source_lines:
 | 
				
			||||||
                source_lines = None
 | 
					                source_lines = None
 | 
				
			||||||
| 
						 | 
					@ -1427,8 +1435,10 @@ def merge(self, other):
 | 
				
			||||||
        d = self._name2ft
 | 
					        d = self._name2ft
 | 
				
			||||||
        for name, (f, t) in other._name2ft.items():
 | 
					        for name, (f, t) in other._name2ft.items():
 | 
				
			||||||
            if name in d:
 | 
					            if name in d:
 | 
				
			||||||
                print("*** DocTestRunner.merge: '" + name + "' in both" \
 | 
					                # Don't print here by default, since doing
 | 
				
			||||||
                    " testers; summing outcomes.")
 | 
					                #     so breaks some of the buildbots
 | 
				
			||||||
 | 
					                #print("*** DocTestRunner.merge: '" + name + "' in both" \
 | 
				
			||||||
 | 
					                #    " testers; summing outcomes.")
 | 
				
			||||||
                f2, t2 = d[name]
 | 
					                f2, t2 = d[name]
 | 
				
			||||||
                f = f + f2
 | 
					                f = f + f2
 | 
				
			||||||
                t = t + t2
 | 
					                t = t + t2
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -169,6 +169,35 @@ def test_doctest_issue4197(self):
 | 
				
			||||||
            for obj in known_good_tests:
 | 
					            for obj in known_good_tests:
 | 
				
			||||||
                _run_object_doctest(obj, test_zipped_doctest)
 | 
					                _run_object_doctest(obj, test_zipped_doctest)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_doctest_main_issue4197(self):
 | 
				
			||||||
 | 
					        test_src = textwrap.dedent("""\
 | 
				
			||||||
 | 
					                    class Test:
 | 
				
			||||||
 | 
					                        ">>> 'line 2'"
 | 
				
			||||||
 | 
					                        pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    import doctest
 | 
				
			||||||
 | 
					                    doctest.testmod()
 | 
				
			||||||
 | 
					                    """)
 | 
				
			||||||
 | 
					        pattern = 'File "%s", line 2, in %s'
 | 
				
			||||||
 | 
					        with temp_dir() as d:
 | 
				
			||||||
 | 
					            script_name = _make_test_script(d, 'script', test_src)
 | 
				
			||||||
 | 
					            exit_code, data = _run_python(script_name)
 | 
				
			||||||
 | 
					            expected = pattern % (script_name, "__main__.Test")
 | 
				
			||||||
 | 
					            if verbose:
 | 
				
			||||||
 | 
					                print ("Expected line", expected)
 | 
				
			||||||
 | 
					                print ("Got stdout:")
 | 
				
			||||||
 | 
					                print (data)
 | 
				
			||||||
 | 
					            self.assert_(expected in data)
 | 
				
			||||||
 | 
					            zip_name, run_name = _make_test_zip(d, "test_zip",
 | 
				
			||||||
 | 
					                                                script_name, '__main__.py')
 | 
				
			||||||
 | 
					            exit_code, data = _run_python(zip_name)
 | 
				
			||||||
 | 
					            expected = pattern % (run_name, "__main__.Test")
 | 
				
			||||||
 | 
					            if verbose:
 | 
				
			||||||
 | 
					                print ("Expected line", expected)
 | 
				
			||||||
 | 
					                print ("Got stdout:")
 | 
				
			||||||
 | 
					                print (data)
 | 
				
			||||||
 | 
					            self.assert_(expected in data)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_pdb_issue4201(self):
 | 
					    def test_pdb_issue4201(self):
 | 
				
			||||||
        test_src = textwrap.dedent("""\
 | 
					        test_src = textwrap.dedent("""\
 | 
				
			||||||
                    def f():
 | 
					                    def f():
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue