From b5abd9bd8858a52e517f343e2b9a2c68271b3852 Mon Sep 17 00:00:00 2001 From: gitee Date: Thu, 9 May 2024 17:32:53 +0800 Subject: [PATCH 1/3] fix --- .../test/ut/common/test_common_utils.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/debug/accuracy_tools/api_accuracy_checker/test/ut/common/test_common_utils.py b/debug/accuracy_tools/api_accuracy_checker/test/ut/common/test_common_utils.py index 5f25e81c0..c2b77ee46 100644 --- a/debug/accuracy_tools/api_accuracy_checker/test/ut/common/test_common_utils.py +++ b/debug/accuracy_tools/api_accuracy_checker/test/ut/common/test_common_utils.py @@ -8,7 +8,8 @@ class TestUtils(unittest.TestCase): def test_read_json(self): test_dict = {"key": "value"} - with open('test.json', 'w') as f: + fd = os.open('test.json', os.O_CREAT | os.O_WRONLY | os.O_TRUNC, 0o644) + with os.fdopen(fd, 'w') as f: json.dump(test_dict, f) self.assertEqual(read_json('test.json'), test_dict) os.remove('test.json') @@ -97,13 +98,15 @@ class TestUtils(unittest.TestCase): def test_get_json_contents(self): test_dict = {"key": "value"} - with open('test.json', 'w') as f: + fd = os.open('test.json', os.O_CREAT | os.O_WRONLY | os.O_TRUNC, 0o644) + with os.fdopen(fd, 'w') as f: json.dump(test_dict, f) self.assertEqual(get_json_contents('test.json'), test_dict) os.remove('test.json') def test_get_file_content_bytes(self): - with open('test.txt', 'w') as f: + fd = os.open('test.json', os.O_CREAT | os.O_WRONLY | os.O_TRUNC, 0o644) + with os.fdopen(fd, 'w') as f: f.write("Hello, World!") self.assertEqual(get_file_content_bytes('test.txt'), b"Hello, World!") os.remove('test.txt') -- Gitee From da4a3b5f711fce10b7f1fc5e49017eadbc26ab05 Mon Sep 17 00:00:00 2001 From: gitee Date: Thu, 9 May 2024 20:18:15 +0800 Subject: [PATCH 2/3] fix --- debug/accuracy_tools/ptdbg_ascend/configure.py | 6 ++++-- .../src/python/ptdbg_ascend/common/file_check_util.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/debug/accuracy_tools/ptdbg_ascend/configure.py b/debug/accuracy_tools/ptdbg_ascend/configure.py index 3508896fb..42e77724d 100644 --- a/debug/accuracy_tools/ptdbg_ascend/configure.py +++ b/debug/accuracy_tools/ptdbg_ascend/configure.py @@ -90,9 +90,11 @@ def setup_python(env_path): print('Pytorch is not installed or does not work properly.') continue # Write tools/python_bin_path.sh - with open(config_path('PYTHON_BIN_PATH'), 'w') as f: + fd = os.open(config_path('PYTHON_BIN_PATH'), os.O_CREAT | os.O_WRONLY | os.O_TRUNC, 0o644) + with os.fdopen(fd, 'w') as f: f.write(python_bin_path) - with open(config_path('PYTORCH_INSTALLED_PATH'), 'w') as f: + fd = os.open(config_path('PYTORCH_INSTALLED_PATH'), os.O_CREAT | os.O_WRONLY | os.O_TRUNC, 0o644) + with os.fdopen(fd, 'w') as f: f.write(compile_args[1]) break diff --git a/debug/accuracy_tools/ptdbg_ascend/src/python/ptdbg_ascend/common/file_check_util.py b/debug/accuracy_tools/ptdbg_ascend/src/python/ptdbg_ascend/common/file_check_util.py index 61fc4ddf9..ec7ddf8d0 100644 --- a/debug/accuracy_tools/ptdbg_ascend/src/python/ptdbg_ascend/common/file_check_util.py +++ b/debug/accuracy_tools/ptdbg_ascend/src/python/ptdbg_ascend/common/file_check_util.py @@ -253,7 +253,7 @@ def check_path_owner_consistent(path): def check_path_pattern_vaild(path): if not re.match(FileCheckConst.FILE_VALID_PATTERN, path): - print_error_log('The file path {} contains special characters.'.format(path)) + print_error_log('The file path %s contains special characters.' % path) raise FileCheckException(FileCheckException.INVALID_PATH_ERROR) -- Gitee From e4450aa2bad593e2d955680b11612c2fe17a49fd Mon Sep 17 00:00:00 2001 From: gitee Date: Fri, 10 May 2024 11:00:32 +0800 Subject: [PATCH 3/3] fix --- .../api_accuracy_checker/test/ut/common/test_common_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debug/accuracy_tools/api_accuracy_checker/test/ut/common/test_common_utils.py b/debug/accuracy_tools/api_accuracy_checker/test/ut/common/test_common_utils.py index c2b77ee46..653dc8c48 100644 --- a/debug/accuracy_tools/api_accuracy_checker/test/ut/common/test_common_utils.py +++ b/debug/accuracy_tools/api_accuracy_checker/test/ut/common/test_common_utils.py @@ -105,7 +105,7 @@ class TestUtils(unittest.TestCase): os.remove('test.json') def test_get_file_content_bytes(self): - fd = os.open('test.json', os.O_CREAT | os.O_WRONLY | os.O_TRUNC, 0o644) + fd = os.open('test.txt', os.O_CREAT | os.O_WRONLY | os.O_TRUNC, 0o644) with os.fdopen(fd, 'w') as f: f.write("Hello, World!") self.assertEqual(get_file_content_bytes('test.txt'), b"Hello, World!") -- Gitee