From d5436da67c13dcdf29284e412c618421804dbbac Mon Sep 17 00:00:00 2001 From: Antares Date: Sun, 31 Mar 2024 00:32:03 +0800 Subject: [PATCH] fix: Fix file encoding issues in setup.py and test files --- setup.py | 2 +- test/benchmark_test.py | 4 ++-- test/decode_test.py | 2 +- test/encode_test.py | 2 +- test/memory_test.py | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/setup.py b/setup.py index 34a4770..5abad11 100644 --- a/setup.py +++ b/setup.py @@ -29,7 +29,7 @@ def find_src(): extra_link_args=["-lstdc++", "-lm"] + strip_flags, ) -with open("src/version_template.h") as f: +with open("src/version_template.h", encoding='utf-8') as f: version_template = f.read() diff --git a/test/benchmark_test.py b/test/benchmark_test.py index ee772eb..f223563 100644 --- a/test/benchmark_test.py +++ b/test/benchmark_test.py @@ -29,7 +29,7 @@ def test_benchmark_encode(self): for filename in bench_files: base_name = os.path.basename(filename) - with open(filename, "r") as f: + with open(filename, "r", encoding='utf-8') as f: data = json.load(f) time_std = self.time_benchmark(1000, json.dumps, data, indent=None, ensure_ascii=False) print(f"test encode, file: {base_name}, time_std: {time_std}") @@ -45,7 +45,7 @@ def test_benchmark_decode(self): for filename in bench_files: base_name = os.path.basename(filename) - with open(filename, "r") as f: + with open(filename, "r", encoding='utf-8') as f: data = f.read() time_std = self.time_benchmark(1000, json.loads, data) print(f"test decode, file: {base_name}, time_std: {time_std}") diff --git a/test/decode_test.py b/test/decode_test.py index 4ccd052..1abfca0 100644 --- a/test/decode_test.py +++ b/test/decode_test.py @@ -87,7 +87,7 @@ def test_decode(self): test_cases = [json.dumps(case, ensure_ascii=False) for case in test_cases_origin] for bench_file in bench_files: - with open(bench_file, "r") as f: + with open(bench_file, "r", encoding='utf-8') as f: test_cases.append(f.read()) for case in test_cases: diff --git a/test/encode_test.py b/test/encode_test.py index 0aef866..bc57cac 100644 --- a/test/encode_test.py +++ b/test/encode_test.py @@ -109,7 +109,7 @@ def test_encode(self): ] for file in self._get_benchfiles_fullpath(): - with open(file, "r") as f: + with open(file, "r", encoding='utf-8') as f: test_cases.append(json.load(f)) for case in test_cases: diff --git a/test/memory_test.py b/test/memory_test.py index 91a8588..f9a5606 100644 --- a/test/memory_test.py +++ b/test/memory_test.py @@ -152,7 +152,7 @@ def test_decode_leak(self): datas = [] for file in self._get_benchfiles_fullpath(): - with open(file, "r") as f: + with open(file, "r", encoding='utf-8') as f: datas.append(f.read()) # warm up. CPython will not release memory immediately.