diff --git a/tests/test_cli.py b/tests/test_cli.py index f4ccbbb..16f38af 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -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( @@ -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( @@ -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( @@ -249,17 +249,18 @@ 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() @@ -267,7 +268,7 @@ def test_cli_run_report_fd(capfd, tmpdir, devnull): 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, @@ -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): @@ -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, '']) @@ -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, '']) @@ -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, '']) @@ -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. @@ -575,6 +576,7 @@ 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, [ @@ -582,8 +584,8 @@ def test_report_source(runner, tmpdir, devnull): 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 ( @@ -591,7 +593,7 @@ def test_report_source(runner, tmpdir, devnull): == [ "Name Stmts Miss Cover", "---------------------------------------------------------------", - "tests/test_plugin/merged_conditionals.vim 19 12 37%", + "%s 19 12 37%" % source_file, ] ) assert result.exit_code == 0 @@ -601,7 +603,7 @@ 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']) @@ -609,8 +611,8 @@ def test_cli_xml(runner, tmpdir): 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' @@ -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' @@ -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) @@ -715,6 +716,7 @@ 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), @@ -722,7 +724,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 assert open('.coverage_covimerage').read().startswith(covdata_header) @@ -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. @@ -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