Skip to content

Commit

Permalink
tests: fix path separators in tests for Windows CI
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Jan 30, 2020
1 parent c4aab3b commit 6cbc2b3
Showing 1 changed file with 32 additions and 30 deletions.
62 changes: 32 additions & 30 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def test_cli_run_args(runner, mocker, devnull, tmpdir):
'tests/test_plugin/conditional_function.vim')),
'Not writing coverage file: no data to report!']

profiled_file = 'tests/test_plugin/conditional_function.vim'
profiled_file = os.path.normpath('tests/test_plugin/conditional_function.vim')
profiled_file_content = open(profiled_file, 'r').read()
with tmpdir.as_cwd() as old_dir:
profile_file = str(old_dir.join(
Expand Down Expand Up @@ -205,7 +205,7 @@ def test_cli_run_subprocess_wait_exception(runner, mocker, devnull, tmpdir):

@pytest.mark.parametrize('with_append', (True, False))
def test_cli_run_can_skip_writing_data(with_append, runner, tmpdir):
profiled_file = 'tests/test_plugin/conditional_function.vim'
profiled_file = os.path.normpath('tests/test_plugin/conditional_function.vim')
profiled_file_content = open(profiled_file, 'r').read()
with tmpdir.as_cwd() as old_dir:
profile_file = str(old_dir.join(
Expand All @@ -221,12 +221,12 @@ def test_cli_run_can_skip_writing_data(with_append, runner, tmpdir):
'Parsing profile file %s.' % profile_file,
'Name Stmts Miss Cover',
'----------------------------------------------------------------',
'tests/test_plugin/conditional_function.vim 13 5 62%']
'%s 13 5 62%%' % profiled_file]
assert not tmpdir.join(DEFAULT_COVERAGE_DATA_FILE).exists()


def test_cli_write_coverage_with_append(runner, tmpdir, covdata_header):
profiled_file = 'tests/test_plugin/conditional_function.vim'
profiled_file = os.path.normpath('tests/test_plugin/conditional_function.vim')
profiled_file_content = open(profiled_file, 'r').read()
with tmpdir.as_cwd() as old_dir:
profile_file = str(old_dir.join(
Expand All @@ -249,25 +249,26 @@ def test_cli_write_coverage_with_append(runner, tmpdir, covdata_header):


def test_cli_run_report_fd(capfd, tmpdir, devnull):
profile_fname = 'tests/fixtures/conditional_function.profile'
profile_fname = os.path.normpath('tests/fixtures/conditional_function.profile')
with open(profile_fname, 'r') as f:
profile_lines = f.readlines()
profile_lines[0] = 'SCRIPT tests/test_plugin/conditional_function.vim\n'
profile_lines[0] = 'SCRIPT %s\n' % profile_fname

tmp_profile_fname = str(tmpdir.join('tmp.profile'))
with open(tmp_profile_fname, 'w') as f:
f.writelines(profile_lines)
data_file = str(tmpdir.join('datafile'))
source_file = os.path.normpath('tests/test_plugin/conditional_function.vim')
args = ['--no-wrap-profile', '--profile-file', tmp_profile_fname,
'--source', 'tests/test_plugin/conditional_function.vim',
'--source', source_file,
'--data-file', data_file, 'true']
exit_code = call(['covimerage', '--rcfile', devnull.name, 'run'] + args)
out, err = capfd.readouterr()
assert exit_code == 0, err
assert out.splitlines() == [
'Name Stmts Miss Cover',
'----------------------------------------------------------------',
'tests/test_plugin/conditional_function.vim 13 5 62%']
'%s 13 5 62%%' % source_file]
assert err.splitlines() == [
'Running cmd: true (in %s)' % str(os.getcwd()),
'Parsing profile file %s.' % tmp_profile_fname,
Expand All @@ -286,7 +287,7 @@ def test_cli_run_report_fd(capfd, tmpdir, devnull):
assert open(ofname).read().splitlines() == [
'Name Stmts Miss Cover',
'----------------------------------------------------------------',
'tests/test_plugin/conditional_function.vim 13 5 62%']
'%s 13 5 62%%' % source_file]


def test_cli_call(capfd):
Expand Down Expand Up @@ -370,7 +371,7 @@ def test_cli_writecoverage_datafile(runner):

fname = tempfile.mktemp()
result = runner.invoke(cli.main, ['write_coverage', '--data-file', fname,
'tests/fixtures/conditional_function.profile'])
os.path.normpath('tests/fixtures/conditional_function.profile')])
assert result.output == '\n'.join([
'Writing coverage file %s.' % fname,
''])
Expand All @@ -388,7 +389,7 @@ def test_cli_writecoverage_source(runner, devnull):
fname = tempfile.mktemp()
result = runner.invoke(cli.main, [
'write_coverage', '--data-file', fname, '--source', '.',
'tests/fixtures/conditional_function.profile'])
os.path.normpath('tests/fixtures/conditional_function.profile')])
assert result.output == '\n'.join([
'Writing coverage file %s.' % fname,
''])
Expand All @@ -407,9 +408,9 @@ def test_coverage_plugin_for_annotate_merged_conditionals(runner, capfd,
tmpfile = str(tmpdir.join('.coverage'))
result = runner.invoke(cli.main, [
'write_coverage', '--data-file', tmpfile,
'tests/fixtures/merged_conditionals-0.profile',
'tests/fixtures/merged_conditionals-1.profile',
'tests/fixtures/merged_conditionals-2.profile'])
os.path.normpath('tests/fixtures/merged_conditionals-0.profile'),
os.path.normpath('tests/fixtures/merged_conditionals-1.profile'),
os.path.normpath('tests/fixtures/merged_conditionals-2.profile')])
assert result.output == '\n'.join([
'Writing coverage file %s.' % tmpfile,
''])
Expand Down Expand Up @@ -507,16 +508,16 @@ def test_report_profile_or_data_file(runner, tmpdir):

