1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-01-19 04:21:14 +00:00
thefuck/tests/conftest.py

70 lines
1.6 KiB
Python
Raw Normal View History

2017-08-03 12:30:04 +02:00
import os
2015-07-10 17:58:41 +03:00
import pytest
2016-01-29 13:09:40 +03:00
from thefuck import shells
2016-02-22 18:40:28 +03:00
from thefuck import conf, const
2016-08-14 15:15:03 +03:00
from thefuck.system import Path
2015-07-10 17:58:41 +03:00
2016-01-29 13:09:40 +03:00
shells.shell = shells.Generic()
2015-07-10 17:58:41 +03:00
2015-09-06 01:13:44 +03:00
def pytest_addoption(parser):
2017-05-01 17:49:13 +02:00
"""Adds `--enable-functional` argument."""
2015-09-06 01:13:44 +03:00
group = parser.getgroup("thefuck")
group.addoption('--enable-functional', action="store_true", default=False,
help="Enable functional tests")
2015-07-10 17:58:41 +03:00
@pytest.fixture
def no_memoize(monkeypatch):
monkeypatch.setattr('thefuck.utils.memoize.disabled', True)
2015-09-07 12:12:16 +03:00
@pytest.fixture(autouse=True)
def settings(request):
2015-09-07 18:59:10 +03:00
def _reset_settings():
conf.settings.clear()
2016-02-22 18:40:28 +03:00
conf.settings.update(const.DEFAULT_SETTINGS)
2015-09-07 18:59:10 +03:00
request.addfinalizer(_reset_settings)
conf.settings.user_dir = Path('~/.thefuck')
2015-09-07 12:12:16 +03:00
return conf.settings
@pytest.fixture
2015-09-07 12:12:16 +03:00
def no_colors(settings):
settings.no_colors = True
2015-09-02 11:10:03 +03:00
@pytest.fixture(autouse=True)
def no_cache(monkeypatch):
monkeypatch.setattr('thefuck.utils.cache.disabled', True)
2015-09-06 01:13:44 +03:00
@pytest.fixture(autouse=True)
def functional(request):
if request.node.get_marker('functional') \
and not request.config.getoption('enable_functional'):
pytest.skip('functional tests are disabled')
2015-09-08 15:24:49 +03:00
@pytest.fixture
def source_root():
return Path(__file__).parent.parent.resolve()
2016-01-29 13:09:40 +03:00
@pytest.fixture
2017-09-03 10:10:50 +02:00
def set_shell(monkeypatch):
2016-01-29 13:09:40 +03:00
def _set(cls):
shell = cls()
monkeypatch.setattr('thefuck.shells.shell', shell)
return shell
return _set
@pytest.fixture(autouse=True)
def os_environ(monkeypatch):
2017-08-03 12:30:04 +02:00
env = {'PATH': os.environ['PATH']}
monkeypatch.setattr('os.environ', env)
return env