public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Michał Górny" <mgorny@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/pms-test-suite:master commit in: /, pmstestsuite/, pmstestsuite/output/
Date: Fri,  5 Aug 2011 10:04:21 +0000 (UTC)	[thread overview]
Message-ID: <7bb2877434ccc06aa39d2956485c2df86f7ab91b.mgorny@gentoo> (raw)

commit:     7bb2877434ccc06aa39d2956485c2df86f7ab91b
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Fri Aug  5 10:05:18 2011 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Fri Aug  5 10:05:39 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/pms-test-suite.git;a=commit;h=7bb28774

Support switchable output modules.

---
 pmstestsuite/cli.py             |   29 ++++++++++++-------------
 pmstestsuite/output/__init__.py |   44 +++++++++++++++++++++++++++++++++++++++
 pmstestsuite/output/cli.py      |   25 ++++++++++++++++++++++
 setup.py                        |    1 +
 4 files changed, 84 insertions(+), 15 deletions(-)

diff --git a/pmstestsuite/cli.py b/pmstestsuite/cli.py
index 97dd8db..0c492e1 100644
--- a/pmstestsuite/cli.py
+++ b/pmstestsuite/cli.py
@@ -13,6 +13,7 @@ from pmstestsuite import PV
 from pmstestsuite.library import load_library
 from pmstestsuite.repository import NewEbuildRepository
 from pmstestsuite.repository.pms_eclass import get_common_eclass_files
+from pmstestsuite.output import get_output_modules
 from pmstestsuite.pm import get_package_managers
 
 class PMSTestSuiteCLI(object):
@@ -45,6 +46,9 @@ class PMSTestSuiteCLI(object):
 		opt.add_option('-M', '--no-manifests', dest='no_manifests',
 				help='Disable Manifest generation/updates',
 				action='store_true', default=False)
+		opt.add_option('-o', '--output-module', dest='outputmod',
+				help='Output module to use',
+				default='cli')
 		# XXX: get list, autodetect, more magic
 		opt.add_option('-p', '--package-manager', dest='pm',
 				help='Package manager to use',
@@ -84,6 +88,13 @@ class PMSTestSuiteCLI(object):
 		if opts.repo_path and opts.repo_name:
 			opt.error('--repository-path and --repository-name are mutually exclusive')
 
+		for x in get_output_modules():
+			if x.name == opts.outputmod:
+				self.output = x()
+				break
+		else:
+			opt.error('Output module not available: %s' % opts.outputmod)
+
 		for x in get_package_managers():
 			if x.name == opts.pm:
 				try:
@@ -148,21 +159,9 @@ class PMSTestSuiteCLI(object):
 			self.all_done()
 
 	def all_done(self):
-		failed = filter(lambda tr: not tr[1], self.results.items())
-		if not failed and not self.verbose:
-			print('%d tests completed successfully.' % len(self.results))
-		else:
-			print('%d of %d tests completed successfully, %d failed:'
-					% (len(self.results) - len(failed),
-						len(self.results), len(failed)))
-			tl = failed if not self.verbose else self.results.items()
-			for t, r in tl:
-				print('- %s [%s]' % (t, 'OK' if r else 'FAILED'))
-				for a in t.assertions:
-					print('-> %s: %s [%s]' % (a.name, str(a),
-							'OK' if a else 'FAILED'))
-
-		self.ret = 0 if not failed else 1
+		ret = self.output(self.results, verbose = self.verbose)
+
+		self.ret = 0 if ret else 1
 		self.loop.quit()
 
 	def start_pm(self):

diff --git a/pmstestsuite/output/__init__.py b/pmstestsuite/output/__init__.py
new file mode 100644
index 0000000..b6a1446
--- /dev/null
+++ b/pmstestsuite/output/__init__.py
@@ -0,0 +1,44 @@
+#	vim:fileencoding=utf-8
+# (c) 2011 Michał Górny <mgorny@gentoo.org>
+# Released under the terms of the 2-clause BSD license.
+
+from gentoopm.util import ABCObject
+from abc import abstractmethod, abstractproperty
+
+class OutputModule(ABCObject):
+	""" A module handling test results output. """
+
+	@abstractproperty
+	def name(self):
+		"""
+		Output module name.
+
+		@type: string
+		"""
+		pass
+
+	@abstractmethod
+	def __call__(self, results, verbose = False):
+		"""
+		Output the test results.
+
+		@param results: test result dict
+		@type results: dict(L{TestCase} -> bool)
+		@param verbose: whether to output the results verbosely
+		@type verbose: bool
+		@return: whether all of the tests succeeded
+		@rtype: bool
+		"""
+		pass
+
+def get_output_modules():
+	"""
+	Return the list of supported output modules.
+
+	@return: supported output modules
+	@rtype: L{OutputModule}
+	"""
+
+	from pmstestsuite.output.cli import CLIOutput
+
+	return (CLIOutput,)

diff --git a/pmstestsuite/output/cli.py b/pmstestsuite/output/cli.py
new file mode 100644
index 0000000..f7d882f
--- /dev/null
+++ b/pmstestsuite/output/cli.py
@@ -0,0 +1,25 @@
+#	vim:fileencoding=utf-8
+# (c) 2011 Michał Górny <mgorny@gentoo.org>
+# Released under the terms of the 2-clause BSD license.
+
+from pmstestsuite.output import OutputModule
+
+class CLIOutput(OutputModule):
+	name = 'cli'
+
+	def __call__(self, results, verbose = False):
+		failed = filter(lambda tr: not tr[1], results.items())
+		if not failed and not verbose:
+			print('%d tests completed successfully.' % len(results))
+		else:
+			print('%d of %d tests completed successfully, %d failed:'
+					% (len(results) - len(failed),
+						len(results), len(failed)))
+			tl = failed if not verbose else results.items()
+			for t, r in tl:
+				print('- %s [%s]' % (t, 'OK' if r else 'FAILED'))
+				for a in t.assertions:
+					print('-> %s: %s [%s]' % (a.name, str(a),
+							'OK' if a else 'FAILED'))
+
+		return bool(failed)

diff --git a/setup.py b/setup.py
index 097d124..5b996ba 100755
--- a/setup.py
+++ b/setup.py
@@ -66,6 +66,7 @@ setup(
 			'pmstestsuite.library',
 			'pmstestsuite.library.standard',
 			'pmstestsuite.library.test',
+			'pmstestsuite.output',
 			'pmstestsuite.pm',
 			'pmstestsuite.repository'
 		],



                 reply	other threads:[~2011-08-05 10:04 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7bb2877434ccc06aa39d2956485c2df86f7ab91b.mgorny@gentoo \
    --to=mgorny@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox