Skip to content

Commit 75f0812

Browse files
Update test/cli/proj2_test.py
Co-authored-by: Oliver Stöneberg <firewave@users.noreply.github.com>
1 parent 46369cc commit 75f0812

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

test/cli/proj2_test.py

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

76-
def test_progress_json():
77-
size1 = os.path.getsize(os.path.join(__proj_dir, 'a', 'a.c'))
78-
size2 = os.path.getsize(os.path.join(__proj_dir, 'b', 'b.c'))
76+
def test_progress_json(tmp_path):
77+
proj_dir = tmp_path / 'proj2'
78+
shutil.copytree(__proj_dir, proj_dir)
79+
size1 = os.path.getsize(os.path.join(proj_dir, 'a', 'a.c'))
80+
size2 = os.path.getsize(os.path.join(proj_dir, 'b', 'b.c'))
7981
perc1 = 100 * size1 // (size1 + size2)
8082
perc2 = 100 * size2 // (size1 + size2)
81-
__create_compile_commands()
82-
ret, stdout, _ = cppcheck(['--project=' + os.path.join(__proj_dir, __COMPILE_COMMANDS_JSON)], cwd=__script_dir)
83+
__create_compile_commands(proj_dir)
84+
ret, stdout, _ = cppcheck(['--project=' + os.path.join(proj_dir, __COMPILE_COMMANDS_JSON)], cwd=tmp_path)
8385
assert ret == 0, stdout
8486
assert stdout.find('1/2 files checked %d%% done' % perc1) >= 0 or stdout.find('1/2 files checked %d%% done' % perc2) >= 0
8587
assert stdout.find('2/2 files checked 100% done') >= 0
8688

87-
def test_progress_cppcheck():
88-
size1 = os.path.getsize(os.path.join(__proj_dir, 'a', 'a.c'))
89-
size2 = os.path.getsize(os.path.join(__proj_dir, 'b', 'b.c'))
89+
def test_progress_cppcheck(tmp_path):
90+
proj_dir = tmp_path / 'proj2'
91+
shutil.copytree(__proj_dir, proj_dir)
92+
size1 = os.path.getsize(os.path.join(proj_dir, 'a', 'a.c'))
93+
size2 = os.path.getsize(os.path.join(proj_dir, 'b', 'b.c'))
9094
perc1 = 100 * size1 // (size1 + size2)
9195
perc2 = 100 * size2 // (size1 + size2)
92-
__create_compile_commands()
93-
ret, stdout, _ = cppcheck(['--project=proj2/proj2.cppcheck'], cwd=__script_dir)
96+
__create_compile_commands(proj_dir)
97+
ret, stdout, _ = cppcheck(['--project=proj2/proj2.cppcheck'], cwd=tmp_path)
9498
assert ret == 0, stdout
9599
assert stdout.find('1/2 files checked %d%% done' % perc1) >= 0 or stdout.find('1/2 files checked %d%% done' % perc2) >= 0
96100
assert stdout.find('2/2 files checked 100% done') >= 0

0 commit comments

Comments
 (0)