diff options
author | Gustavo Niemeyer <gustavo@niemeyer.net> | 2007-12-09 13:37:49 -0200 |
---|---|---|
committer | Gustavo Niemeyer <gustavo@niemeyer.net> | 2007-12-09 13:37:49 -0200 |
commit | 7ba4e6a4eff5896808e7b95e84744cd97a963c07 (patch) | |
tree | fa8d823d53de7ec05e28128009186c2fbe413f59 /mocker.py | |
parent | 92e4f5b0bc5ec7a06284b9cc2245fdfb052d9707 (diff) | |
download | mocker-7ba4e6a4eff5896808e7b95e84744cd97a963c07.tar.gz |
Fixed problem when requesting order on similar expressions. The
second expression might not be accepted.
Diffstat (limited to 'mocker.py')
-rw-r--r-- | mocker.py | 18 |
1 files changed, 11 insertions, 7 deletions
@@ -684,13 +684,11 @@ class MockerBase(object): recorder(self, event) return Mock(self, path) else: - satisfied = [] - for event in self._events: - if event.satisfied(): - satisfied.append(event) - elif event.matches(path): - return event.run(path) - for event in satisfied: + # First run unsatisfied events, then ones not previously run. + events = [(event.satisfied()*2 + event.has_run(), event) + for event in self._events] + events.sort() + for key, event in events: if event.matches(path): return event.run(path) raise MatchError(ERROR_PREFIX + "Unexpected expression: %s" % path) @@ -1458,6 +1456,7 @@ class Event(object): def __init__(self, path=None): self.path = path self._tasks = [] + self._has_run = False def add_task(self, task): """Add a new task to this taks.""" @@ -1477,6 +1476,9 @@ class Event(object): return False return bool(self._tasks) + def has_run(self): + return self._has_run + def run(self, path): """Run all tasks with the given action. @@ -1487,6 +1489,7 @@ class Event(object): The result of this method will be the last result of a task which isn't None, or None if they're all None. """ + self._has_run = True result = None errors = [] for task in self._tasks: @@ -1548,6 +1551,7 @@ class Event(object): def replay(self): """Put all tasks in replay mode.""" + self._has_run = False for task in self._tasks: task.replay() |