summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorRobert Collins <robertc@robertcollins.net>2009-10-04 21:09:40 +1100
committerRobert Collins <robertc@robertcollins.net>2009-10-04 21:09:40 +1100
commit47dc87aec4dc886ae625074c7d03410422453a31 (patch)
tree8044e69c082096887164b8b8b2230888bfcf295a /python
parent32f4cb1fb06fa08a76c75bc0881ef9a17e6c17d2 (diff)
downloadsubunit-git-47dc87aec4dc886ae625074c7d03410422453a31.tar.gz
Add ContentType class.
Diffstat (limited to 'python')
-rw-r--r--python/subunit/content_type.py35
-rw-r--r--python/subunit/tests/__init__.py2
-rw-r--r--python/subunit/tests/test_content_type.py49
3 files changed, 86 insertions, 0 deletions
diff --git a/python/subunit/content_type.py b/python/subunit/content_type.py
new file mode 100644
index 0000000..cafc437
--- /dev/null
+++ b/python/subunit/content_type.py
@@ -0,0 +1,35 @@
+#
+# subunit: extensions to Python unittest to get test results from subprocesses.
+# Copyright (C) 2009 Robert Collins <robertc@robertcollins.net>
+#
+# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
+# license at the users choice. A copy of both licenses are available in the
+# project source as Apache-2.0 and BSD. You may not use this file except in
+# compliance with one of these two licences.
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# license you chose for the specific language governing permissions and
+# limitations under that license.
+#
+
+"""ContentType - a MIME Content Type."""
+
+class ContentType(object):
+ """A content type from http://www.iana.org/assignments/media-types/
+
+ :ivar type: The primary type, e.g. "text" or "application"
+ :ivar subtype: The subtype, e.g. "plain" or "octet-stream"
+ :ivar parameters: A dict of additional parameters specific to the
+ content type.
+ """
+
+ def __init__(self, primary_type, sub_type, parameters=None):
+ """Create a ContentType."""
+ if None in (primary_type, sub_type):
+ raise ValueError("None not permitted in %r, %r" % (
+ primary_type, sub_type))
+ self.type = primary_type
+ self.subtype = sub_type
+ self.parameters = parameters or {}
diff --git a/python/subunit/tests/__init__.py b/python/subunit/tests/__init__.py
index 36e93ba..d0648f2 100644
--- a/python/subunit/tests/__init__.py
+++ b/python/subunit/tests/__init__.py
@@ -16,6 +16,7 @@
from subunit.tests import (
TestUtil,
+ test_content_type,
test_progress_model,
test_subunit_filter,
test_subunit_stats,
@@ -27,6 +28,7 @@ from subunit.tests import (
def test_suite():
result = TestUtil.TestSuite()
+ result.addTest(test_content_type.test_suite())
result.addTest(test_progress_model.test_suite())
result.addTest(test_test_results.test_suite())
result.addTest(test_test_protocol.test_suite())
diff --git a/python/subunit/tests/test_content_type.py b/python/subunit/tests/test_content_type.py
new file mode 100644
index 0000000..fea9a9b
--- /dev/null
+++ b/python/subunit/tests/test_content_type.py
@@ -0,0 +1,49 @@
+#
+# subunit: extensions to Python unittest to get test results from subprocesses.
+# Copyright (C) 2009 Robert Collins <robertc@robertcollins.net>
+#
+# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
+# license at the users choice. A copy of both licenses are available in the
+# project source as Apache-2.0 and BSD. You may not use this file except in
+# compliance with one of these two licences.
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# license you chose for the specific language governing permissions and
+# limitations under that license.
+#
+
+import datetime
+import unittest
+from StringIO import StringIO
+import os
+import subunit
+from subunit.content_type import ContentType
+import sys
+
+import subunit.iso8601 as iso8601
+
+
+def test_suite():
+ loader = subunit.tests.TestUtil.TestLoader()
+ result = loader.loadTestsFromName(__name__)
+ return result
+
+
+class TestContentType(unittest.TestCase):
+
+ def test___init___None_errors(self):
+ self.assertRaises(ValueError, ContentType, None, None)
+ self.assertRaises(ValueError, ContentType, None, "traceback")
+ self.assertRaises(ValueError, ContentType, "text", None)
+
+ def test___init___sets_ivars(self):
+ content_type = ContentType("foo", "bar")
+ self.assertEqual("foo", content_type.type)
+ self.assertEqual("bar", content_type.subtype)
+ 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)