pytest-dev#8204 migrate tests on testing/code/test_source to tmp_path
This commit is contained in:
		
							parent
							
								
									7585221d55
								
							
						
					
					
						commit
						ac428f67eb
					
				| 
						 | 
					@ -17,6 +17,7 @@ from _pytest._code import Code
 | 
				
			||||||
from _pytest._code import Frame
 | 
					from _pytest._code import Frame
 | 
				
			||||||
from _pytest._code import getfslineno
 | 
					from _pytest._code import getfslineno
 | 
				
			||||||
from _pytest._code import Source
 | 
					from _pytest._code import Source
 | 
				
			||||||
 | 
					from _pytest.pathlib import import_path
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_source_str_function() -> None:
 | 
					def test_source_str_function() -> None:
 | 
				
			||||||
| 
						 | 
					@ -285,7 +286,9 @@ def test_deindent() -> None:
 | 
				
			||||||
    assert lines == ["def f():", "    def g():", "        pass"]
 | 
					    assert lines == ["def f():", "    def g():", "        pass"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_source_of_class_at_eof_without_newline(tmpdir, _sys_snapshot) -> None:
 | 
					def test_source_of_class_at_eof_without_newline(
 | 
				
			||||||
 | 
					    tmpdir, _sys_snapshot, tmp_path: Path
 | 
				
			||||||
 | 
					) -> None:
 | 
				
			||||||
    # this test fails because the implicit inspect.getsource(A) below
 | 
					    # this test fails because the implicit inspect.getsource(A) below
 | 
				
			||||||
    # does not return the "x = 1" last line.
 | 
					    # does not return the "x = 1" last line.
 | 
				
			||||||
    source = Source(
 | 
					    source = Source(
 | 
				
			||||||
| 
						 | 
					@ -295,9 +298,10 @@ def test_source_of_class_at_eof_without_newline(tmpdir, _sys_snapshot) -> None:
 | 
				
			||||||
                x = 1
 | 
					                x = 1
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    path = tmpdir.join("a.py")
 | 
					    path = tmp_path.joinpath("a.py")
 | 
				
			||||||
    path.write(source)
 | 
					    path.write_text(str(source))
 | 
				
			||||||
    s2 = Source(tmpdir.join("a.py").pyimport().A)
 | 
					    mod: Any = import_path(path)
 | 
				
			||||||
 | 
					    s2 = Source(mod.A)
 | 
				
			||||||
    assert str(source).strip() == str(s2).strip()
 | 
					    assert str(source).strip() == str(s2).strip()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue