Skip to content

Commit 4a96f1f

Browse files
committed
Fix tests issue with new merged code from 1.3.x
The new code from 1.3.x fixed some potential issue of file writting in files.overwrite_file, however it breaks the tests of radas. Assisted by: Claude code
1 parent 58a33d1 commit 4a96f1f

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

tests/test_radas_sign_generation.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import os
2121
import json
2222
import shutil
23-
import builtins
2423
from unittest import mock
2524
from charon.utils.files import overwrite_file
2625
from charon.pkgs.radas_sign import generate_radas_sign
@@ -68,20 +67,14 @@ def test_sign_files_generation_with_failure(self):
6867
expected_asc1 = os.path.join(self.__repo_dir, "foo/bar/1.0/foo-bar-1.0.jar.asc")
6968
expected_asc2 = os.path.join(self.__repo_dir, "foo/bar/2.0/foo-bar-2.0.jar.asc")
7069

71-
# simulate expected_asc1 can not open to write properly
72-
real_open = builtins.open
73-
with mock.patch("builtins.open") as mock_open:
74-
def side_effect(path, *args, **kwargs):
75-
# this is for pylint check
76-
mode = "r"
77-
if len(args) > 0:
78-
mode = args[0]
79-
elif "mode" in kwargs:
80-
mode = kwargs["mode"]
81-
if path == expected_asc1 and "w" in mode:
70+
# simulate expected_asc1 can not be written properly
71+
real_overwrite = overwrite_file
72+
with mock.patch("charon.pkgs.radas_sign.files.overwrite_file") as mock_overwrite:
73+
def side_effect(path, content):
74+
if path == expected_asc1:
8275
raise IOError("mock write error")
83-
return real_open(path, *args, **kwargs)
84-
mock_open.side_effect = side_effect
76+
return real_overwrite(path, content)
77+
mock_overwrite.side_effect = side_effect
8578
failed, generated = generate_radas_sign(self.__repo_dir, self.__sign_result_file)
8679

8780
self.assertEqual(len(failed), 1)

0 commit comments

Comments
 (0)