From fd23946de34e578eef89c9eb2f0822f3ff451657 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Sun, 1 Mar 2020 01:12:47 +0100 Subject: [PATCH] Avoid universal newlines even more --- test/refactor.py | 5 ++++- test/run.py | 2 +- test/test_api/test_environment.py | 4 ++-- test/test_api/test_refactoring.py | 2 +- test/test_inference/test_pyc.py | 6 +++--- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/test/refactor.py b/test/refactor.py index e82c582b..9c8d879a 100644 --- a/test/refactor.py +++ b/test/refactor.py @@ -9,6 +9,7 @@ from __future__ import with_statement import os import platform import re +import sys from parso import split_lines @@ -90,12 +91,14 @@ def _collect_file_tests(code, path, lines_to_execute): def collect_dir_tests(base_dir, test_files): + if sys.version_info[0] == 2: + return for f_name in os.listdir(base_dir): files_to_execute = [a for a in test_files.items() if a[0] in f_name] lines_to_execute = reduce(lambda x, y: x + y[1], files_to_execute, []) if f_name.endswith(".py") and (not test_files or files_to_execute): path = os.path.join(base_dir, f_name) - with open(path) as f: + with open(path, newline='') as f: code = f.read() for case in _collect_file_tests(code, path, lines_to_execute): yield case diff --git a/test/run.py b/test/run.py index 2f4dfc61..2bc9e1e2 100755 --- a/test/run.py +++ b/test/run.py @@ -411,7 +411,7 @@ def collect_dir_tests(base_dir, test_files, check_thirdparty=False): path = os.path.join(base_dir, f_name) if is_py3: - with open(path, encoding='utf-8') as f: + with open(path, encoding='utf-8', newline='') as f: source = f.read() else: with open(path) as f: diff --git a/test/test_api/test_environment.py b/test/test_api/test_environment.py index bf3d5674..0baf3fb8 100644 --- a/test/test_api/test_environment.py +++ b/test/test_api/test_environment.py @@ -118,9 +118,9 @@ def test_create_environment_executable(): assert environment.executable == sys.executable -def test_get_default_environment_from_env_does_not_use_safe(tmpdir, monkeypatch): +def test_get_default_environment_from_env_does_not_use_safe(tmpdir, monkeypatch, skip_python2): fake_python = os.path.join(str(tmpdir), 'fake_python') - with open(fake_python, 'w') as f: + with open(fake_python, 'w', newline='') as f: f.write('') def _get_subprocess(self): diff --git a/test/test_api/test_refactoring.py b/test/test_api/test_refactoring.py index b43e7834..a40acd13 100644 --- a/test/test_api/test_refactoring.py +++ b/test/test_api/test_refactoring.py @@ -33,7 +33,7 @@ def test_rename_mod(Script, dir_with_content): p2 = os.path.join(dir_with_content, 'modr.py') expected_code = 'import modr\nfoo\n' assert not os.path.exists(p1) - with open(p2) as f: + with open(p2, newline='') as f: assert f.read() == expected_code assert refactoring.get_renames() == [(p1, p2)] diff --git a/test/test_inference/test_pyc.py b/test/test_inference/test_pyc.py index 35d51327..bc8de391 100644 --- a/test/test_inference/test_pyc.py +++ b/test/test_inference/test_pyc.py @@ -25,15 +25,15 @@ class Bar: @pytest.fixture -def pyc_project_path(tmpdir): +def pyc_project_path(tmpdir, skip_python2): path = tmpdir.strpath dummy_package_path = os.path.join(path, "dummy_package") os.mkdir(dummy_package_path) - with open(os.path.join(dummy_package_path, "__init__.py"), 'w'): + with open(os.path.join(dummy_package_path, "__init__.py"), 'w', newline=''): pass dummy_path = os.path.join(dummy_package_path, 'dummy.py') - with open(dummy_path, 'w') as f: + with open(dummy_path, 'w', newline='') as f: f.write(SRC) import compileall compileall.compile_file(dummy_path)