public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/portage:master commit in: pym/portage/tests/
@ 2011-10-09 20:41 Mike Frysinger
  0 siblings, 0 replies; 19+ messages in thread
From: Mike Frysinger @ 2011-10-09 20:41 UTC (permalink / raw
  To: gentoo-commits

commit:     4dfb7a71ab9983e5bd0f2121062df04ffd6a748a
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Sun Oct  9 18:43:01 2011 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Sun Oct  9 20:40:43 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=4dfb7a71

tests: add --list flag to show available tests

Trying to guess at what runtests actually wants in terms of command line
tests is pretty hard.  Any invalid value just gives you an ugly traceback.
So add a helper --list option so the user can easily figure out what the
code wants *exactly*.

Signed-off-by: Mike Frysinger <vapier <AT> gentoo.org>

---
 pym/portage/tests/__init__.py |   55 +++++++++++++++++++++++++---------------
 1 files changed, 34 insertions(+), 21 deletions(-)

diff --git a/pym/portage/tests/__init__.py b/pym/portage/tests/__init__.py
index fa297b5..016a4e8 100644
--- a/pym/portage/tests/__init__.py
+++ b/pym/portage/tests/__init__.py
@@ -17,38 +17,28 @@ from portage import _encodings
 from portage import _unicode_decode
 
 def main():
-
-	TEST_FILE = b'__test__'
-	svn_dirname = b'.svn'
 	suite = unittest.TestSuite()
 	basedir = os.path.dirname(os.path.realpath(__file__))
-	testDirs = []
 
 	usage = "usage: %s [options] [tests to run]" % os.path.basename(sys.argv[0])
 	parser = OptionParser(usage=usage)
+	parser.add_option("-l", "--list", help="list all tests",
+		action="store_true", dest="list_tests")
 	(options, args) = parser.parse_args(args=sys.argv)
 
+	if options.list_tests:
+		testdir = os.path.dirname(sys.argv[0])
+		for mydir in getTestDirs(basedir):
+			testsubdir = os.path.basename(mydir)
+			for name in getTestNames(mydir):
+				print("%s/%s/%s.py" % (testdir, testsubdir, name))
+		sys.exit(0)
+
 	if len(args) > 1:
 		suite.addTests(getTestFromCommandLine(args[1:], basedir))
 		return TextTestRunner(verbosity=2).run(suite)
 
-	# the os.walk help mentions relative paths as being quirky
-	# I was tired of adding dirs to the list, so now we add __test__
-	# to each dir we want tested.
-	for root, dirs, files in os.walk(basedir):
-		if svn_dirname in dirs:
-			dirs.remove(svn_dirname)
-		try:
-			root = _unicode_decode(root,
-				encoding=_encodings['fs'], errors='strict')
-		except UnicodeDecodeError:
-			continue
-
-		if TEST_FILE in files:
-			testDirs.append(root)
-
-	testDirs.sort()
-	for mydir in testDirs:
+	for mydir in getTestDirs(basedir):
 		suite.addTests(getTests(os.path.join(basedir, mydir), basedir) )
 	return TextTestRunner(verbosity=2).run(suite)
 
@@ -73,6 +63,29 @@ def getTestFromCommandLine(args, base_path):
 		result.extend(getTestsFromFiles(path, base_path, [mymodule]))
 	return result
 
+def getTestDirs(base_path):
+	TEST_FILE = b'__test__'
+	svn_dirname = b'.svn'
+	testDirs = []
+
+	# the os.walk help mentions relative paths as being quirky
+	# I was tired of adding dirs to the list, so now we add __test__
+	# to each dir we want tested.
+	for root, dirs, files in os.walk(base_path):
+		if svn_dirname in dirs:
+			dirs.remove(svn_dirname)
+		try:
+			root = _unicode_decode(root,
+				encoding=_encodings['fs'], errors='strict')
+		except UnicodeDecodeError:
+			continue
+
+		if TEST_FILE in files:
+			testDirs.append(root)
+
+	testDirs.sort()
+	return testDirs
+
 def getTestNames(path):
 	files = os.listdir(path)
 	files = [ f[:-3] for f in files if f.startswith("test") and f.endswith(".py") ]



^ permalink raw reply related	[flat|nested] 19+ messages in thread
* [gentoo-commits] proj/portage:master commit in: pym/portage/tests/
@ 2018-05-07  0:27 Zac Medico
  0 siblings, 0 replies; 19+ messages in thread
From: Zac Medico @ 2018-05-07  0:27 UTC (permalink / raw
  To: gentoo-commits

commit:     299a9a40536209c4c2664857b5aecb018fa0a6f6
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sun May  6 23:40:33 2018 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Mon May  7 00:19:54 2018 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=299a9a40

TestCase: handle SkipTest during setUp method

 pym/portage/tests/__init__.py | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/pym/portage/tests/__init__.py b/pym/portage/tests/__init__.py
index bf681c47e..e149b5c0c 100644
--- a/pym/portage/tests/__init__.py
+++ b/pym/portage/tests/__init__.py
@@ -207,18 +207,18 @@ class TestCase(unittest.TestCase):
 		result.startTest(self)
 		testMethod = getattr(self, self._testMethodName)
 		try:
-			try:
-				self.setUp()
-			except SystemExit:
-				raise
-			except KeyboardInterrupt:
-				raise
-			except:
-				result.addError(self, sys.exc_info())
-				return
-
 			ok = False
 			try:
+				try:
+					self.setUp()
+				except KeyboardInterrupt:
+					raise
+				except SkipTest:
+					raise
+				except Exception:
+					result.addError(self, sys.exc_info())
+					return
+
 				testMethod()
 				ok = True
 			except SkipTest as e:


^ permalink raw reply related	[flat|nested] 19+ messages in thread
* [gentoo-commits] proj/portage:master commit in: pym/portage/tests/
@ 2014-09-29 22:27 Brian Dolbec
  0 siblings, 0 replies; 19+ messages in thread
From: Brian Dolbec @ 2014-09-29 22:27 UTC (permalink / raw
  To: gentoo-commits

commit:     02ed485976fbf88a548c7b83978e23e3b50f41a2
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Mon Sep 29 21:48:20 2014 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Mon Sep 29 22:26:35 2014 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=02ed4859

Fix travis test failures due to setup.py installing future sbin scripts in bindir

---
 pym/portage/tests/__init__.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/pym/portage/tests/__init__.py b/pym/portage/tests/__init__.py
index 708dd59..afa57e3 100644
--- a/pym/portage/tests/__init__.py
+++ b/pym/portage/tests/__init__.py
@@ -197,7 +197,9 @@ class TestCase(unittest.TestCase):
 		self.cnf_path = cnf_path
 		self.cnf_etc_path = cnf_etc_path
 		self.bindir = cnf_bindir
-		self.sbindir = cnf_sbindir
+		# sbin scripts are installed by setup.py to the bindir
+		# they are relocated to /usr/sbin dir by the ebuild later
+		self.sbindir = self.bindir
 
 	def defaultTestResult(self):
 		return TextTestResult()


^ permalink raw reply related	[flat|nested] 19+ messages in thread
* [gentoo-commits] proj/portage:master commit in: pym/portage/tests/
@ 2013-10-21  2:20 Mike Frysinger
  0 siblings, 0 replies; 19+ messages in thread
From: Mike Frysinger @ 2013-10-21  2:20 UTC (permalink / raw
  To: gentoo-commits

commit:     44accfe2cacdc72145be1849e937af813d7fc7d3
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Mon Oct 21 02:11:05 2013 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Mon Oct 21 02:12:58 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=44accfe2

tests: support assertIn/assertNotIn in python-2.6

---
 pym/portage/tests/__init__.py | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/pym/portage/tests/__init__.py b/pym/portage/tests/__init__.py
index 6c5c4df..84e732a 100644
--- a/pym/portage/tests/__init__.py
+++ b/pym/portage/tests/__init__.py
@@ -279,9 +279,16 @@ if unittest_skip_shims:
 
 	def skipTest(self, reason):
 		raise SkipTest(reason)
-
 	setattr(TestCase, 'skipTest', skipTest)
 
+	def assertIn(self, member, container, msg=None):
+		self.assertTrue(member in container, msg=msg)
+	setattr(TestCase, 'assertIn', assertIn)
+
+	def assertNotIn(self, member, container, msg=None):
+		self.assertFalse(member in container, msg=msg)
+	setattr(TestCase, 'assertNotIn', assertNotIn)
+
 class TextTestRunner(unittest.TextTestRunner):
 	"""
 	We subclass unittest.TextTestRunner to output SKIP for tests that fail but are skippable


^ permalink raw reply related	[flat|nested] 19+ messages in thread
* [gentoo-commits] proj/portage:master commit in: pym/portage/tests/
@ 2013-10-17  7:31 Mike Frysinger
  0 siblings, 0 replies; 19+ messages in thread
From: Mike Frysinger @ 2013-10-17  7:31 UTC (permalink / raw
  To: gentoo-commits

commit:     b02fab10e3ec124d1c2f0b66717451f55c3224a0
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Thu Oct 17 05:00:56 2013 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Thu Oct 17 05:00:56 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=b02fab10

tests: support standard unittest.SkipTest exceptions

---
 pym/portage/tests/__init__.py | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/pym/portage/tests/__init__.py b/pym/portage/tests/__init__.py
index 890851b..6c5c4df 100644
--- a/pym/portage/tests/__init__.py
+++ b/pym/portage/tests/__init__.py
@@ -13,6 +13,14 @@ try:
 except ImportError:
 	from unittest import _TextTestResult
 
+try:
+	# They added the skip framework to python-2.7.
+	# Drop this once we drop python-2.6 support.
+	unittest_skip_shims = False
+	import unittest.SkipTest as SkipTest # new in python-2.7
+except ImportError:
+	unittest_skip_shims = True
+
 import portage
 from portage import os
 from portage import _encodings
@@ -188,10 +196,14 @@ class TestCase(unittest.TestCase):
 			except:
 				result.addError(self, sys.exc_info())
 				return
+
 			ok = False
 			try:
 				testMethod()
 				ok = True
+			except SkipTest as e:
+				result.addPortageSkip(self, "%s: SKIP: %s" %
+					(testMethod, str(e)))
 			except self.failureException:
 				if self.portage_skip is not None:
 					if self.portage_skip is True:
@@ -207,6 +219,7 @@ class TestCase(unittest.TestCase):
 				raise
 			except:
 				result.addError(self, sys.exc_info())
+
 			try:
 				self.tearDown()
 			except SystemExit:
@@ -216,7 +229,8 @@ class TestCase(unittest.TestCase):
 			except:
 				result.addError(self, sys.exc_info())
 				ok = False
-			if ok: result.addSuccess(self)
+			if ok:
+				result.addSuccess(self)
 		finally:
 			result.stopTest(self)
 
@@ -258,6 +272,16 @@ class TestCase(unittest.TestCase):
 		if os.path.exists(path):
 			raise self.failureException('path exists when it should not: %s' % path)
 
+if unittest_skip_shims:
+	# Shim code for <python-2.7.
+	class SkipTest(Exception):
+		"""unittest.SkipTest shim for <python-2.7"""
+
+	def skipTest(self, reason):
+		raise SkipTest(reason)
+
+	setattr(TestCase, 'skipTest', skipTest)
+
 class TextTestRunner(unittest.TextTestRunner):
 	"""
 	We subclass unittest.TextTestRunner to output SKIP for tests that fail but are skippable


^ permalink raw reply related	[flat|nested] 19+ messages in thread
* [gentoo-commits] proj/portage:master commit in: pym/portage/tests/
@ 2013-08-03  1:37 Zac Medico
  0 siblings, 0 replies; 19+ messages in thread
From: Zac Medico @ 2013-08-03  1:37 UTC (permalink / raw
  To: gentoo-commits

commit:     4b2ff81f880a73cff6a4b9ec67cebeed79bd3382
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sat Aug  3 01:37:14 2013 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sat Aug  3 01:37:14 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=4b2ff81f

runTests: portage.util._argparse

---
 pym/portage/tests/__init__.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/pym/portage/tests/__init__.py b/pym/portage/tests/__init__.py
index d90fe6f..c0ad112 100644
--- a/pym/portage/tests/__init__.py
+++ b/pym/portage/tests/__init__.py
@@ -7,7 +7,6 @@ from __future__ import print_function
 import sys
 import time
 import unittest
-from optparse import OptionParser, OptionValueError
 
 try:
 	from unittest.runner import _TextTestResult # new in python-2.7
@@ -18,16 +17,17 @@ import portage
 from portage import os
 from portage import _encodings
 from portage import _unicode_decode
+from portage.util._argparse import ArgumentParser
 
 def main():
 	suite = unittest.TestSuite()
 	basedir = os.path.dirname(os.path.realpath(__file__))
 
 	usage = "usage: %s [options] [tests to run]" % os.path.basename(sys.argv[0])
-	parser = OptionParser(usage=usage)
-	parser.add_option("-l", "--list", help="list all tests",
+	parser = ArgumentParser(usage=usage)
+	parser.add_argument("-l", "--list", help="list all tests",
 		action="store_true", dest="list_tests")
-	(options, args) = parser.parse_args(args=sys.argv)
+	options, args = parser.parse_known_args(args=sys.argv)
 
 	if (os.environ.get('NOCOLOR') in ('yes', 'true') or
 		os.environ.get('TERM') == 'dumb' or


^ permalink raw reply related	[flat|nested] 19+ messages in thread
* [gentoo-commits] proj/portage:master commit in: pym/portage/tests/
@ 2013-03-19  8:36 Zac Medico
  0 siblings, 0 replies; 19+ messages in thread
From: Zac Medico @ 2013-03-19  8:36 UTC (permalink / raw
  To: gentoo-commits

commit:     478401665d0b1f9613b236f07c6a38e13e2f77e4
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Tue Mar 19 08:35:40 2013 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Tue Mar 19 08:35:40 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=47840166

tests.main(): disable colors when appropriate

---
 pym/portage/tests/__init__.py |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/pym/portage/tests/__init__.py b/pym/portage/tests/__init__.py
index ee1e563..a46c2db 100644
--- a/pym/portage/tests/__init__.py
+++ b/pym/portage/tests/__init__.py
@@ -14,6 +14,7 @@ try:
 except ImportError:
 	from unittest import _TextTestResult
 
+import portage
 from portage import os
 from portage import _encodings
 from portage import _unicode_decode
@@ -28,6 +29,11 @@ def main():
 		action="store_true", dest="list_tests")
 	(options, args) = parser.parse_args(args=sys.argv)
 
+	if (os.environ.get('NOCOLOR') in ('yes', 'true') or
+		os.environ.get('TERM') == 'dumb' or
+		not sys.stdout.isatty()):
+		portage.output.nocolor()
+
 	if options.list_tests:
 		testdir = os.path.dirname(sys.argv[0])
 		for mydir in getTestDirs(basedir):


^ permalink raw reply related	[flat|nested] 19+ messages in thread
* [gentoo-commits] proj/portage:master commit in: pym/portage/tests/
@ 2013-03-13  4:10 Arfrever Frehtes Taifersar Arahesis
  0 siblings, 0 replies; 19+ messages in thread
From: Arfrever Frehtes Taifersar Arahesis @ 2013-03-13  4:10 UTC (permalink / raw
  To: gentoo-commits

commit:     ccf4ff7cbb010f547603b86d0cac733259e5aead
Author:     Arfrever Frehtes Taifersar Arahesis <Arfrever <AT> Apache <DOT> Org>
AuthorDate: Wed Mar 13 04:09:01 2013 +0000
Commit:     Arfrever Frehtes Taifersar Arahesis <arfrever.fta <AT> gmail <DOT> com>
CommitDate: Wed Mar 13 04:09:01 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=ccf4ff7c

portage.tests.getTestDirs(): Delete obsolete handling of .svn directories.

---
 pym/portage/tests/__init__.py |    5 +----
 1 files changed, 1 insertions(+), 4 deletions(-)

diff --git a/pym/portage/tests/__init__.py b/pym/portage/tests/__init__.py
index 492ece4..ee1e563 100644
--- a/pym/portage/tests/__init__.py
+++ b/pym/portage/tests/__init__.py
@@ -1,5 +1,5 @@
 # tests/__init__.py -- Portage Unit Test functionality
-# Copyright 2006-2011 Gentoo Foundation
+# Copyright 2006-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 from __future__ import print_function
@@ -70,15 +70,12 @@ def getTestFromCommandLine(args, base_path):
 
 def getTestDirs(base_path):
 	TEST_FILE = b'__test__'
-	svn_dirname = b'.svn'
 	testDirs = []
 
 	# the os.walk help mentions relative paths as being quirky
 	# I was tired of adding dirs to the list, so now we add __test__
 	# to each dir we want tested.
 	for root, dirs, files in os.walk(base_path):
-		if svn_dirname in dirs:
-			dirs.remove(svn_dirname)
 		try:
 			root = _unicode_decode(root,
 				encoding=_encodings['fs'], errors='strict')


^ permalink raw reply related	[flat|nested] 19+ messages in thread
* [gentoo-commits] proj/portage:master commit in: pym/portage/tests/
@ 2013-01-31 19:56 Zac Medico
  0 siblings, 0 replies; 19+ messages in thread
From: Zac Medico @ 2013-01-31 19:56 UTC (permalink / raw
  To: gentoo-commits

commit:     88e8f1fcc212c93b5dc35dd441f1431986de07b7
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Thu Jan 31 19:56:13 2013 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Thu Jan 31 19:56:13 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=88e8f1fc

runTests: handle samefile OSError, bug #454880

---
 pym/portage/tests/runTests |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/pym/portage/tests/runTests b/pym/portage/tests/runTests
index 53e1b5c..b006969 100755
--- a/pym/portage/tests/runTests
+++ b/pym/portage/tests/runTests
@@ -1,6 +1,6 @@
 #!/usr/bin/python -Wd
 # runTests.py -- Portage Unit Test Functionality
-# Copyright 2006-2012 Gentoo Foundation
+# Copyright 2006-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 import os, sys
@@ -45,11 +45,17 @@ import portage.tests as tests
 from portage.const import PORTAGE_BIN_PATH
 path = os.environ.get("PATH", "").split(":")
 path = [x for x in path if x]
-if not path or not os.path.samefile(path[0], PORTAGE_BIN_PATH):
+
+insert_bin_path = True
+try:
+	insert_bin_path = not path or \
+		not os.path.samefile(path[0], PORTAGE_BIN_PATH)
+except OSError:
+	pass
+
+if insert_bin_path:
 	path.insert(0, PORTAGE_BIN_PATH)
 	os.environ["PATH"] = ":".join(path)
-del path
-
 
 if __name__ == "__main__":
 	sys.exit(tests.main())


^ permalink raw reply related	[flat|nested] 19+ messages in thread
* [gentoo-commits] proj/portage:master commit in: pym/portage/tests/
@ 2013-01-03 23:31 Zac Medico
  0 siblings, 0 replies; 19+ messages in thread
From: Zac Medico @ 2013-01-03 23:31 UTC (permalink / raw
  To: gentoo-commits

commit:     fbc857d820ee83d99521e32a7378e1c24d43edb4
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Thu Jan  3 23:31:15 2013 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Thu Jan  3 23:31:15 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=fbc857d8

runTests: portage._internal_caller = True

---
 pym/portage/tests/runTests |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/pym/portage/tests/runTests b/pym/portage/tests/runTests
index 1c1008d..53e1b5c 100755
--- a/pym/portage/tests/runTests
+++ b/pym/portage/tests/runTests
@@ -32,6 +32,7 @@ os.environ["PORTAGE_GRPNAME"] = grp.getgrgid(os.getgid()).gr_name
 sys.path.insert(0, osp.dirname(osp.dirname(osp.dirname(osp.abspath(__file__)))))
 
 import portage
+portage._internal_caller = True
 
 # Ensure that we don't instantiate portage.settings, so that tests should
 # work the same regardless of global configuration file state/existence.


^ permalink raw reply related	[flat|nested] 19+ messages in thread
* [gentoo-commits] proj/portage:master commit in: pym/portage/tests/
@ 2011-12-16  2:42 Zac Medico
  0 siblings, 0 replies; 19+ messages in thread
From: Zac Medico @ 2011-12-16  2:42 UTC (permalink / raw
  To: gentoo-commits

commit:     9c2990c593d739f19e85415b841273c74e54911d
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Fri Dec 16 02:41:45 2011 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Fri Dec 16 02:41:45 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=9c2990c5

runTests: initialize portage.data for PyPy

---
 pym/portage/tests/runTests |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/pym/portage/tests/runTests b/pym/portage/tests/runTests
index 4c10087..0c476b3 100755
--- a/pym/portage/tests/runTests
+++ b/pym/portage/tests/runTests
@@ -30,6 +30,10 @@ import portage
 # work the same regardless of global configuration file state/existence.
 portage._disable_legacy_globals()
 
+# Somehow this prevents "TypeError: expected string" errors
+# from grp.getgrnam() with PyPy 1.7
+portage.data._init(os.environ)
+
 import portage.tests as tests
 from portage.const import PORTAGE_BIN_PATH
 path = os.environ.get("PATH", "").split(":")



^ permalink raw reply related	[flat|nested] 19+ messages in thread
* [gentoo-commits] proj/portage:master commit in: pym/portage/tests/
@ 2011-10-10  2:22 Zac Medico
  0 siblings, 0 replies; 19+ messages in thread
From: Zac Medico @ 2011-10-10  2:22 UTC (permalink / raw
  To: gentoo-commits

commit:     93b7bbebd96c1cca24a53659657033d621e5c1f4
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Mon Oct 10 02:21:54 2011 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Mon Oct 10 02:21:54 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=93b7bbeb

tests/__init__: return int from main()

---
 pym/portage/tests/__init__.py |   13 ++++++++-----
 pym/portage/tests/runTests    |    4 +---
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/pym/portage/tests/__init__.py b/pym/portage/tests/__init__.py
index fedb7e6..492ece4 100644
--- a/pym/portage/tests/__init__.py
+++ b/pym/portage/tests/__init__.py
@@ -34,15 +34,18 @@ def main():
 			testsubdir = os.path.basename(mydir)
 			for name in getTestNames(mydir):
 				print("%s/%s/%s.py" % (testdir, testsubdir, name))
-		sys.exit(0)
+		return os.EX_OK
 
 	if len(args) > 1:
 		suite.addTests(getTestFromCommandLine(args[1:], basedir))
-		return TextTestRunner(verbosity=2).run(suite)
+	else:
+		for mydir in getTestDirs(basedir):
+			suite.addTests(getTests(os.path.join(basedir, mydir), basedir))
 
-	for mydir in getTestDirs(basedir):
-		suite.addTests(getTests(os.path.join(basedir, mydir), basedir) )
-	return TextTestRunner(verbosity=2).run(suite)
+	result = TextTestRunner(verbosity=2).run(suite)
+	if not result.wasSuccessful():
+		return 1
+	return os.EX_OK
 
 def my_import(name):
 	mod = __import__(name)

diff --git a/pym/portage/tests/runTests b/pym/portage/tests/runTests
index 146f7d4..4c10087 100755
--- a/pym/portage/tests/runTests
+++ b/pym/portage/tests/runTests
@@ -41,6 +41,4 @@ del path
 
 
 if __name__ == "__main__":
-	result = tests.main()
-	if not result.wasSuccessful():
-		sys.exit(1)
+	sys.exit(tests.main())



^ permalink raw reply related	[flat|nested] 19+ messages in thread
* [gentoo-commits] proj/portage:master commit in: pym/portage/tests/
@ 2011-10-10  1:55 Zac Medico
  0 siblings, 0 replies; 19+ messages in thread
From: Zac Medico @ 2011-10-10  1:55 UTC (permalink / raw
  To: gentoo-commits

commit:     6d6784555cdc6d541a824ff7a5cd31a343f62ca3
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Mon Oct 10 01:55:30 2011 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Mon Oct 10 01:55:30 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=6d678455

tests/__init__: import print_function

---
 pym/portage/tests/__init__.py |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/pym/portage/tests/__init__.py b/pym/portage/tests/__init__.py
index 016a4e8..fedb7e6 100644
--- a/pym/portage/tests/__init__.py
+++ b/pym/portage/tests/__init__.py
@@ -2,6 +2,8 @@
 # Copyright 2006-2011 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+from __future__ import print_function
+
 import sys
 import time
 import unittest



^ permalink raw reply related	[flat|nested] 19+ messages in thread
* [gentoo-commits] proj/portage:master commit in: pym/portage/tests/
@ 2011-10-09 20:41 Mike Frysinger
  0 siblings, 0 replies; 19+ messages in thread
From: Mike Frysinger @ 2011-10-09 20:41 UTC (permalink / raw
  To: gentoo-commits

commit:     0e32e6f3b950b6ca05724491cde8c9d04817d670
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Sun Oct  9 18:42:01 2011 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Sun Oct  9 20:40:43 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=0e32e6f3

tests: add a --help option to make runtest more friendly

At the moment, trying to do `./runtests.h -h` just produces an ugly and
indecipherable traceback.  Make it a bit more friendly.

Signed-off-by: Mike Frysinger <vapier <AT> gentoo.org>

---
 pym/portage/tests/__init__.py |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/pym/portage/tests/__init__.py b/pym/portage/tests/__init__.py
index 7f1ed3f..fa297b5 100644
--- a/pym/portage/tests/__init__.py
+++ b/pym/portage/tests/__init__.py
@@ -5,6 +5,7 @@
 import sys
 import time
 import unittest
+from optparse import OptionParser, OptionValueError
 
 try:
 	from unittest.runner import _TextTestResult # new in python-2.7
@@ -23,8 +24,12 @@ def main():
 	basedir = os.path.dirname(os.path.realpath(__file__))
 	testDirs = []
 
-	if len(sys.argv) > 1:
-		suite.addTests(getTestFromCommandLine(sys.argv[1:], basedir))
+	usage = "usage: %s [options] [tests to run]" % os.path.basename(sys.argv[0])
+	parser = OptionParser(usage=usage)
+	(options, args) = parser.parse_args(args=sys.argv)
+
+	if len(args) > 1:
+		suite.addTests(getTestFromCommandLine(args[1:], basedir))
 		return TextTestRunner(verbosity=2).run(suite)
 
 	# the os.walk help mentions relative paths as being quirky



^ permalink raw reply related	[flat|nested] 19+ messages in thread
* [gentoo-commits] proj/portage:master commit in: pym/portage/tests/
@ 2011-10-09 20:41 Mike Frysinger
  0 siblings, 0 replies; 19+ messages in thread
From: Mike Frysinger @ 2011-10-09 20:41 UTC (permalink / raw
  To: gentoo-commits

commit:     7dc6f767eb849040bd933046a3f8aa2938e04b13
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Sun Oct  9 18:39:39 2011 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Sun Oct  9 20:40:43 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=7dc6f767

tests: split up getTests into helper funcs to avoid duplication

This avoids a little duplication between the getTestFromCommandLine and
getTests funcs, and they'll get utilized even more in follow up patches.

Signed-off-by: Mike Frysinger <vapier <AT> gentoo.org>

---
 pym/portage/tests/__init__.py |   37 +++++++++++++++++--------------------
 1 files changed, 17 insertions(+), 20 deletions(-)

diff --git a/pym/portage/tests/__init__.py b/pym/portage/tests/__init__.py
index 3897aba..7f1ed3f 100644
--- a/pym/portage/tests/__init__.py
+++ b/pym/portage/tests/__init__.py
@@ -55,7 +55,7 @@ def my_import(name):
 	return mod
 
 def getTestFromCommandLine(args, base_path):
-	ret = []
+	result = []
 	for arg in args:
 		realpath = os.path.realpath(arg)
 		path = os.path.dirname(realpath)
@@ -65,29 +65,16 @@ def getTestFromCommandLine(args, base_path):
 			raise Exception("Invalid argument: '%s'" % arg)
 
 		mymodule = f[:-3]
+		result.extend(getTestsFromFiles(path, base_path, [mymodule]))
+	return result
 
-		parent_path = path[len(base_path)+1:]
-		parent_module = ".".join(("portage", "tests", parent_path))
-		parent_module = parent_module.replace('/', '.')
-		result = []
-
-		# Make the trailing / a . for module importing
-		modname = ".".join((parent_module, mymodule))
-		mod = my_import(modname)
-		ret.append(unittest.TestLoader().loadTestsFromModule(mod))
-	return ret
-
-def getTests(path, base_path):
-	"""
-
-	path is the path to a given subdir ( 'portage/' for example)
-	This does a simple filter on files in that dir to give us modules
-	to import
-
-	"""
+def getTestNames(path):
 	files = os.listdir(path)
 	files = [ f[:-3] for f in files if f.startswith("test") and f.endswith(".py") ]
 	files.sort()
+	return files
+
+def getTestsFromFiles(path, base_path, files):
 	parent_path = path[len(base_path)+1:]
 	parent_module = ".".join(("portage", "tests", parent_path))
 	parent_module = parent_module.replace('/', '.')
@@ -99,6 +86,16 @@ def getTests(path, base_path):
 		result.append(unittest.TestLoader().loadTestsFromModule(mod))
 	return result
 
+def getTests(path, base_path):
+	"""
+
+	path is the path to a given subdir ( 'portage/' for example)
+	This does a simple filter on files in that dir to give us modules
+	to import
+
+	"""
+	return getTestsFromFiles(path, base_path, getTestNames(path))
+
 class TextTestResult(_TextTestResult):
 	"""
 	We need a subclass of unittest._TextTestResult to handle tests with TODO



^ permalink raw reply related	[flat|nested] 19+ messages in thread
* [gentoo-commits] proj/portage:master commit in: pym/portage/tests/
@ 2011-10-08 21:54 Mike Frysinger
  0 siblings, 0 replies; 19+ messages in thread
From: Mike Frysinger @ 2011-10-08 21:54 UTC (permalink / raw
  To: gentoo-commits

commit:     5dbf25fc1ff3d951f3936662283c37a03afce4ca
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Sat Oct  8 21:53:34 2011 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Sat Oct  8 21:53:59 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=5dbf25fc

tests: fix whitespace to be consistent

Signed-off-by: Mike Frysinger <vapier <AT> gentoo.org>

---
 pym/portage/tests/__init__.py |   20 ++++++++++----------
 1 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/pym/portage/tests/__init__.py b/pym/portage/tests/__init__.py
index dcf73ba..3897aba 100644
--- a/pym/portage/tests/__init__.py
+++ b/pym/portage/tests/__init__.py
@@ -27,7 +27,7 @@ def main():
 		suite.addTests(getTestFromCommandLine(sys.argv[1:], basedir))
 		return TextTestRunner(verbosity=2).run(suite)
 
-  # the os.walk help mentions relative paths as being quirky
+	# the os.walk help mentions relative paths as being quirky
 	# I was tired of adding dirs to the list, so now we add __test__
 	# to each dir we want tested.
 	for root, dirs, files in os.walk(basedir):
@@ -206,21 +206,21 @@ class TestCase(unittest.TestCase):
 		   unexpected exception.
 		"""
 		try:
-		    callableObj(*args, **kwargs)
+			callableObj(*args, **kwargs)
 		except excClass:
-		    return
+			return
 		else:
-		    if hasattr(excClass,'__name__'): excName = excClass.__name__
-		    else: excName = str(excClass)
-		    raise self.failureException("%s not raised: %s" % (excName, msg))
-			
+			if hasattr(excClass,'__name__'): excName = excClass.__name__
+			else: excName = str(excClass)
+			raise self.failureException("%s not raised: %s" % (excName, msg))
+
 class TextTestRunner(unittest.TextTestRunner):
 	"""
 	We subclass unittest.TextTestRunner to output SKIP for tests that fail but are skippable
 	"""
-	
+
 	def _makeResult(self):
-	        return TextTestResult(self.stream, self.descriptions, self.verbosity)
+		return TextTestResult(self.stream, self.descriptions, self.verbosity)
 
 	def run(self, test):
 		"""
@@ -250,7 +250,7 @@ class TextTestRunner(unittest.TextTestRunner):
 		else:
 			self.stream.writeln("OK")
 		return result
-	
+
 test_cps = ['sys-apps/portage','virtual/portage']
 test_versions = ['1.0', '1.0-r1','2.3_p4','1.0_alpha57']
 test_slots = [ None, '1','gentoo-sources-2.6.17','spankywashere']



^ permalink raw reply related	[flat|nested] 19+ messages in thread
* [gentoo-commits] proj/portage:master commit in: pym/portage/tests/
@ 2011-08-29  2:59 Zac Medico
  0 siblings, 0 replies; 19+ messages in thread
From: Zac Medico @ 2011-08-29  2:59 UTC (permalink / raw
  To: gentoo-commits

commit:     ab21cd451955ff7ed9419ffdbe3dc34bbb397281
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Mon Aug 29 02:59:01 2011 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Mon Aug 29 02:59:01 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=ab21cd45

Sort test cases, for predictable order.

---
 pym/portage/tests/__init__.py |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/pym/portage/tests/__init__.py b/pym/portage/tests/__init__.py
index 6f21d10..dcf73ba 100644
--- a/pym/portage/tests/__init__.py
+++ b/pym/portage/tests/__init__.py
@@ -42,6 +42,7 @@ def main():
 		if TEST_FILE in files:
 			testDirs.append(root)
 
+	testDirs.sort()
 	for mydir in testDirs:
 		suite.addTests(getTests(os.path.join(basedir, mydir), basedir) )
 	return TextTestRunner(verbosity=2).run(suite)
@@ -86,6 +87,7 @@ def getTests(path, base_path):
 	"""
 	files = os.listdir(path)
 	files = [ f[:-3] for f in files if f.startswith("test") and f.endswith(".py") ]
+	files.sort()
 	parent_path = path[len(base_path)+1:]
 	parent_module = ".".join(("portage", "tests", parent_path))
 	parent_module = parent_module.replace('/', '.')



^ permalink raw reply related	[flat|nested] 19+ messages in thread
* [gentoo-commits] proj/portage:master commit in: pym/portage/tests/
@ 2011-08-26  6:13 Zac Medico
  0 siblings, 0 replies; 19+ messages in thread
From: Zac Medico @ 2011-08-26  6:13 UTC (permalink / raw
  To: gentoo-commits

commit:     ebc4f381f351f6c67dd911be1efa2df51de87f07
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Fri Aug 26 06:07:39 2011 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Fri Aug 26 06:07:39 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=ebc4f381

Add skipped test support (for python 2.6 compat)

Python supports skipped tests since 2.7, but we'll implement support
ourselves for python 2.6 compatibility. This is a simple extension of
the todo support that we have already implemented.

---
 pym/portage/tests/__init__.py |   18 +++++++++++++++++-
 1 files changed, 17 insertions(+), 1 deletions(-)

diff --git a/pym/portage/tests/__init__.py b/pym/portage/tests/__init__.py
index dddf386..6f21d10 100644
--- a/pym/portage/tests/__init__.py
+++ b/pym/portage/tests/__init__.py
@@ -109,6 +109,7 @@ class TextTestResult(_TextTestResult):
 	def __init__(self, stream, descriptions, verbosity):
 		super(TextTestResult, self).__init__(stream, descriptions, verbosity)
 		self.todoed = []
+		self.portage_skipped = []
 
 	def addTodo(self, test, info):
 		self.todoed.append((test,info))
@@ -117,12 +118,20 @@ class TextTestResult(_TextTestResult):
 		elif self.dots:
 			self.stream.write(".")
 
+	def addPortageSkip(self, test, info):
+		self.portage_skipped.append((test,info))
+		if self.showAll:
+			self.stream.writeln("SKIP")
+		elif self.dots:
+			self.stream.write(".")
+
 	def printErrors(self):
 		if self.dots or self.showAll:
 			self.stream.writeln()
 			self.printErrorList('ERROR', self.errors)
 			self.printErrorList('FAIL', self.failures)
 			self.printErrorList('TODO', self.todoed)
+			self.printErrorList('SKIP', self.portage_skipped)
 
 class TestCase(unittest.TestCase):
 	"""
@@ -135,6 +144,7 @@ class TestCase(unittest.TestCase):
 	def __init__(self, *pargs, **kwargs):
 		unittest.TestCase.__init__(self, *pargs, **kwargs)
 		self.todo = False
+		self.portage_skip = None
 
 	def defaultTestResult(self):
 		return TextTestResult()
@@ -158,7 +168,13 @@ class TestCase(unittest.TestCase):
 				testMethod()
 				ok = True
 			except self.failureException:
-				if self.todo:
+				if self.portage_skip is not None:
+					if self.portage_skip is True:
+						result.addPortageSkip(self, "%s: SKIP" % testMethod)
+					else:
+						result.addPortageSkip(self, "%s: SKIP: %s" %
+							(testMethod, self.portage_skip))
+				elif self.todo:
 					result.addTodo(self,"%s: TODO" % testMethod)
 				else:
 					result.addFailure(self, sys.exc_info())



^ permalink raw reply related	[flat|nested] 19+ messages in thread
* [gentoo-commits] proj/portage:master commit in: pym/portage/tests/
@ 2011-08-25 21:54 Zac Medico
  0 siblings, 0 replies; 19+ messages in thread
From: Zac Medico @ 2011-08-25 21:54 UTC (permalink / raw
  To: gentoo-commits

commit:     3735e3e1805769fcaae2ef450907db7508355ec9
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Thu Aug 25 21:54:34 2011 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Thu Aug 25 21:54:34 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=3735e3e1

TestCase: remove python 2.4 compat constructor

---
 pym/portage/tests/__init__.py |   14 +++++---------
 1 files changed, 5 insertions(+), 9 deletions(-)

diff --git a/pym/portage/tests/__init__.py b/pym/portage/tests/__init__.py
index a647aa2..dddf386 100644
--- a/pym/portage/tests/__init__.py
+++ b/pym/portage/tests/__init__.py
@@ -1,5 +1,5 @@
 # tests/__init__.py -- Portage Unit Test functionality
-# Copyright 2006-2010 Gentoo Foundation
+# Copyright 2006-2011 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 import sys
@@ -131,15 +131,11 @@ class TestCase(unittest.TestCase):
 	and then fix the code later.  This may not be a great approach
 	(broken code!!??!11oneone) but it does happen at times.
 	"""
-	
-	def __init__(self, methodName='runTest'):
-		# This method exists because unittest.py in python 2.4 stores
-		# the methodName as __testMethodName while 2.5 uses
-		# _testMethodName.
-		self._testMethodName = methodName
-		unittest.TestCase.__init__(self, methodName)
+
+	def __init__(self, *pargs, **kwargs):
+		unittest.TestCase.__init__(self, *pargs, **kwargs)
 		self.todo = False
-		
+
 	def defaultTestResult(self):
 		return TextTestResult()
 



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

end of thread, other threads:[~2018-05-07  0:27 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-09 20:41 [gentoo-commits] proj/portage:master commit in: pym/portage/tests/ Mike Frysinger
  -- strict thread matches above, loose matches on Subject: below --
2018-05-07  0:27 Zac Medico
2014-09-29 22:27 Brian Dolbec
2013-10-21  2:20 Mike Frysinger
2013-10-17  7:31 Mike Frysinger
2013-08-03  1:37 Zac Medico
2013-03-19  8:36 Zac Medico
2013-03-13  4:10 Arfrever Frehtes Taifersar Arahesis
2013-01-31 19:56 Zac Medico
2013-01-03 23:31 Zac Medico
2011-12-16  2:42 Zac Medico
2011-10-10  2:22 Zac Medico
2011-10-10  1:55 Zac Medico
2011-10-09 20:41 Mike Frysinger
2011-10-09 20:41 Mike Frysinger
2011-10-08 21:54 Mike Frysinger
2011-08-29  2:59 Zac Medico
2011-08-26  6:13 Zac Medico
2011-08-25 21:54 Zac Medico

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