mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
Move events reset to pytest fixture
This commit is contained in:
parent
8de7f65d4a
commit
793101c387
2 changed files with 13 additions and 15 deletions
|
@ -34,7 +34,17 @@ def xonsh_execer(monkeypatch):
|
|||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def xonsh_builtins():
|
||||
def xonsh_events():
|
||||
yield events
|
||||
for name, oldevent in vars(events).items():
|
||||
# Heavily based on transmogrification
|
||||
klass = type(oldevent)
|
||||
newevent = events._mkevent(name, klass, klass.__doc__)
|
||||
setattr(events, name, newevent)
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def xonsh_builtins(xonsh_events):
|
||||
"""Mock out most of the builtins xonsh attributes."""
|
||||
builtins.__xonsh_env__ = DummyEnv()
|
||||
if ON_WINDOWS:
|
||||
|
@ -63,7 +73,7 @@ def xonsh_builtins():
|
|||
builtins.aliases = {}
|
||||
# Unlike all the other stuff, this has to refer to the "real" one because all modules that would
|
||||
# be firing events on the global instance.
|
||||
builtins.events = events
|
||||
builtins.events = xonsh_events
|
||||
yield builtins
|
||||
del builtins.__xonsh_env__
|
||||
del builtins.__xonsh_ctx__
|
||||
|
@ -89,7 +99,6 @@ def xonsh_builtins():
|
|||
del builtins.aliases
|
||||
del builtins.events
|
||||
tasks.clear() # must to this to enable resetting all_jobs
|
||||
events.clean_between_tests()
|
||||
|
||||
|
||||
if ON_WINDOWS:
|
||||
|
|
|
@ -230,6 +230,7 @@ class EventManager:
|
|||
|
||||
@staticmethod
|
||||
def _mkevent(name, klass=Event, doc=None):
|
||||
# NOTE: Also used in `xonsh_events` test fixture
|
||||
# (A little bit of magic to enable docstrings to work right)
|
||||
return type(name, (klass,), {'__doc__': doc, '__module__': 'xonsh.events', '__qualname__': 'events.'+name})()
|
||||
|
||||
|
@ -270,18 +271,6 @@ class EventManager:
|
|||
# Now it exists, and we won't be called again.
|
||||
return e
|
||||
|
||||
def clean_between_tests(self):
|
||||
"""
|
||||
Reset state of events in preparation for a new test.
|
||||
|
||||
Implementation detail: This is done by replacing the events with new instances. Do not call
|
||||
this outside of testing.
|
||||
"""
|
||||
for name, oldevent in vars(self).items():
|
||||
# Heavily based on transmogrification
|
||||
klass = type(oldevent)
|
||||
newevent = self._mkevent(name, klass, klass.__doc__)
|
||||
setattr(self, name, newevent)
|
||||
|
||||
# Not lazy because:
|
||||
# 1. Initialization of EventManager can't be much cheaper
|
||||
|
|
Loading…
Add table
Reference in a new issue