Commit 1d1e6c7f authored by Jérome Perrin's avatar Jérome Perrin

support python2 in test

parent 80a38d1f
......@@ -13,7 +13,7 @@ import pytest
def file_system_script(tmp_path):
p = tmp_path / 'script.py'
p.write_text(
'''\
u'''\
if "a" == "a" and "b" == "c":
_ = 1 / 0 # will not be covered
......@@ -28,7 +28,7 @@ return 'returned value'
@contextlib.contextmanager
def _coverage_process(file_system_script, branch):
cwd = os.getcwd()
os.chdir(file_system_script.parent)
os.chdir(str(file_system_script.parent))
cp = coverage.Coverage(include=['./*'], branch=branch)
cp.set_option('run:plugins', ['erp5_coverage_plugin'])
cp.start()
......@@ -56,14 +56,14 @@ def python_script(file_system_script):
# script
ps._erp5_coverage_filename = str(file_system_script.absolute())
ps.ZPythonScript_edit('', file_system_script.read_text())
ps.ZPythonScript_edit('', file_system_script.open())
yield ps.__of__(makerequest(DummyFolder('folder')))
@pytest.fixture()
def python_script_with_callback(file_system_script):
file_system_script.write_text(
'''\
u'''\
result_storage = []
def callback_function(result):
result_storage.append(result)
......@@ -73,7 +73,7 @@ return result_storage
source_code_folder = file_system_script.parent
callback_file_system_script = source_code_folder / 'callback.py'
callback_file_system_script.write_text(
'''\
u'''\
callback_function("returned value")
''')
......@@ -85,9 +85,9 @@ callback_function("returned value")
test_script._erp5_coverage_filename = str(file_system_script.absolute())
callback_script._erp5_coverage_filename = str(callback_file_system_script.absolute())
test_script.ZPythonScript_edit('', file_system_script.read_text())
test_script.ZPythonScript_edit('', file_system_script.open())
callback_script.ZPythonScript_edit(
'callback_function', callback_file_system_script.read_text())
'callback_function', callback_file_system_script.open())
folder = makerequest(DummyFolder('folder'))
yield test_script.__of__(folder), callback_script.__of__(folder)
......@@ -118,7 +118,7 @@ script.py 4 1 2 1 67%
TOTAL 4 1 2 1 67%
'''
outfile = tmp_path / 'out.json'
assert coverage_process_with_branch_coverage.json_report(outfile=outfile) > 0
assert coverage_process_with_branch_coverage.json_report(outfile=str(outfile)) > 0
script_py_report = json.loads(outfile.read_text())['files']['script.py']
script_py_report.pop('summary')
assert script_py_report == {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment