summaryrefslogtreecommitdiff
path: root/python/qpid/tests
diff options
context:
space:
mode:
authorRafael H. Schloming <rhs@apache.org>2009-12-09 18:08:14 +0000
committerRafael H. Schloming <rhs@apache.org>2009-12-09 18:08:14 +0000
commit1af1e7bb70a66793b055bf9ec2f9cc49dd1b3859 (patch)
treeee940af45fd12b7a106462ed63a7775e6e6520ff /python/qpid/tests
parentc87bce67ac12ee37f8257efd02ab62fe19336b32 (diff)
downloadqpid-python-1af1e7bb70a66793b055bf9ec2f9cc49dd1b3859.tar.gz
split out some of the generic parsing stuff in the address parser, and added a real mimetype parser in anticipation of a fix for QPID-2255
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@888901 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'python/qpid/tests')
-rw-r--r--python/qpid/tests/__init__.py2
-rw-r--r--python/qpid/tests/address.py28
-rw-r--r--python/qpid/tests/mimetype.py56
-rw-r--r--python/qpid/tests/parser.py37
4 files changed, 106 insertions, 17 deletions
diff --git a/python/qpid/tests/__init__.py b/python/qpid/tests/__init__.py
index 6d227dd656..2f0fcfdf67 100644
--- a/python/qpid/tests/__init__.py
+++ b/python/qpid/tests/__init__.py
@@ -25,4 +25,4 @@ class Test:
def configure(self, config):
self.config = config
-import address, framing, messaging
+import address, framing, mimetype, messaging
diff --git a/python/qpid/tests/address.py b/python/qpid/tests/address.py
index 065e2ca8de..f772425e42 100644
--- a/python/qpid/tests/address.py
+++ b/python/qpid/tests/address.py
@@ -19,12 +19,20 @@
from qpid.tests import Test
from qpid.address import lex, parse, ParseError, EOF, ID, NUMBER, SYM, WSPACE
+from parser import ParserBase
-class AddressTests(Test):
+class AddressTests(ParserBase, Test):
- def lex(self, addr, *types):
- toks = [t.type for t in lex(addr) if t.type not in (WSPACE, EOF)]
- assert list(types) == toks, "expected %s, got %s" % (types, toks)
+ EXCLUDE = (WSPACE, EOF)
+
+ def do_lex(self, st):
+ return lex(st)
+
+ def do_parse(self, st):
+ return parse(st)
+
+ def valid(self, addr, name=None, subject=None, options=None):
+ ParserBase.valid(self, addr, (name, subject, options))
def testDashInId1(self):
self.lex("foo-bar", ID)
@@ -47,18 +55,6 @@ class AddressTests(Test):
def testNegativeNum(self):
self.lex("-3", NUMBER)
- def valid(self, addr, name=None, subject=None, options=None):
- expected = (name, subject, options)
- got = parse(addr)
- assert expected == got, "expected %s, got %s" % (expected, got)
-
- def invalid(self, addr, error=None):
- try:
- p = parse(addr)
- assert False, "invalid address parsed: %s" % p
- except ParseError, e:
- assert error == str(e), "expected %r, got %r" % (error, str(e))
-
def testHash(self):
self.valid("foo/bar.#", "foo", "bar.#")
diff --git a/python/qpid/tests/mimetype.py b/python/qpid/tests/mimetype.py
new file mode 100644
index 0000000000..22760316f0
--- /dev/null
+++ b/python/qpid/tests/mimetype.py
@@ -0,0 +1,56 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+from qpid.tests import Test
+from qpid.mimetype import lex, parse, ParseError, EOF, WSPACE
+from parser import ParserBase
+
+class MimeTypeTests(ParserBase, Test):
+
+ EXCLUDE = (WSPACE, EOF)
+
+ def do_lex(self, st):
+ return lex(st)
+
+ def do_parse(self, st):
+ return parse(st)
+
+ def valid(self, addr, type=None, subtype=None, parameters=None):
+ ParserBase.valid(self, addr, (type, subtype, parameters))
+
+ def testTypeOnly(self):
+ self.invalid("type", "expecting SLASH, got EOF line:1,4:type")
+
+ def testTypeSubtype(self):
+ self.valid("type/subtype", "type", "subtype", [])
+
+ def testTypeSubtypeParam(self):
+ self.valid("type/subtype ; name=value",
+ "type", "subtype", [("name", "value")])
+
+ def testTypeSubtypeParamComment(self):
+ self.valid("type/subtype ; name(This is a comment.)=value",
+ "type", "subtype", [("name", "value")])
+
+ def testMultipleParams(self):
+ self.valid("type/subtype ; name1=value1 ; name2=value2",
+ "type", "subtype", [("name1", "value1"), ("name2", "value2")])
+
+ def testCaseInsensitivity(self):
+ self.valid("Type/Subtype", "type", "subtype", [])
diff --git a/python/qpid/tests/parser.py b/python/qpid/tests/parser.py
new file mode 100644
index 0000000000..a4865cc9fe
--- /dev/null
+++ b/python/qpid/tests/parser.py
@@ -0,0 +1,37 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+from qpid.parser import ParseError
+
+class ParserBase:
+
+ def lex(self, addr, *types):
+ toks = [t.type for t in self.do_lex(addr) if t.type not in self.EXCLUDE]
+ assert list(types) == toks, "expected %s, got %s" % (types, toks)
+
+ def valid(self, addr, expected):
+ got = self.do_parse(addr)
+ assert expected == got, "expected %s, got %s" % (expected, got)
+
+ def invalid(self, addr, error=None):
+ try:
+ p = self.do_parse(addr)
+ assert False, "invalid address parsed: %s" % p
+ except ParseError, e:
+ assert error == str(e), "expected %r, got %r" % (error, str(e))