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 5f25e81c09783eeb8c682fd33d3178b99352f6e0..653dc8c483757152506c7ca68bae714c13147c78 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.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!") os.remove('test.txt') diff --git a/debug/accuracy_tools/ptdbg_ascend/configure.py b/debug/accuracy_tools/ptdbg_ascend/configure.py index 7a3f87c08ef8973715ac016a312db1fffef4c359..7461dd4595bbd388ace226835399d60141533fcc 100644 --- a/debug/accuracy_tools/ptdbg_ascend/configure.py +++ b/debug/accuracy_tools/ptdbg_ascend/configure.py @@ -88,9 +88,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 61fc4ddf94c8e295b08c395f21776ac0f05f5c61..ec7ddf8d01ff0a0bc463d5781bf1cfdb04482e7d 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)