result = runner.invoke(cli.main, [
'--rcfile', os.devnull,
'report', 'tests/fixtures/merged_conditionals-0.profile'])
'report', os.path.normpath('tests/fixtures/merged_conditionals-0.profile')])
assert result.output.splitlines() == [
'Name Stmts Miss Cover',
'---------------------------------------------------------------',
'tests/test_plugin/merged_conditionals.vim 19 12 37%']
'%s 19 12 37%%' % 'tests/test_plugin/merged_conditionals.vim']
assert result.exit_code == 0


def test_report_rcfile_and_include(tmpdir, runner):
profiled_file = 'tests/test_plugin/conditional_function.vim'
profiled_file = os.path.normpath('tests/test_plugin/conditional_function.vim')
profiled_file_content = open(profiled_file, 'r').read()

# Works without rcfile.
Expand Down Expand Up @@ -575,23 +576,24 @@ def test_report_source(runner, tmpdir, devnull):
assert out[-1] == "Error: --source can only be used with PROFILE_FILE."
assert result.exit_code == 2

source_file = os.path.normpath("tests/test_plugin/merged_conditionals.vim")
result = runner.invoke(
cli.main,
[
"--rcfile",
devnull.name,
"report",
"--source",
"tests/test_plugin/merged_conditionals.vim",
"tests/fixtures/merged_conditionals-0.profile",
source_file,
os.path.normpath("tests/fixtures/merged_conditionals-0.profile"),
],
)
assert (
result.output.splitlines()
== [
"Name Stmts Miss Cover",
"---------------------------------------------------------------",
"tests/test_plugin/merged_conditionals.vim 19 12 37%",
"%s 19 12 37%" % source_file,
]
)
assert result.exit_code == 0
Expand All @@ -601,16 +603,16 @@ def test_cli_xml(runner, tmpdir):
"""Smoke test for the xml command."""
result = runner.invoke(cli.main, [
'write_coverage', '--data-file', str(tmpdir.join('.coverage')),
'tests/fixtures/merged_conditionals-0.profile'])
os.path.normpath('tests/fixtures/merged_conditionals-0.profile')])
with tmpdir.as_cwd() as old_cwd:
result = runner.invoke(cli.main, [
'xml', '--data-file', '.coverage'])
assert result.exit_code == 0

with open('coverage.xml') as f:
xml = f.read()
assert 'filename="%s/tests/test_plugin/merged_conditionals.vim' % (
old_cwd) in xml
source_file = os.path.normpath('/tests/test_plugin/merged_conditionals.vim')
assert 'filename="%s%s' % (old_cwd, source_file) in xml

# --rcfile is used.
coveragerc = 'customrc'
Expand All @@ -624,8 +626,7 @@ def test_cli_xml(runner, tmpdir):
assert result.exit_code == 0
with open('custom.xml') as f:
xml = f.read()
assert 'filename="%s/tests/test_plugin/merged_conditionals.vim' % (
old_cwd) in xml
assert 'filename="%s%s' % (old_cwd, source_file) in xml

# --rcfile is used.
coveragerc = 'customrc'
Expand Down Expand Up @@ -700,7 +701,7 @@ def test_run_append_with_empty_data(runner, tmpdir):

@pytest.mark.parametrize('with_data_file', (True, False))
def test_run_append_with_data(with_data_file, runner, tmpdir, covdata_header):
profiled_file = 'tests/test_plugin/conditional_function.vim'
profiled_file = os.path.normpath('tests/test_plugin/conditional_function.vim')
profiled_file_content = open(profiled_file, 'r').read()
tmpdir.join(profiled_file).write(profiled_file_content, ensure=True)

Expand All @@ -715,14 +716,15 @@ def run_args(profile_file):
with tmpdir.as_cwd() as old_dir:
profile_file = str(old_dir.join(
'tests/fixtures/conditional_function.profile'))
source_file = os.path.normpath('tests/test_plugin/conditional_function.vim')
result = runner.invoke(cli.run, run_args(profile_file))
assert result.output.splitlines() == [
'Running cmd: printf -- --headless (in %s)' % str(tmpdir),
'Parsing profile file %s.' % profile_file,
'Writing coverage file .coverage_covimerage.',
'Name Stmts Miss Cover',
'----------------------------------------------------------------',
'tests/test_plugin/conditional_function.vim 13 5 62%']
'%s 13 5 62%%' % source_file]
assert result.exit_code == 0

assert open('.coverage_covimerage').read().startswith(covdata_header)
Expand All @@ -735,7 +737,7 @@ def run_args(profile_file):
'Writing coverage file .coverage_covimerage.',
'Name Stmts Miss Cover',
'----------------------------------------------------------------',
'tests/test_plugin/conditional_function.vim 13 5 62%']
'%s 13 5 62%%' % source_file]
assert result.exit_code == 0

# Append another profile.
Expand All @@ -753,8 +755,8 @@ def run_args(profile_file):
'Writing coverage file .coverage_covimerage.',
'Name Stmts Miss Cover',
'----------------------------------------------------------------',
'tests/test_plugin/conditional_function.vim 13 5 62%',
'tests/test_plugin/merged_conditionals.vim 19 12 37%',
'%s 13 5 62%%' % source_file,
'%s 19 12 37%%' % os.path.normpath('tests/test_plugin/merged_conditionals.vim'),
'----------------------------------------------------------------',
'TOTAL 32 17 47%']
assert result.exit_code == 0
Expand Down

0 comments on commit 6cbc2b3

Please sign in to comment.