diff options
| author | Ade Oshineye <adewale@gmail.com> | 2010-02-15 17:52:29 -0800 |
|---|---|---|
| committer | David Tsai <dbtsai@dbtsai.com> | 2012-08-22 14:39:17 -0700 |
| commit | 7d9fecd71d687ee61bbc055d5b5026a2d36d02d5 (patch) | |
| tree | b63e06f8451810fbf68b1d84ae6853a25f83327a | |
| parent | bb1cbb2aa586d3ac74a21148a03c207d18a64262 (diff) | |
| download | python-mimeparse-7d9fecd71d687ee61bbc055d5b5026a2d36d02d5.tar.gz | |
Added tests for parse_mime_type. One came from the docstring for the Python
function. The other came from the test for the Go function. Updated the README
file to describe the structure of the test data.
| -rw-r--r-- | README | 6 | ||||
| -rw-r--r-- | mimeparse_test.py | 7 | ||||
| -rw-r--r-- | testdata.json | 5 |
3 files changed, 18 insertions, 0 deletions
@@ -4,6 +4,12 @@ See section 14.1 of RFC 2616 (the HTTP specification) for a complete explanation Testing ======= +The format of the JSON test data file is as follows: +A top-level JSON object which has a key for each of the functions to be tested. The value corresponding to that key is a list of tests. Each test contains: the argument or arguments to the function being tested, the expected results and an optional description. + + +Python +====== The Python tests require either Python 2.6 or the installation of the SimpleJSON library. Installing SimpleJson can be done by: diff --git a/mimeparse_test.py b/mimeparse_test.py index 8de2d8c..ee193c3 100644 --- a/mimeparse_test.py +++ b/mimeparse_test.py @@ -34,6 +34,12 @@ def test_best_match(args, expected): message = "Expected: '%s' but got %s" % (expected, result) assert expected == result, message +def test_parse_mime_type(args, expected): + expected = tuple(expected) + result = mimeparse.parse_mime_type(args) + message = "Expected: '%s' but got %s" % (expected, result) + assert expected == result, message + def add_tests(suite, json_object, func_name, test_func): test_data = json_object[func_name] for test_datum in test_data: @@ -52,6 +58,7 @@ def run_tests(): add_tests(suite, json_object, "parse_media_range", test_parse_media_range) add_tests(suite, json_object, "quality", test_quality) add_tests(suite, json_object, "best_match", test_best_match) + add_tests(suite, json_object, "parse_mime_type", test_parse_mime_type) test_runner = unittest.TextTestRunner(verbosity=1) test_runner.run(suite) diff --git a/testdata.json b/testdata.json index aea0c55..af08397 100644 --- a/testdata.json +++ b/testdata.json @@ -30,5 +30,10 @@ [[["application/json", "text/html"], "application/json, text/html;q=0.9"], "application/json", "verify fitness ordering"], [[["image/*", "application/xml"], "image/png"], "image/*", "match using a type wildcard"], [[["image/*", "application/xml"], "image/*"], "image/*", "match using a wildcard for both requested and supported"] +], + +"parse_mime_type": [ + ["application/xhtml;q=0.5", ["application", "xhtml", {"q": "0.5"}]], + ["application/xhtml;q=0.5;ver=1.2", ["application", "xhtml", {"q": "0.5", "ver": "1.2"}]] ] }
\ No newline at end of file |
