← Back to team overview

zeitgeist team mailing list archive

[Merge] lp:~thekorn/zeitgeist/fix.test.failures.20100826 into lp:zeitgeist

 

Markus Korn has proposed merging lp:~thekorn/zeitgeist/fix.test.failures.20100826 into lp:zeitgeist.

Requested reviews:
  Zeitgeist Framework Team (zeitgeist)


This branch fixes the failures in our test suite we have right now.

* Event.new_for_values() does also have some optional arguments prefixed
  "subject_"  
* added convenient method to split Event.new_for_values() arguments from
  arguments which are handed over to another method

Once this branch landed and we have a working testsuite I would like to discuss ways to simplify the whole bunch of methods we have with anonymous/optional arguments (e.g. **kwargs)
-- 
https://code.launchpad.net/~thekorn/zeitgeist/fix.test.failures.20100826/+merge/33816
Your team Zeitgeist Framework Team is requested to review the proposed merge of lp:~thekorn/zeitgeist/fix.test.failures.20100826 into lp:zeitgeist.
=== modified file 'zeitgeist/client.py'
--- zeitgeist/client.py	2010-07-18 21:47:58 +0000
+++ zeitgeist/client.py	2010-08-26 18:33:41 +0000
@@ -26,6 +26,7 @@
 import os.path
 import sys
 import logging
+import inspect
 
 from xml.dom.minidom import parseString as minidom_parse
 
@@ -291,6 +292,21 @@
 	always the right thing to do. If you really want to do synchronous
 	DBus calls use the raw DBus API found in the ZeitgeistDBusInterface class.
 	"""
+	
+	@staticmethod
+	def get_event_and_extra_arguments(arguments):
+		""" some methods of :class:`ZeitgeistClient` take a variable
+		number of arguments, where one part of the arguments are used
+		to build one :class:`Event` instance and the other part
+		is forwarded to another method. This function returns an events
+		and the remaining arguments."""
+		kwargs = {}
+		for arg in _FIND_EVENTS_FOR_TEMPLATES_ARGS:
+			if arg in arguments:
+				kwargs[arg] = arguments.pop(arg)
+		ev = Event.new_for_values(**arguments)
+		return ev, kwargs
+	
 	def __init__ (self):
 		self._iface = ZeitgeistDBusInterface()
 		self._registry = self._iface.get_extension("DataSourceRegistry",
@@ -497,11 +513,10 @@
 		allowed keywords are the same as the ones allowed by
 		:meth:`Event.new_for_values() <zeitgeist.datamodel.Event.new_for_values>`.
 		"""
-		ev = Event.new_for_values(**kwargs)
-		
+		ev, arguments = self.get_event_and_extra_arguments(kwargs)
 		self.find_event_ids_for_templates([ev],
 						ids_reply_handler,
-						**kwargs)
+						**arguments)
 	
 	def find_events_for_templates (self,
 					event_templates,
@@ -582,9 +597,10 @@
 		Alias for :meth:`find_events_for_templates`, for use when only
 		one template is needed.
 		"""
-		self.find_events_for_templates([event_template],
+		ev, arguments = self.get_event_and_extra_arguments(kwargs)
+		self.find_events_for_templates([ev],
 						events_reply_handler,
-						**kwargs)
+						**arguments)
 	
 	def find_events_for_values(self, events_reply_handler, **kwargs):
 		"""
@@ -595,15 +611,7 @@
 		allowed keywords are the same as the ones allowed by
 		:meth:`Event.new_for_values() <zeitgeist.datamodel.Event.new_for_values>`.
 		"""
-		ev = Event.new_for_values(**kwargs)
-		# we need a clean dict of arguments to find_event_for_templates
-		# (LP: #510804)
-		arguments = {}
-		for arg in ("timerange", "storage_state", "num_events",
-					"result_type", "error_handler"):
-			if arg in kwargs:
-				arguments[arg] = kwargs[arg]
-		
+		ev, arguments = self.get_event_and_extra_arguments(kwargs)
 		self.find_events_for_templates([ev],
 						events_reply_handler,
 						**arguments)
@@ -896,3 +904,6 @@
 		
 		if callable(normal_reply_handler):
 			normal_reply_handler(normal_reply_data)
+
+_FIND_EVENTS_FOR_TEMPLATES_ARGS = inspect.getargspec(
+	ZeitgeistClient.find_events_for_templates)[0]

=== modified file 'zeitgeist/datamodel.py'
--- zeitgeist/datamodel.py	2010-08-16 18:42:52 +0000
+++ zeitgeist/datamodel.py	2010-08-26 18:33:41 +0000
@@ -706,7 +706,9 @@
 		self = cls()
 		for key in values:
 			if not key in ("timestamp", "interpretation", "manifestation",
-				"actor", "subjects"):
+				"actor", "subjects", "subject_uri", "subject_interpretation",
+				"subject_manifestation", "subject_origin", "subject_mimetype",
+				"subject_text", "subject_storage"):
 				raise ValueError("Event parameter '%s' is not supported" % key)
 			
 		self.timestamp = values.get("timestamp", self.timestamp)


Follow ups