def _check_snapshot(self, old_agent, old_protocols): # check that the state so far matches the snapshop # if old_agent is None, it means that the snapshot is first entry # we are replaynig - hence we have no state to compare to if old_agent is not None: try: if self.agent != old_agent: comp = deep_compare(self.agent._get_state(), old_agent._get_state()) info = " INFO: %s: %s\n" % comp if comp else "" raise ReplayError( "States of current agent mismatch the " "old agent\nInfo: %s\nOld: %s\n" "Loaded: %s." % (info, pformat(old_agent._get_state()), pformat(self.agent._get_state())) ) if len(self.protocols) != len(old_protocols): raise ReplayError( "The number of protocols mismatch. " "\nOld: %r\nLoaded: %r" % (old_protocols, self.protocols) ) else: for protocol in self.protocols: if protocol not in old_protocols: raise ReplayError( "One of the protocols was not " "found.\nOld: %s\nLoaded: %s" % (pformat(old_protocols), pformat(self.protocols)) ) except RuntimeError, e: exc_info = sys.exc_info() raise ReplayError( "Runtime error during replay of %s: %s" % (self.agent.type_name, error.get_exception_message(e)) ), None, exc_info[2]
def _check_snapshot(self, old_agent, old_protocols): # check that the state so far matches the snapshop # if old_agent is None, it means that the snapshot is first entry # we are replaynig - hence we have no state to compare to if old_agent is not None: if self.agent != old_agent: comp = deep_compare(self.agent._get_state(), old_agent._get_state()) info = " INFO: %s: %s\n" % comp if comp else "" raise ReplayError("States of current agent mismatch the " "old agent\nInfo: %s\nOld: %s\nLoaded: %s." % (info, pformat(old_agent._get_state()), pformat(self.agent._get_state()))) if len(self.protocols) != len(old_protocols): raise ReplayError("The number of protocols mismatch. " "\nOld: %r\nLoaded: %r" % (old_protocols, self.protocols)) else: for protocol in self.protocols: if protocol not in old_protocols: raise ReplayError("One of the protocols was not found." "\nOld: %s\nLoaded: %s" % (pformat(old_protocols), pformat(self.protocols)))
def check(self, obj, expected, exp_type=None, encoding="UTF8", verbose=False, **kwargs): doc = document.WritableDocument("application/json", encoding=encoding) ctx = DummyContext(("ROOT", ), ("root", )) fmt = "verbose" if verbose else "compact" yield document.write(doc, obj, context=ctx, format=fmt, **kwargs) data = doc.get_data() self.assertTrue(isinstance(data, str)) struct = json.loads(data, encoding=encoding) if exp_type is not None: self.assertTrue(isinstance(struct, exp_type)) if expected != struct: path, msg = deep_compare(expected, struct) expected_str = StringIO.StringIO() result_str = StringIO.StringIO() pprint.pprint(expected, stream=expected_str) pprint.pprint(struct, stream=result_str) self.fail("ERROR in %s: %s\nEXPECTED:\n%s\nRESULT:\n%s" % (path, msg, expected_str.getvalue(), result_str.getvalue())) defer.returnValue(data)