[Python-checkins] python/dist/src/Lib/test test_urlparse.py,1.8,1.9

fdrake@users.sourceforge.net fdrake@users.sourceforge.net
Wed, 16 Oct 2002 14:02:38 -0700


Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv4190

Modified Files:
	test_urlparse.py 
Log Message:
Make sure we test urlsplit() / urlunsplit() directly, rather than
guessing that urlparse() / urlunparse() use them.

Add tests of urldefrag().


Index: test_urlparse.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_urlparse.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** test_urlparse.py	14 Oct 2002 19:59:54 -0000	1.8
--- test_urlparse.py	16 Oct 2002 21:02:36 -0000	1.9
***************
*** 10,30 ****
  class UrlParseTestCase(unittest.TestCase):
      def test_frags(self):
!         for url, expected in [('http://www.python.org',
!                                ('http', 'www.python.org', '', '', '', '')),
!                               ('http://www.python.org#abc',
!                                ('http', 'www.python.org', '', '', '', 'abc')),
!                               ('http://www.python.org/#abc',
!                                ('http', 'www.python.org', '/', '', '', 'abc')),
!                               (RFC1808_BASE,
!                                ('http', 'a', '/b/c/d', 'p', 'q', 'f')),
!                               ('file:///tmp/junk.txt',
!                                ('file', '', '/tmp/junk.txt', '', '', '')),
!                               ]:
              result = urlparse.urlparse(url)
!             self.assertEqual(result, expected)
              # put it back together and it should be the same
              result2 = urlparse.urlunparse(result)
              self.assertEqual(result2, url)
  
      def checkJoin(self, base, relurl, expected):
          self.assertEqual(urlparse.urljoin(base, relurl), expected,
--- 10,42 ----
  class UrlParseTestCase(unittest.TestCase):
      def test_frags(self):
!         for url, parsed, split in [
!             ('http://www.python.org',
!              ('http', 'www.python.org', '', '', '', ''),
!              ('http', 'www.python.org', '', '', '')),
!             ('http://www.python.org#abc',
!              ('http', 'www.python.org', '', '', '', 'abc'),
!              ('http', 'www.python.org', '', '', 'abc')),
!             ('http://www.python.org/#abc',
!              ('http', 'www.python.org', '/', '', '', 'abc'),
!              ('http', 'www.python.org', '/', '', 'abc')),
!             (RFC1808_BASE,
!              ('http', 'a', '/b/c/d', 'p', 'q', 'f'),
!              ('http', 'a', '/b/c/d;p', 'q', 'f')),
!             ('file:///tmp/junk.txt',
!              ('file', '', '/tmp/junk.txt', '', '', ''),
!              ('file', '', '/tmp/junk.txt', '', '')),
!             ]:
              result = urlparse.urlparse(url)
!             self.assertEqual(result, parsed)
              # put it back together and it should be the same
              result2 = urlparse.urlunparse(result)
              self.assertEqual(result2, url)
  
+             # check the roundtrip using urlsplit() as well
+             result = urlparse.urlsplit(url)
+             self.assertEqual(result, split)
+             result2 = urlparse.urlunsplit(result)
+             self.assertEqual(result2, url)
+ 
      def checkJoin(self, base, relurl, expected):
          self.assertEqual(urlparse.urljoin(base, relurl), expected,
***************
*** 33,36 ****
--- 45,49 ----
      def test_unparse_parse(self):
          for u in ['Python', './Python']:
+             self.assertEqual(urlparse.urlunsplit(urlparse.urlsplit(u)), u)
              self.assertEqual(urlparse.urlunparse(urlparse.urlparse(u)), u)
  
***************
*** 128,131 ****
--- 141,159 ----
          self.checkJoin(RFC2396_BASE, 'g#s/./x', 'http://a/b/c/g#s/./x')
          self.checkJoin(RFC2396_BASE, 'g#s/../x', 'http://a/b/c/g#s/../x')
+ 
+     def test_urldefrag(self):
+         for url, defrag, frag in [
+             ('http://python.org#frag', 'http://python.org', 'frag'),
+             ('http://python.org', 'http://python.org', ''),
+             ('http://python.org/#frag', 'http://python.org/', 'frag'),
+             ('http://python.org/', 'http://python.org/', ''),
+             ('http://python.org/?q#frag', 'http://python.org/?q', 'frag'),
+             ('http://python.org/?q', 'http://python.org/?q', ''),
+             ('http://python.org/p#frag', 'http://python.org/p', 'frag'),
+             ('http://python.org/p?q', 'http://python.org/p?q', ''),
+             (RFC1808_BASE, 'http://a/b/c/d;p?q', 'f'),
+             (RFC2396_BASE, 'http://a/b/c/d;p?q', ''),
+             ]:
+             self.assertEqual(urlparse.urldefrag(url), (defrag, frag))
  
  def test_main():