public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/pms-test-suite:master commit in: PMSTestSuite/library/test/, PMSTestSuite/library/
@ 2011-05-23  7:38 Michał Górny
  0 siblings, 0 replies; 4+ messages in thread
From: Michał Górny @ 2011-05-23  7:38 UTC (permalink / raw
  To: gentoo-commits

commit:     5df1c8e9c28b7beabf523cea81f1aa5f7cc2a3c3
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Mon May 23 07:38:46 2011 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Mon May 23 07:38:46 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/pms-test-suite.git;a=commit;h=5df1c8e9

Support loading test cases.

---
 PMSTestSuite/library/__init__.py                   |   85 +++++++++++++++-----
 PMSTestSuite/library/case.py                       |    7 ++
 PMSTestSuite/library/test/__init__.py              |    5 +-
 .../library/test/{__init__.py => random_test.py}   |    6 +-
 4 files changed, 78 insertions(+), 25 deletions(-)

diff --git a/PMSTestSuite/library/__init__.py b/PMSTestSuite/library/__init__.py
index 40db438..322edbd 100644
--- a/PMSTestSuite/library/__init__.py
+++ b/PMSTestSuite/library/__init__.py
@@ -2,38 +2,81 @@
 # (c) 2011 Michał Górny <mgorny@gentoo.org>
 # Released under the terms of the 2-clause BSD license.
 
-class TestLibrary(object):
-	""" Base class for a test library. """
-	pass
-
-def load_library(name):
-	"""
-	Try to load a test library <name>. Instiantiate the first TestLibrary
-	subclass found there.
+"""
+>>> l = load_library('test')
+>>> l # doctest: +ELLIPSIS
+<PMSTestSuite.library.test.ExampleLibrary object at ...>
+>>> t = [x for x in l][0]
+>>> t # doctest: +ELLIPSIS
+<PMSTestSuite.library.test.random_test.ExampleCase object at ...>
+"""
 
-	Returns a new TestLibrary subclass instance or raises an ImportError.
+from PMSTestSuite.library.case import TestCase
 
-	>>> load_library('test') # doctest: +ELLIPSIS
-	<PMSTestSuite.library.test.ExampleLibrary object at ...>
+def grabmodule(modname, baseclass):
 	"""
-	# XXX: which exceptions can it raise?
+	Import Python module <modname> and find subclasses of <baseclass> there.
 	
-	modname = 'PMSTestSuite.library.%s' % name
+	Returns an iterator over subclasses or raises one of the following
+	exceptions:
+	- ImportError if module import fails,
+	- TypeError if no matching class is found.
+	"""
 	mod = __import__(modname, {}, {}, ['.'], 0)
-	
+	fail = True
+
 	for k in dir(mod):
 		modvar = getattr(mod, k)
 		# the !issubclass() check is necessary to omit TestLibrary class
 		# imported for the subclass
 		try:
-			if issubclass(modvar, TestLibrary) and \
-					not issubclass(TestLibrary, modvar):
-				cls = modvar
-				break
+			if issubclass(modvar, baseclass) and \
+					not issubclass(baseclass, modvar):
+				fail = False
+				yield modvar
 		except TypeError:
 			pass
-	else:
-		raise ImportError('Unable to find a TestLibrary subclass in %s'
+
+	if fail:
+		raise TypeError('Unable to find a %s subclass in %s'
+				% (baseclass.__name__, modname))
+
+class TestLibrary(object):
+	""" Base class for a test library. """
+
+	def __iter__(self):
+		"""
+		Iterate over all the tests in a test library, loading its modules
+		as necessary. Uses <self.test_names> to get the module names.
+
+		Returns an iterator over TestCase subclass instances or raises one
+		of the following exceptions:
+		- ImportError if submodule import fails,
+		- TypeError if no TestCase subclass is found in a submodule.
+		"""
+		for t in self.test_names:
+			cls = grabmodule('%s.%s' % (self.modname, t), TestCase)
+			for c in cls:
+				yield c()
+
+	def __init__(self, modname):
+		self.modname = modname
+
+def load_library(name):
+	"""
+	Try to load a test library <name>. Instiantiate the first TestLibrary
+	subclass found there.
+
+	Returns a new TestLibrary subclass instance or raises one of the following
+	exceptions:
+	- ImportError if module import fails,
+	- TypeError if no matching class is found.
+	"""
+
+	modname = 'PMSTestSuite.library.%s' % name
+	cls = list(grabmodule(modname, TestLibrary))
+	if len(cls) > 1:
+		raise TypeError('%s ambiguous - more than a single TestLibrary subclass found.'
 				% modname)
 
-	return cls()
+	return cls[0](modname)

diff --git a/PMSTestSuite/library/case.py b/PMSTestSuite/library/case.py
new file mode 100644
index 0000000..a2e60f2
--- /dev/null
+++ b/PMSTestSuite/library/case.py
@@ -0,0 +1,7 @@
+#	vim:fileencoding=utf-8
+# (c) 2011 Michał Górny <mgorny@gentoo.org>
+# Released under the terms of the 2-clause BSD license.
+
+class TestCase(object):
+	""" Base class for a test case. """
+	pass

diff --git a/PMSTestSuite/library/test/__init__.py b/PMSTestSuite/library/test/__init__.py
index 91afc38..9cfbe39 100644
--- a/PMSTestSuite/library/test/__init__.py
+++ b/PMSTestSuite/library/test/__init__.py
@@ -8,4 +8,7 @@ class ExampleLibrary(TestLibrary):
 	"""
 	Absolutely random TestLibrary subclass to test it.
 	"""
-	pass
+
+	test_names=[
+		'random_test'
+	]

diff --git a/PMSTestSuite/library/test/__init__.py b/PMSTestSuite/library/test/random_test.py
similarity index 52%
copy from PMSTestSuite/library/test/__init__.py
copy to PMSTestSuite/library/test/random_test.py
index 91afc38..50acc45 100644
--- a/PMSTestSuite/library/test/__init__.py
+++ b/PMSTestSuite/library/test/random_test.py
@@ -2,10 +2,10 @@
 # (c) 2011 Michał Górny <mgorny@gentoo.org>
 # Released under the terms of the 2-clause BSD license.
 
-from PMSTestSuite.library import TestLibrary
+from PMSTestSuite.library.case import TestCase
 
-class ExampleLibrary(TestLibrary):
+class ExampleCase(TestCase):
 	"""
-	Absolutely random TestLibrary subclass to test it.
+	Absolutely random TestCase subclass to test it.
 	"""
 	pass



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [gentoo-commits] proj/pms-test-suite:master commit in: PMSTestSuite/library/test/, PMSTestSuite/library/
@ 2011-05-23  9:51 Michał Górny
  0 siblings, 0 replies; 4+ messages in thread
From: Michał Górny @ 2011-05-23  9:51 UTC (permalink / raw
  To: gentoo-commits

commit:     15ff5be89fc74bc54b9be9db4e4058276e6d0364
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Mon May 23 09:46:45 2011 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Mon May 23 09:46:45 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/pms-test-suite.git;a=commit;h=15ff5be8

Switch to explicit test case class names.

Grepping for random TestCase subclasses fails when we import another
subclass already.

---
 PMSTestSuite/library/__init__.py      |    8 +++++---
 PMSTestSuite/library/test/__init__.py |    2 +-
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/PMSTestSuite/library/__init__.py b/PMSTestSuite/library/__init__.py
index 322edbd..5c56ba6 100644
--- a/PMSTestSuite/library/__init__.py
+++ b/PMSTestSuite/library/__init__.py
@@ -55,9 +55,11 @@ class TestLibrary(object):
 		- TypeError if no TestCase subclass is found in a submodule.
 		"""
 		for t in self.test_names:
-			cls = grabmodule('%s.%s' % (self.modname, t), TestCase)
-			for c in cls:
-				yield c()
+			modname, clsname = t.rsplit('.', 1)
+			modname = '%s.%s' % (self.modname, modname)
+			mod = __import__(modname, {}, {}, [clsname], 0)
+			cls = getattr(mod, clsname)
+			yield cls()
 
 	def __init__(self, modname):
 		self.modname = modname

diff --git a/PMSTestSuite/library/test/__init__.py b/PMSTestSuite/library/test/__init__.py
index 9cfbe39..ea9940a 100644
--- a/PMSTestSuite/library/test/__init__.py
+++ b/PMSTestSuite/library/test/__init__.py
@@ -10,5 +10,5 @@ class ExampleLibrary(TestLibrary):
 	"""
 
 	test_names=[
-		'random_test'
+		'random_test.ExampleCase'
 	]



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [gentoo-commits] proj/pms-test-suite:master commit in: PMSTestSuite/library/test/, PMSTestSuite/library/
@ 2011-05-23  9:51 Michał Górny
  0 siblings, 0 replies; 4+ messages in thread
From: Michał Górny @ 2011-05-23  9:51 UTC (permalink / raw
  To: gentoo-commits

commit:     d2f9b92ced956b3063fa5c1590397ef782ad7a12
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Mon May 23 09:47:26 2011 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Mon May 23 09:47:41 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/pms-test-suite.git;a=commit;h=d2f9b92c

Add a dummy EbuildTestCase for testing.

---
 PMSTestSuite/library/case.py             |    4 ++++
 PMSTestSuite/library/test/random_test.py |   15 ++++++++++++---
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/PMSTestSuite/library/case.py b/PMSTestSuite/library/case.py
index a2e60f2..6eb3f09 100644
--- a/PMSTestSuite/library/case.py
+++ b/PMSTestSuite/library/case.py
@@ -5,3 +5,7 @@
 class TestCase(object):
 	""" Base class for a test case. """
 	pass
+
+class EbuildTestCase(TestCase):
+	""" Test case using a single ebuild (per EAPI). """
+	pass

diff --git a/PMSTestSuite/library/test/random_test.py b/PMSTestSuite/library/test/random_test.py
index 50acc45..23be2a0 100644
--- a/PMSTestSuite/library/test/random_test.py
+++ b/PMSTestSuite/library/test/random_test.py
@@ -2,10 +2,19 @@
 # (c) 2011 Michał Górny <mgorny@gentoo.org>
 # Released under the terms of the 2-clause BSD license.
 
-from PMSTestSuite.library.case import TestCase
+from PMSTestSuite.library.case import EbuildTestCase
 
-class ExampleCase(TestCase):
+class ExampleCase(EbuildTestCase):
 	"""
 	Absolutely random TestCase subclass to test it.
 	"""
-	pass
+
+	relevant_eapis = (0, 1, 2, 4)
+
+	ebuild_vars = {
+		'DESCRIPTION': 'A really random test'
+	}
+
+	phase_funcs = {
+		'pkg_setup': ['die "Random failure"']
+	}



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [gentoo-commits] proj/pms-test-suite:master commit in: PMSTestSuite/library/test/, PMSTestSuite/library/
@ 2011-05-26  6:35 Michał Górny
  0 siblings, 0 replies; 4+ messages in thread
From: Michał Górny @ 2011-05-26  6:35 UTC (permalink / raw
  To: gentoo-commits

commit:     b934ffc0fa5becd176974fb19cfa7f476a4fd616
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Thu May 26 06:35:18 2011 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Thu May 26 06:35:18 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/pms-test-suite.git;a=commit;h=b934ffc0

Cleanup test names.

---
 PMSTestSuite/library/__init__.py         |    4 ++--
 PMSTestSuite/library/case.py             |    9 ++++++++-
 PMSTestSuite/library/test/__init__.py    |    2 +-
 PMSTestSuite/library/test/random_test.py |    2 +-
 4 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/PMSTestSuite/library/__init__.py b/PMSTestSuite/library/__init__.py
index af7765f..52aa8d2 100644
--- a/PMSTestSuite/library/__init__.py
+++ b/PMSTestSuite/library/__init__.py
@@ -8,10 +8,10 @@
 <PMSTestSuite.library.test.ExampleLibrary object at ...>
 >>> t = [x for x in l][0]
 >>> t # doctest: +ELLIPSIS
-<PMSTestSuite.library.test.random_test.ExampleCase object at ...>
+<PMSTestSuite.library.test.random_test.RandomExampleTest object at ...>
 >>> files = t.get_output_files()
 >>> files # doctest: +ELLIPSIS
-{'pms-test/examplecase/examplecase-0.ebuild': ...}
+{'pms-test/random-example/random-example-0.ebuild': ...}
 >>> f = files.values()[0]
 >>> str(f) # doctest: +ELLIPSIS
 '# Copyright 1999...inherit pms-test...pms-test_pkg_setup...die...'

diff --git a/PMSTestSuite/library/case.py b/PMSTestSuite/library/case.py
index 084edd8..2908342 100644
--- a/PMSTestSuite/library/case.py
+++ b/PMSTestSuite/library/case.py
@@ -2,6 +2,8 @@
 # (c) 2011 Michał Górny <mgorny@gentoo.org>
 # Released under the terms of the 2-clause BSD license.
 
+import re
+
 # XXX: move to some consts module?
 phase_func_names = [
 	'pkg_pretend', 'pkg_setup', 'src_unpack', 'src_prepare',
@@ -17,6 +19,8 @@ inherit pms-test
 
 '''
 
+pn_re = re.compile('(.)([A-Z])')
+
 class TestCase(object):
 	""" Base class for a test case. """
 	pass
@@ -73,7 +77,10 @@ class EbuildTestCase(TestCase):
 
 				return ''.join(contents)
 
-		pn = self.__class__.__name__.lower()
+		pn = self.__class__.__name__
+		if pn.endswith('Test'):
+			pn = pn[:-4]
+		pn = pn_re.sub('\\1-\\2', pn).lower()
 		fn = 'pms-test/%s/%s-%s.ebuild' % (pn, pn, self.eapi)
 
 		return {fn: EbuildTestCaseEbuildFile(self)}

diff --git a/PMSTestSuite/library/test/__init__.py b/PMSTestSuite/library/test/__init__.py
index ea9940a..4ef8e30 100644
--- a/PMSTestSuite/library/test/__init__.py
+++ b/PMSTestSuite/library/test/__init__.py
@@ -10,5 +10,5 @@ class ExampleLibrary(TestLibrary):
 	"""
 
 	test_names=[
-		'random_test.ExampleCase'
+		'random_test.RandomExampleTest'
 	]

diff --git a/PMSTestSuite/library/test/random_test.py b/PMSTestSuite/library/test/random_test.py
index 23be2a0..d60c32d 100644
--- a/PMSTestSuite/library/test/random_test.py
+++ b/PMSTestSuite/library/test/random_test.py
@@ -4,7 +4,7 @@
 
 from PMSTestSuite.library.case import EbuildTestCase
 
-class ExampleCase(EbuildTestCase):
+class RandomExampleTest(EbuildTestCase):
 	"""
 	Absolutely random TestCase subclass to test it.
 	"""



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-05-26  6:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-26  6:35 [gentoo-commits] proj/pms-test-suite:master commit in: PMSTestSuite/library/test/, PMSTestSuite/library/ Michał Górny
  -- strict thread matches above, loose matches on Subject: below --
2011-05-23  9:51 Michał Górny
2011-05-23  9:51 Michał Górny
2011-05-23  7:38 Michał Górny

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox