File pytest-mock.patch of Package python-natsort
From 3a3bd474bf97b3b3440a8fe8714072f730ddf365 Mon Sep 17 00:00:00 2001
From: Seth Morton <seth.m.morton@gmail.com>
Date: Mon, 6 Jan 2020 20:31:53 -0800
Subject: [PATCH] Fix bug caused by pytest-mocker API being removed
mocker.patch no longer supports context managers. Not sure why I was
using it in a context manager in the first place...
This closes issue #107.
---
tests/test_natsort_keygen.py | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
Index: natsort-6.0.0/tests/test_natsort_keygen.py
===================================================================
--- natsort-6.0.0.orig/tests/test_natsort_keygen.py
+++ natsort-6.0.0/tests/test_natsort_keygen.py
@@ -150,9 +150,9 @@ def test_natsort_keygen_with_locale(mock
expected[1][1][i] = strxfrm(expected[1][1][i])
expected = tuple(tuple(tuple(subsub) for subsub in sub) for sub in expected)
- with mocker.patch("natsort.compat.locale.dumb_sort", return_value=is_dumb):
- ns_key = natsort_keygen(alg=alg)
- assert ns_key(arbitrary_input) == expected
+ mocker.patch("natsort.compat.locale.dumb_sort", return_value=is_dumb)
+ ns_key = natsort_keygen(alg=alg)
+ assert ns_key(arbitrary_input) == expected
@pytest.mark.parametrize(
@@ -163,6 +163,6 @@ def test_natsort_keygen_with_locale(mock
@pytest.mark.usefixtures("with_locale_en_us")
def test_natsort_keygen_with_locale_bytes(mocker, bytes_input, alg, is_dumb):
expected = (b"6A-5.034e+1",)
- with mocker.patch("natsort.compat.locale.dumb_sort", return_value=is_dumb):
- ns_key = natsort_keygen(alg=alg)
- assert ns_key(bytes_input) == expected
+ mocker.patch("natsort.compat.locale.dumb_sort", return_value=is_dumb)
+ ns_key = natsort_keygen(alg=alg)
+ assert ns_key(bytes_input) == expected
Index: natsort-6.0.0/tests/test_natsort_cmp.py
===================================================================
--- natsort-6.0.0.orig/tests/test_natsort_cmp.py
+++ natsort-6.0.0/tests/test_natsort_cmp.py
@@ -44,17 +44,17 @@ class TestNatCmp:
natcmp(0, 0)
assert len(natcmp.cached_keys) == 1
- with mocker.patch("natsort.compat.locale.dumb_sort", return_value=False):
- natcmp(0, 0, alg=ns.L)
- assert len(natcmp.cached_keys) == 2
- natcmp(0, 0, alg=ns.L)
- assert len(natcmp.cached_keys) == 2
+ mocker.patch("natsort.compat.locale.dumb_sort", return_value=False)
+ natcmp(0, 0, alg=ns.L)
+ assert len(natcmp.cached_keys) == 2
+ natcmp(0, 0, alg=ns.L)
+ assert len(natcmp.cached_keys) == 2
- with mocker.patch("natsort.compat.locale.dumb_sort", return_value=True):
- natcmp(0, 0, alg=ns.L)
- assert len(natcmp.cached_keys) == 3
- natcmp(0, 0, alg=ns.L)
- assert len(natcmp.cached_keys) == 3
+ mocker.patch("natsort.compat.locale.dumb_sort", return_value=True)
+ natcmp(0, 0, alg=ns.L)
+ assert len(natcmp.cached_keys) == 3
+ natcmp(0, 0, alg=ns.L)
+ assert len(natcmp.cached_keys) == 3
def test_illegal_algorithm_raises_error(self):
with pytest.raises(ValueError):