|
9 | 9 | import unittest |
10 | 10 | import urlparse |
11 | 11 |
|
| 12 | +# Add ability to run sub-tests |
| 13 | +def sub_test(param_list): |
| 14 | + """Decorates a test case to run it as a set of subtests.""" |
| 15 | + |
| 16 | + def decorator(f): |
| 17 | + |
| 18 | + @functools.wraps(f) |
| 19 | + def wrapped(self): |
| 20 | + for param in param_list: |
| 21 | + with self.subTest(**param): |
| 22 | + f(self, **param) |
| 23 | + |
| 24 | + return wrapped |
| 25 | + |
| 26 | + return decorator |
| 27 | + |
| 28 | + |
12 | 29 | RFC1808_BASE = "http://a/b/c/d;p?q#f" |
13 | 30 | RFC2396_BASE = "http://a/b/c/d;p?q" |
14 | 31 | RFC3986_BASE = 'http://a/b/c/d;p?q' |
@@ -667,19 +684,18 @@ def test_attributes_bad_port(self): |
667 | 684 | for bytes in (False, True): |
668 | 685 | for parse in (urlparse.urlsplit, urlparse.urlparse): |
669 | 686 | for port in ("foo", "1.5", "-1", "0x10", "-0", "1_1", " 1", "1 ", "६"): |
670 | | - with self.subTest(bytes=bytes, parse=parse, port=port): |
671 | | - netloc = "www.example.net:" + port |
672 | | - url = "http://" + netloc + "/" |
673 | | - if bytes: |
674 | | - if netloc.isascii() and port.isascii(): |
675 | | - netloc = netloc.encode("ascii") |
676 | | - url = url.encode("ascii") |
677 | | - else: |
678 | | - continue |
679 | | - p = parse(url) |
680 | | - self.assertEqual(p.netloc, netloc) |
681 | | - with self.assertRaises(ValueError): |
682 | | - p.port |
| 687 | + netloc = "www.example.net:" + port |
| 688 | + url = "http://" + netloc + "/" |
| 689 | + if bytes: |
| 690 | + if netloc.isascii() and port.isascii(): |
| 691 | + netloc = netloc.encode("ascii") |
| 692 | + url = url.encode("ascii") |
| 693 | + else: |
| 694 | + continue |
| 695 | + p = parse(url) |
| 696 | + self.assertEqual(p.netloc, netloc) |
| 697 | + with self.assertRaises(ValueError): |
| 698 | + p.port |
683 | 699 |
|
684 | 700 | def test_attributes_without_netloc(self): |
685 | 701 | # This example is straight from RFC 3261. It looks like it |
|
0 commit comments