~bzr/ubuntu/natty/python-testtools/bzr-ppa

« back to all changes in this revision

Viewing changes to testtools/tests/test_content_type.py

  • Committer: Robert Collins
  • Date: 2010-11-14 15:49:58 UTC
  • mfrom: (16.11.4 upstream)
  • Revision ID: robertc@robertcollins.net-20101114154958-lwb16rdhehq6q020
New snapshot for testing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright (c) 2008 Jonathan M. Lange. See LICENSE for details.
2
2
 
3
 
import unittest
4
 
from testtools.content_type import ContentType
5
 
 
6
 
 
7
 
def test_suite():
8
 
    from unittest import TestLoader
9
 
    return TestLoader().loadTestsFromName(__name__)
10
 
 
11
 
 
12
 
class TestContentType(unittest.TestCase):
 
3
from testtools import TestCase
 
4
from testtools.matchers import Equals, MatchesException, Raises
 
5
from testtools.content_type import ContentType, UTF8_TEXT
 
6
 
 
7
 
 
8
class TestContentType(TestCase):
13
9
 
14
10
    def test___init___None_errors(self):
15
 
        self.assertRaises(ValueError, ContentType, None, None)
16
 
        self.assertRaises(ValueError, ContentType, None, "traceback")
17
 
        self.assertRaises(ValueError, ContentType, "text", None)
 
11
        raises_value_error = Raises(MatchesException(ValueError))
 
12
        self.assertThat(lambda:ContentType(None, None), raises_value_error)
 
13
        self.assertThat(lambda:ContentType(None, "traceback"),
 
14
            raises_value_error)
 
15
        self.assertThat(lambda:ContentType("text", None), raises_value_error)
18
16
 
19
17
    def test___init___sets_ivars(self):
20
18
        content_type = ContentType("foo", "bar")
23
21
        self.assertEqual({}, content_type.parameters)
24
22
 
25
23
    def test___init___with_parameters(self):
26
 
        content_type = ContentType("foo", "bar", {"quux":"thing"})
27
 
        self.assertEqual({"quux":"thing"}, content_type.parameters)
 
24
        content_type = ContentType("foo", "bar", {"quux": "thing"})
 
25
        self.assertEqual({"quux": "thing"}, content_type.parameters)
28
26
 
29
27
    def test___eq__(self):
30
 
        content_type1 = ContentType("foo", "bar", {"quux":"thing"})
31
 
        content_type2 = ContentType("foo", "bar", {"quux":"thing"})
32
 
        content_type3 = ContentType("foo", "bar", {"quux":"thing2"})
 
28
        content_type1 = ContentType("foo", "bar", {"quux": "thing"})
 
29
        content_type2 = ContentType("foo", "bar", {"quux": "thing"})
 
30
        content_type3 = ContentType("foo", "bar", {"quux": "thing2"})
33
31
        self.assertTrue(content_type1.__eq__(content_type2))
34
32
        self.assertFalse(content_type1.__eq__(content_type3))
 
33
 
 
34
 
 
35
class TestBuiltinContentTypes(TestCase):
 
36
 
 
37
    def test_plain_text(self):
 
38
        # The UTF8_TEXT content type represents UTF-8 encoded text/plain.
 
39
        self.assertThat(UTF8_TEXT.type, Equals('text'))
 
40
        self.assertThat(UTF8_TEXT.subtype, Equals('plain'))
 
41
        self.assertThat(UTF8_TEXT.parameters, Equals({'charset': 'utf8'}))
 
42
 
 
43
 
 
44
def test_suite():
 
45
    from unittest import TestLoader
 
46
    return TestLoader().loadTestsFromName(__name__)