Implement all remaining Path issues and use it instead of strings

This commit is contained in:
Dave Halter
2020-07-12 01:14:00 +02:00
parent db0e90763b
commit 480a464179
23 changed files with 131 additions and 97 deletions

View File

@@ -1,5 +1,6 @@
import os
from textwrap import dedent
from pathlib import Path
import pytest
@@ -10,22 +11,22 @@ import jedi
def dir_with_content(tmpdir):
with open(os.path.join(tmpdir.strpath, 'modx.py'), 'w', newline='') as f:
f.write('import modx\nfoo\n') # self reference
return tmpdir.strpath
return Path(tmpdir.strpath)
def test_rename_mod(Script, dir_with_content):
script = Script(
'import modx; modx\n',
path=os.path.join(dir_with_content, 'some_script.py'),
path=dir_with_content.joinpath('some_script.py'),
project=jedi.Project(dir_with_content),
)
refactoring = script.rename(line=1, new_name='modr')
refactoring.apply()
p1 = os.path.join(dir_with_content, 'modx.py')
p2 = os.path.join(dir_with_content, 'modr.py')
p1 = dir_with_content.joinpath('modx.py')
p2 = dir_with_content.joinpath('modr.py')
expected_code = 'import modr\nfoo\n'
assert not os.path.exists(p1)
assert not p1.exists()
with open(p2, newline='') as f:
assert f.read() == expected_code