From 3428772e1a605e1ad9fcb0db9a16d3451bdc2e9e Mon Sep 17 00:00:00 2001 From: Reid Hayes Date: Sat, 31 Oct 2020 10:07:21 -0400 Subject: [PATCH] Fix test_supervised_util_test for python3 Fixes errors like this testing in python3: ``` ====================================================================== ERROR: test_supervised_util_test_0 (fasttext.tests.test_script.TestFastTextUnitPy) ---------------------------------------------------------------------- Traceback (most recent call last): File "/build/work/003c13a04323e5dc26c2c02cd9c8df29e6c6/google3/runfiles/google3/third_party/py/fasttext/tests/test_script.py", line 590, in test "gen_" + test_name)(self, copy.deepcopy(kwargs)) File "/build/work/003c13a04323e5dc26c2c02cd9c8df29e6c6/google3/runfiles/google3/third_party/py/fasttext/tests/test_script.py", line 229, in gen_test_supervised_util_test check(get_random_data(100, min_words_line=2)) File "/build/work/003c13a04323e5dc26c2c02cd9c8df29e6c6/google3/runfiles/google3/third_party/py/fasttext/tests/test_script.py", line 210, in check for line in fid: File "/encodings/ascii.py", line 26, in decode return codecs.ascii_decode(input, self.errors)[0] UnicodeDecodeError: 'ascii' codec can't decode byte 0xc7 in position 9: ordinal not in range(128) ``` --- python/fasttext_module/fasttext/tests/test_script.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/fasttext_module/fasttext/tests/test_script.py b/python/fasttext_module/fasttext/tests/test_script.py index a41515ad0..72075920e 100644 --- a/python/fasttext_module/fasttext/tests/test_script.py +++ b/python/fasttext_module/fasttext/tests/test_script.py @@ -206,7 +206,7 @@ def check(data): model = train_supervised(input=tmpf.name, **kwargs) true_labels = [] all_words = [] - with open(tmpf2.name, 'r') as fid: + with open(tmpf2.name, 'r', encoding="UTF-8") as fid: for line in fid: if sys.version_info < (3, 0): line = line.decode("UTF-8")