mirror of
https://github.com/nvbn/thefuck.git
synced 2025-04-19 01:00:42 +01:00
#N/A Add ability to disable memoization in tests
This commit is contained in:
parent
4b4e7acc0f
commit
f40b63f44b
@ -2,7 +2,7 @@ import pytest
|
|||||||
from mock import Mock
|
from mock import Mock
|
||||||
from thefuck.utils import sudo_support, wrap_settings, memoize, get_closest
|
from thefuck.utils import sudo_support, wrap_settings, memoize, get_closest
|
||||||
from thefuck.types import Settings
|
from thefuck.types import Settings
|
||||||
from tests.utils import Command
|
from tests.utils import Command, no_memoize
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('override, old, new', [
|
@pytest.mark.parametrize('override, old, new', [
|
||||||
@ -34,6 +34,15 @@ def test_memoize():
|
|||||||
fn.assert_called_once_with()
|
fn.assert_called_once_with()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures('no_memoize')
|
||||||
|
def test_no_memoize():
|
||||||
|
fn = Mock(__name__='fn')
|
||||||
|
memoized = memoize(fn)
|
||||||
|
memoized()
|
||||||
|
memoized()
|
||||||
|
assert fn.call_count == 2
|
||||||
|
|
||||||
|
|
||||||
class TestGetClosest(object):
|
class TestGetClosest(object):
|
||||||
|
|
||||||
def test_when_can_match(self):
|
def test_when_can_match(self):
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import pytest
|
||||||
from thefuck import types
|
from thefuck import types
|
||||||
from thefuck.conf import DEFAULT_PRIORITY
|
from thefuck.conf import DEFAULT_PRIORITY
|
||||||
|
|
||||||
@ -14,3 +15,7 @@ def Rule(name='', match=lambda *_: True,
|
|||||||
return types.Rule(name, match, get_new_command,
|
return types.Rule(name, match, get_new_command,
|
||||||
enabled_by_default, side_effect,
|
enabled_by_default, side_effect,
|
||||||
priority)
|
priority)
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def no_memoize(monkeypatch):
|
||||||
|
monkeypatch.setattr('thefuck.utils.memoize.disabled', True)
|
||||||
|
@ -80,12 +80,13 @@ def memoize(fn):
|
|||||||
@wraps(fn)
|
@wraps(fn)
|
||||||
def wrapper(*args, **kwargs):
|
def wrapper(*args, **kwargs):
|
||||||
key = pickle.dumps((args, kwargs))
|
key = pickle.dumps((args, kwargs))
|
||||||
if key not in memo:
|
if key not in memo or memoize.disabled:
|
||||||
memo[key] = fn(*args, **kwargs)
|
memo[key] = fn(*args, **kwargs)
|
||||||
|
|
||||||
return memo[key]
|
return memo[key]
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
memoize.disabled = False
|
||||||
|
|
||||||
|
|
||||||
def get_closest(word, possibilities, n=3, cutoff=0.6):
|
def get_closest(word, possibilities, n=3, cutoff=0.6):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user