← Back to team overview

testtools-dev team mailing list archive

[Merge] lp:~jml/testtools/detail-tweaks into lp:testtools

 

Jonathan Lange has proposed merging lp:~jml/testtools/detail-tweaks into lp:testtools.

Requested reviews:
  testtools developers (testtools-dev)


This patch adds a PLAIN_TEXT content type, which ought to make using details a little easier.
-- 
https://code.launchpad.net/~jml/testtools/detail-tweaks/+merge/31307
Your team testtools developers is requested to review the proposed merge of lp:~jml/testtools/detail-tweaks into lp:testtools.
=== modified file 'testtools/content_type.py'
--- testtools/content_type.py	2010-01-16 01:12:24 +0000
+++ testtools/content_type.py	2010-07-29 17:26:40 +0000
@@ -28,3 +28,6 @@
 
     def __repr__(self):
         return "%s/%s params=%s" % (self.type, self.subtype, self.parameters)
+
+
+PLAIN_TEXT = ContentType('text', 'plain', {'charset': 'utf8'})

=== modified file 'testtools/tests/test_content.py'
--- testtools/tests/test_content.py	2010-06-18 21:35:11 +0000
+++ testtools/tests/test_content.py	2010-07-29 17:26:40 +0000
@@ -1,18 +1,17 @@
 # Copyright (c) 2008 Jonathan M. Lange. See LICENSE for details.
 
 import unittest
+<<<<<<< TREE
 from testtools.compat import _u
+=======
+from testtools import TestCase
+>>>>>>> MERGE-SOURCE
 from testtools.content import Content, TracebackContent
 from testtools.content_type import ContentType
 from testtools.tests.helpers import an_exc_info
 
 
-def test_suite():
-    from unittest import TestLoader
-    return TestLoader().loadTestsFromName(__name__)
-
-
-class TestContent(unittest.TestCase):
+class TestContent(TestCase):
 
     def test___init___None_errors(self):
         self.assertRaises(ValueError, Content, None, None)
@@ -57,7 +56,7 @@
         self.assertEqual([text], list(content.iter_text()))
 
 
-class TestTracebackContent(unittest.TestCase):
+class TestTracebackContent(TestCase):
 
     def test___init___None_errors(self):
         self.assertRaises(ValueError, TracebackContent, None, None)
@@ -70,3 +69,8 @@
         result = unittest.TestResult()
         expected = result._exc_info_to_string(an_exc_info, self)
         self.assertEqual(expected, ''.join(list(content.iter_text())))
+
+
+def test_suite():
+    from unittest import TestLoader
+    return TestLoader().loadTestsFromName(__name__)

=== modified file 'testtools/tests/test_content_type.py'
--- testtools/tests/test_content_type.py	2009-10-28 10:29:30 +0000
+++ testtools/tests/test_content_type.py	2010-07-29 17:26:40 +0000
@@ -1,15 +1,11 @@
 # Copyright (c) 2008 Jonathan M. Lange. See LICENSE for details.
 
-import unittest
-from testtools.content_type import ContentType
-
-
-def test_suite():
-    from unittest import TestLoader
-    return TestLoader().loadTestsFromName(__name__)
-
-
-class TestContentType(unittest.TestCase):
+from testtools import TestCase
+from testtools.matchers import Equals
+from testtools.content_type import ContentType, PLAIN_TEXT
+
+
+class TestContentType(TestCase):
 
     def test___init___None_errors(self):
         self.assertRaises(ValueError, ContentType, None, None)
@@ -23,12 +19,26 @@
         self.assertEqual({}, content_type.parameters)
 
     def test___init___with_parameters(self):
-        content_type = ContentType("foo", "bar", {"quux":"thing"})
-        self.assertEqual({"quux":"thing"}, content_type.parameters)
+        content_type = ContentType("foo", "bar", {"quux": "thing"})
+        self.assertEqual({"quux": "thing"}, content_type.parameters)
 
     def test___eq__(self):
-        content_type1 = ContentType("foo", "bar", {"quux":"thing"})
-        content_type2 = ContentType("foo", "bar", {"quux":"thing"})
-        content_type3 = ContentType("foo", "bar", {"quux":"thing2"})
+        content_type1 = ContentType("foo", "bar", {"quux": "thing"})
+        content_type2 = ContentType("foo", "bar", {"quux": "thing"})
+        content_type3 = ContentType("foo", "bar", {"quux": "thing2"})
         self.assertTrue(content_type1.__eq__(content_type2))
         self.assertFalse(content_type1.__eq__(content_type3))
+
+
+class TestBuiltinContentTypes(TestCase):
+
+    def test_plain_text(self):
+        # The PLAIN_TEXT content type represents UTF-8 encoded text/plain.
+        self.assertThat(PLAIN_TEXT.type, Equals('text'))
+        self.assertThat(PLAIN_TEXT.subtype, Equals('plain'))
+        self.assertThat(PLAIN_TEXT.parameters, Equals({'charset': 'utf8'}))
+
+
+def test_suite():
+    from unittest import TestLoader
+    return TestLoader().loadTestsFromName(__name__)


Follow ups