From 38da98d2d65d9df37671aba3f10fbbd080fadd4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Thu, 15 Aug 2019 18:43:31 +0300 Subject: [PATCH] Address @asottile's review comments --- pre_commit/languages/python.py | 1 - tests/languages/python_test.py | 9 +++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pre_commit/languages/python.py b/pre_commit/languages/python.py index df00a071..1585a7fc 100644 --- a/pre_commit/languages/python.py +++ b/pre_commit/languages/python.py @@ -66,7 +66,6 @@ def _find_by_sys_executable(): def _get_default_version(): # pragma: no cover (platform dependent) - # First attempt from `sys.executable` (or the realpath) exe = _find_by_sys_executable() diff --git a/tests/languages/python_test.py b/tests/languages/python_test.py index 4506f9f0..3634fa4f 100644 --- a/tests/languages/python_test.py +++ b/tests/languages/python_test.py @@ -7,6 +7,7 @@ import sys import mock import pytest +import pre_commit.parse_shebang from pre_commit.languages import python @@ -35,7 +36,7 @@ def test_sys_executable_matches_does_not_match(v): @pytest.mark.parametrize( - 'exe,realpath,expected', ( + ('exe', 'realpath', 'expected'), ( ('/usr/bin/python3', '/usr/bin/python3.7', 'python3'), ('/usr/bin/python', '/usr/bin/python3.7', 'python3.7'), ('/usr/bin/python', '/usr/bin/python', None), @@ -47,9 +48,9 @@ def test_find_by_sys_executable(exe, realpath, expected): def mocked_find_executable(exe): return exe.rpartition('/')[2] with mock.patch.object(sys, 'executable', exe): - with mock.patch('os.path.realpath', return_value=realpath): - with mock.patch( - 'pre_commit.parse_shebang.find_executable', + with mock.patch.object(os.path, 'realpath', return_value=realpath): + with mock.patch.object( + pre_commit.parse_shebang, 'find_executable', side_effect=mocked_find_executable, ): assert python._find_by_sys_executable() == expected