Commit 89e1ada7 authored by Dom Sekotill's avatar Dom Sekotill
Browse files

generator: wrap() works on instances, not attr dict

unittest_extra.generator.test_generator.wrap() has been changed to take
an instance rather than a dictionary of attributes, allowing it to use
inheritance features to get attributes from bases.
parent de4bcfcb
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -90,16 +90,16 @@ class test_generator(object):
		self.func = func
		return self

	def wrap(self, attr):
	def wrap(self, instance):
		"""
		Generate a test-wrapper with each set of arguments and add it to 'attr'.
		"""
		if isinstance(self.values, string_types):
			values = attr[self.values]
			values = getattr(instance, self.values)
		else:
			values = self.values
		for name, func in self._wrap(values):
			attr[name] = func
			setattr(instance, name, func)

	def _wrap(self, value_list):
		for number, values in enumerate(value_list):
@@ -145,7 +145,8 @@ class test_generator(object):
class TestGeneratorMeta(type):

	def __new__(cls, clsname, bases, attr):
		new = super(TestGeneratorMeta, cls).__new__(cls, clsname, bases, attr)
		for name, obj in list(attr.items()):
			if isinstance(obj, test_generator):
				obj.wrap(attr)
		return super(TestGeneratorMeta, cls).__new__(cls, clsname, bases, attr)
				obj.wrap(new)
		return new