summaryrefslogtreecommitdiff
path: root/lib/subunit/python/testtools/tests
diff options
context:
space:
mode:
Diffstat (limited to 'lib/subunit/python/testtools/tests')
-rw-r--r--lib/subunit/python/testtools/tests/__init__.py2
-rw-r--r--lib/subunit/python/testtools/tests/test_matchers.py45
-rw-r--r--lib/subunit/python/testtools/tests/test_testtools.py16
3 files changed, 61 insertions, 2 deletions
diff --git a/lib/subunit/python/testtools/tests/__init__.py b/lib/subunit/python/testtools/tests/__init__.py
index e1d1148d5c..2cceba91e2 100644
--- a/lib/subunit/python/testtools/tests/__init__.py
+++ b/lib/subunit/python/testtools/tests/__init__.py
@@ -1,3 +1,5 @@
+"""Tests for testtools itself."""
+
# See README for copyright and licensing details.
import unittest
diff --git a/lib/subunit/python/testtools/tests/test_matchers.py b/lib/subunit/python/testtools/tests/test_matchers.py
index a9f4b245eb..d5fd8bab3b 100644
--- a/lib/subunit/python/testtools/tests/test_matchers.py
+++ b/lib/subunit/python/testtools/tests/test_matchers.py
@@ -12,6 +12,9 @@ from testtools.matchers import (
Equals,
DocTestMatches,
MatchesAny,
+ MatchesAll,
+ Not,
+ NotEquals,
)
@@ -81,6 +84,31 @@ class TestEqualsInterface(TestCase, TestMatchersInterface):
describe_examples = [("1 != 2", 2, Equals(1))]
+class TestNotEqualsInterface(TestCase, TestMatchersInterface):
+
+ matches_matcher = NotEquals(1)
+ matches_matches = [2]
+ matches_mismatches = [1]
+
+ str_examples = [
+ ("NotEquals(1)", NotEquals(1)), ("NotEquals('1')", NotEquals('1'))]
+
+ describe_examples = [("1 == 1", 1, NotEquals(1))]
+
+
+class TestNotInterface(TestCase, TestMatchersInterface):
+
+ matches_matcher = Not(Equals(1))
+ matches_matches = [2]
+ matches_mismatches = [1]
+
+ str_examples = [
+ ("Not(Equals(1))", Not(Equals(1))),
+ ("Not(Equals('1'))", Not(Equals('1')))]
+
+ describe_examples = [('1 matches Equals(1)', 1, Not(Equals(1)))]
+
+
class TestMatchersAnyInterface(TestCase, TestMatchersInterface):
matches_matcher = MatchesAny(DocTestMatches("1"), DocTestMatches("2"))
@@ -108,6 +136,23 @@ Got:
"3", MatchesAny(DocTestMatches("1"), DocTestMatches("2")))]
+class TestMatchesAllInterface(TestCase, TestMatchersInterface):
+
+ matches_matcher = MatchesAll(NotEquals(1), NotEquals(2))
+ matches_matches = [3, 4]
+ matches_mismatches = [1, 2]
+
+ str_examples = [
+ ("MatchesAll(NotEquals(1), NotEquals(2))",
+ MatchesAll(NotEquals(1), NotEquals(2)))]
+
+ describe_examples = [("""Differences: [
+1 == 1
+]
+""",
+ 1, MatchesAll(NotEquals(1), NotEquals(2)))]
+
+
def test_suite():
from unittest import TestLoader
return TestLoader().loadTestsFromName(__name__)
diff --git a/lib/subunit/python/testtools/tests/test_testtools.py b/lib/subunit/python/testtools/tests/test_testtools.py
index 8cd90de6fe..af1fd794c3 100644
--- a/lib/subunit/python/testtools/tests/test_testtools.py
+++ b/lib/subunit/python/testtools/tests/test_testtools.py
@@ -223,6 +223,12 @@ class TestAssertions(TestCase):
self.assertFails('None is not 42', self.assertIs, None, 42)
self.assertFails('[42] is not [42]', self.assertIs, [42], [42])
+ def test_assertIs_fails_with_message(self):
+ # assertIs raises assertion errors if one object is not identical to
+ # another, and includes a user-supplied message, if it's provided.
+ self.assertFails(
+ 'None is not 42: foo bar', self.assertIs, None, 42, 'foo bar')
+
def test_assertIsNot(self):
# assertIsNot asserts that an object is not identical to another
# object.
@@ -238,6 +244,12 @@ class TestAssertions(TestCase):
self.assertFails(
'[42] is [42]', self.assertIsNot, some_list, some_list)
+ def test_assertIsNot_fails_with_message(self):
+ # assertIsNot raises assertion errors if one object is identical to
+ # another, and includes a user-supplied message if it's provided.
+ self.assertFails(
+ 'None is None: foo bar', self.assertIsNot, None, None, "foo bar")
+
def test_assertThat_matches_clean(self):
class Matcher:
def match(self, foo):
@@ -303,12 +315,12 @@ class TestAddCleanup(TestCase):
self.assertEqual(messages, [call[0] for call in self._result_calls])
def assertTestLogEqual(self, messages):
- """Assert that the call log equals `messages`."""
+ """Assert that the call log equals 'messages'."""
case = self._result_calls[0][1]
self.assertEqual(messages, case._calls)
def logAppender(self, message):
- """A cleanup that appends `message` to the tests log.
+ """A cleanup that appends 'message' to the tests log.
Cleanups are callables that are added to a test by addCleanup. To
verify that our cleanups run in the right order, we add strings to a