diff options
author | Gustavo Niemeyer <gustavo@niemeyer.net> | 2007-10-31 23:05:24 -0400 |
---|---|---|
committer | Gustavo Niemeyer <gustavo@niemeyer.net> | 2007-10-31 23:05:24 -0400 |
commit | 4ad5399bfa58556c901127144e78a9120b0a0630 (patch) | |
tree | a26134162c10595b798ae74dcd504f42dcee243b /mocker.py | |
parent | 9c4134a7f47ac0065ebfef3c72d527a7f3f23339 (diff) | |
download | mocker-4ad5399bfa58556c901127144e78a9120b0a0630.tar.gz |
Implemented support for "getitem" and "setitem" action kinds.
Diffstat (limited to 'mocker.py')
-rw-r--r-- | mocker.py | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -754,6 +754,12 @@ class Mock(object): def __contains__(self, value): return self.__mocker_act__("contains", (value,)) + def __getitem__(self, key): + return self.__mocker_act__("getitem", (key,)) + + def __setitem__(self, key, value): + return self.__mocker_act__("setitem", (key, value)) + # When adding a new action kind here, also add support for it on # Action.execute() and Path.__str__(). @@ -833,6 +839,10 @@ class Action(object): result = object(*self.args, **self.kwargs) elif kind == "contains": result = self.args[0] in object + elif kind == "getitem": + result = object[self.args[0]] + elif kind == "setitem": + result = object[self.args[0]] = self.args[1] else: raise RuntimeError("Don't know how to execute %r kind." % kind) self._execute_cache[id(object)] = result @@ -911,6 +921,11 @@ class Path(object): result = "%s(%s)" % (result, ", ".join(args)) elif action.kind == "contains": result = "%r in %s" % (action.args[0], result) + elif action.kind == "getitem": + result = "%s[%r]" % (result, action.args[0]) + elif action.kind == "setitem": + result = "%s[%r] = %r" % (result, action.args[0], + action.args[1]) else: raise RuntimeError("Don't know how to format kind %r" % action.kind) |