From: "Michał Górny" <mgorny@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/pms-test-suite:master commit in: pmstestsuite/library/
Date: Tue, 2 Aug 2011 18:53:07 +0000 (UTC) [thread overview]
Message-ID: <c8f668f617583998ed87b85f051846036631dbef.mgorny@gentoo> (raw)
commit: c8f668f617583998ed87b85f051846036631dbef
Author: Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Tue Aug 2 18:54:02 2011 +0000
Commit: Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Tue Aug 2 18:54:02 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/pms-test-suite.git;a=commit;h=c8f668f6
Store assertion results.
---
pmstestsuite/library/case.py | 109 ++++++++++++++++++++++++++++++++++++++----
1 files changed, 100 insertions(+), 9 deletions(-)
diff --git a/pmstestsuite/library/case.py b/pmstestsuite/library/case.py
index 956a1a3..5295002 100644
--- a/pmstestsuite/library/case.py
+++ b/pmstestsuite/library/case.py
@@ -3,7 +3,7 @@
# Released under the terms of the 2-clause BSD license.
import copy, random, re
-from gentoopm.util import ABCObject
+from gentoopm.util import ABCObject, BoolCompat
from abc import ABCMeta, abstractmethod, abstractproperty
@@ -53,6 +53,92 @@ def cleanup_test_case_name(classname):
classname = classname[:-4]
return pn_re.sub('\\1-\\2', classname).lower()
+class AssertionResult(ABCObject, BoolCompat):
+ def __init__(self, name):
+ self._name = name
+
+ @property
+ def name(self):
+ return self._name
+
+ @abstractproperty
+ def expected(self):
+ pass
+
+ @abstractproperty
+ def actual(self):
+ pass
+
+ @abstractmethod
+ def __bool__(self):
+ pass
+
+ def __str__(self):
+ return '%s == %s' % (self.actual, self.expected)
+
+class BoolAssertionResult(AssertionResult):
+ def __init__(self, name, expect, cond):
+ AssertionResult.__init__(self, name)
+ self._expect = bool(expect)
+ self._cond = bool(cond)
+
+ @property
+ def expected(self):
+ return self._expect
+
+ @property
+ def actual(self):
+ return self._cond
+
+ def __bool__(self):
+ return self._cond == self._expect
+
+class ContainsAssertionResult(AssertionResult):
+ def __init__(self, name, needle, container):
+ AssertionResult.__init__(self, name)
+ self._cont = container
+ self._need = needle
+
+ @property
+ def expected(self):
+ return 'contains %s' % repr(self._need)
+
+ @property
+ def actual(self):
+ return repr(self._cont)
+
+ def __bool__(self):
+ return self._need in self._cont
+
+class EqualAssertionResult(AssertionResult):
+ def __init__(self, name, expect, value):
+ AssertionResult.__init__(self, name)
+ self._expect = expect
+ self._value = value
+
+ @property
+ def expected(self):
+ return repr(self._expect)
+
+ @property
+ def actual(self):
+ return repr(self._value)
+
+ def __bool__(self):
+ return self._value == self._expect
+
+class NotEqualAssertionResult(EqualAssertionResult):
+ def __bool__(self):
+ return self._value != self._expect
+
+ @property
+ def expected(self):
+ return 'not %s' % repr(self._expect)
+
+ def __str__(self):
+ return '%s != %s' % (self.actual,
+ repr(self._expect))
+
class TestCase(ABCObject):
"""
Base class for a test case.
@@ -64,6 +150,9 @@ class TestCase(ABCObject):
_finalized = False
+ def __init__(self):
+ self.assertions = []
+
def _finalize(self):
"""
Do any final modifications to test case data. Mark it finalized.
@@ -102,6 +191,11 @@ class TestCase(ABCObject):
"""
pass
+ def _append_assert(self, a):
+ self.assertions.append(a)
+ if not a:
+ raise AssertionError(str(a))
+
def assertTrue(self, cond, msg):
"""
Assert that the condition evaluates to True.
@@ -135,8 +229,7 @@ class TestCase(ABCObject):
@param msg: assertion description
@type msg: string
"""
- if bool(cond) != expect:
- raise AssertionError(msg)
+ self._append_assert(BoolAssertionResult(msg, expect, cond))
def assertContains(self, needle, container, msg = None):
"""
@@ -151,8 +244,7 @@ class TestCase(ABCObject):
"""
if msg is None:
msg = '%s in %s' % (repr(needle), repr(container))
- if needle not in container:
- raise AssertionError(msg)
+ self._append_assert(ContainsAssertionResult(msg, needle, container))
def assertEqual(self, value, expect, msg):
"""
@@ -165,8 +257,7 @@ class TestCase(ABCObject):
@param msg: assertion description
@type msg: string
"""
- if value != expect:
- raise AssertionError(msg)
+ self._append_assert(EqualAssertionResult(msg, expect, value))
def assertNotEqual(self, value, unallowed, msg):
"""
@@ -179,8 +270,7 @@ class TestCase(ABCObject):
@param msg: assertion description
@type msg: string
"""
- if value == unallowed:
- raise AssertionError(msg)
+ self._append_assert(NotEqualAssertionResult(msg, unallowed, value))
@abstractmethod
def check_result(self, pm):
@@ -324,6 +414,7 @@ class EbuildTestCase(TestCase):
@param eapi: the EAPI
@type eapi: string
"""
+ TestCase.__init__(self)
self.eapi = eapi
for v in ('ebuild_vars', 'inherits', 'phase_funcs'):
next reply other threads:[~2011-08-02 18:53 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-02 18:53 Michał Górny [this message]
-- strict thread matches above, loose matches on Subject: below --
2012-01-03 15:52 [gentoo-commits] proj/pms-test-suite:master commit in: pmstestsuite/library/ Michał Górny
2012-01-02 22:26 Michał Górny
2011-08-12 20:55 Michał Górny
2011-08-11 22:09 Michał Górny
2011-08-11 22:09 Michał Górny
2011-08-11 8:54 Michał Górny
2011-08-11 8:53 Michał Górny
2011-08-06 14:26 Michał Górny
2011-08-06 14:25 Michał Górny
2011-08-06 14:25 Michał Górny
2011-08-03 20:17 Michał Górny
2011-08-03 20:17 Michał Górny
2011-08-03 8:17 Michał Górny
2011-08-02 18:53 Michał Górny
2011-08-02 18:53 Michał Górny
2011-08-02 18:53 Michał Górny
2011-07-24 14:37 Michał Górny
2011-06-29 17:52 Michał Górny
2011-06-29 17:52 Michał Górny
2011-06-29 17:52 Michał Górny
2011-06-29 17:52 Michał Górny
2011-06-29 17:52 Michał Górny
2011-06-29 17:52 Michał Górny
2011-06-23 21:14 [gentoo-commits] proj/pms-test-suite:master commit in: PMSTestSuite/library/ Michał Górny
2011-06-23 21:14 Michał Górny
2011-06-20 19:20 Michał Górny
2011-06-17 15:07 Michał Górny
2011-06-17 5:59 Michał Górny
2011-06-16 19:49 Michał Górny
2011-06-16 19:49 Michał Górny
2011-06-14 12:35 Michał Górny
2011-06-14 8:32 Michał Górny
2011-06-14 8:32 Michał Górny
2011-06-13 19:16 Michał Górny
2011-06-13 19:16 Michał Górny
2011-06-07 17:22 Michał Górny
2011-06-03 17:36 Michał Górny
2011-05-31 17:19 Michał Górny
2011-05-29 18:57 Michał Górny
2011-05-29 18:57 Michał Górny
2011-05-29 18:57 Michał Górny
2011-05-29 18:17 Michał Górny
2011-05-26 7:25 Michał Górny
2011-05-26 6:35 Michał Górny
2011-05-25 20:40 Michał Górny
2011-05-24 14:28 Michał Górny
2011-05-24 8:11 Michał Górny
2011-05-24 8:11 Michał Górny
2011-05-24 8:11 Michał Górny
2011-05-23 11:52 Michał Górny
2011-05-23 9:51 Michał Górny
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=c8f668f617583998ed87b85f051846036631dbef.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