Skip to content

Commit feb624b

Browse files
ludviggunnefirewave
andcommitted
Update test/cli/proj2_test.py
Co-authored-by: Oliver Stöneberg <firewave@users.noreply.github.com>
1 parent a9570ae commit feb624b

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

test/cli/proj2_test.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,24 +85,28 @@ def test_absolute_path(tmp_path):
8585
assert stdout.find('Checking %s ...' % file1) >= 0
8686
assert stdout.find('Checking %s ...' % file2) >= 0
8787

88-
def test_progress_json():
89-
size1 = os.path.getsize(os.path.join(__proj_dir, 'a', 'a.c'))
90-
size2 = os.path.getsize(os.path.join(__proj_dir, 'b', 'b.c'))
88+
def test_progress_json(tmp_path):
89+
proj_dir = tmp_path / 'proj2'
90+
shutil.copytree(__proj_dir, proj_dir)
91+
size1 = os.path.getsize(os.path.join(proj_dir, 'a', 'a.c'))
92+
size2 = os.path.getsize(os.path.join(proj_dir, 'b', 'b.c'))
9193
perc1 = 100 * size1 // (size1 + size2)
9294
perc2 = 100 * size2 // (size1 + size2)
93-
__create_compile_commands()
94-
ret, stdout, _ = cppcheck(['--project=' + os.path.join(__proj_dir, __COMPILE_COMMANDS_JSON)], cwd=__script_dir)
95+
__create_compile_commands(proj_dir)
96+
ret, stdout, _ = cppcheck(['--project=' + os.path.join(proj_dir, __COMPILE_COMMANDS_JSON)], cwd=tmp_path)
9597
assert ret == 0, stdout
9698
assert stdout.find('1/2 files checked %d%% done' % perc1) >= 0 or stdout.find('1/2 files checked %d%% done' % perc2) >= 0
9799
assert stdout.find('2/2 files checked 100% done') >= 0
98100

99-
def test_progress_cppcheck():
100-
size1 = os.path.getsize(os.path.join(__proj_dir, 'a', 'a.c'))
101-
size2 = os.path.getsize(os.path.join(__proj_dir, 'b', 'b.c'))
101+
def test_progress_cppcheck(tmp_path):
102+
proj_dir = tmp_path / 'proj2'
103+
shutil.copytree(__proj_dir, proj_dir)
104+
size1 = os.path.getsize(os.path.join(proj_dir, 'a', 'a.c'))
105+
size2 = os.path.getsize(os.path.join(proj_dir, 'b', 'b.c'))
102106
perc1 = 100 * size1 // (size1 + size2)
103107
perc2 = 100 * size2 // (size1 + size2)
104-
__create_compile_commands()
105-
ret, stdout, _ = cppcheck(['--project=proj2/proj2.cppcheck'], cwd=__script_dir)
108+
__create_compile_commands(proj_dir)
109+
ret, stdout, _ = cppcheck(['--project=proj2/proj2.cppcheck'], cwd=tmp_path)
106110
assert ret == 0, stdout
107111
assert stdout.find('1/2 files checked %d%% done' % perc1) >= 0 or stdout.find('1/2 files checked %d%% done' % perc2) >= 0
108112
assert stdout.find('2/2 files checked 100% done') >= 0

0 commit comments

Comments
 (0)