[Python-checkins] python/dist/src/Lib/test test_urllib.py,1.11,1.12

bcannon@users.sourceforge.net bcannon@users.sourceforge.net
Mon, 28 Apr 2003 22:08:08 -0700


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

Modified Files:
	test_urllib.py 
Log Message:
Added tests for urlretrieve.  Also made sure urlopen tests cleaned up properly after themselves.

Index: test_urllib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_urllib.py,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** test_urllib.py	25 Apr 2003 15:01:05 -0000	1.11
--- test_urllib.py	29 Apr 2003 05:08:06 -0000	1.12
***************
*** 36,39 ****
--- 36,40 ----
          """Shut down the open object"""
          self.returned_obj.close()
+         os.remove(test_support.TESTFN)
  
      def test_interface(self):
***************
*** 88,101 ****
              self.assertEqual(line, self.text)
  
! class urlretrieve_Tests(unittest.TestCase):
      """Test urllib.urlretrieve() on local files"""
-     pass
  
! class _urlopener_Tests(unittest.TestCase):
!     """Make sure urlopen() and urlretrieve() use the class assigned to
!     _urlopener"""
!     #XXX: Maybe create a custom class here that takes in a list and modifies
!     #   it to signal that it was called?
!     pass
  
  class QuotingTests(unittest.TestCase):
--- 89,140 ----
              self.assertEqual(line, self.text)
  
! class urlretrieve_FileTests(unittest.TestCase):
      """Test urllib.urlretrieve() on local files"""
  
!     def setUp(self):
!         # Create a temporary file.
!         self.text = 'testing urllib.urlretrieve'
!         FILE = file(test_support.TESTFN, 'wb')
!         FILE.write(self.text)
!         FILE.close()
! 
!     def tearDown(self):
!         # Delete the temporary file.
!         os.remove(test_support.TESTFN)
! 
!     def test_basic(self):
!         # Make sure that a local file just gets its own location returned and
!         # a headers value is returned.
!         result = urllib.urlretrieve("file:%s" % test_support.TESTFN)
!         self.assertEqual(result[0], test_support.TESTFN)
!         self.assert_(isinstance(result[1], mimetools.Message),
!                      "did not get a mimetools.Message instance as second "
!                      "returned value")
! 
!     def test_copy(self):
!         # Test that setting the filename argument works.
!         second_temp = "%s.2" % test_support.TESTFN
!         result = urllib.urlretrieve("file:%s" % test_support.TESTFN, second_temp)
!         self.assertEqual(second_temp, result[0])
!         self.assert_(os.path.exists(second_temp), "copy of the file was not "
!                                                   "made")
!         FILE = file(second_temp, 'rb')
!         try:
!             text = FILE.read()
!         finally:
!             FILE.close()
!         self.assertEqual(self.text, text)
! 
!     def test_reporthook(self):
!         # Make sure that the reporthook works.
!         def hooktester(count, block_size, total_size, count_holder=[0]):
!             self.assert_(isinstance(count, int))
!             self.assert_(isinstance(block_size, int))
!             self.assert_(isinstance(total_size, int))
!             self.assertEqual(count, count_holder[0])
!             count_holder[0] = count_holder[0] + 1
!         second_temp = "%s.2" % test_support.TESTFN
!         urllib.urlretrieve(test_support.TESTFN, second_temp, hooktester)
!         os.remove(second_temp)
  
  class QuotingTests(unittest.TestCase):
***************
*** 372,375 ****
--- 411,415 ----
      test_suite = unittest.TestSuite()
      test_suite.addTest(unittest.makeSuite(urlopen_FileTests))
+     test_suite.addTest(unittest.makeSuite(urlretrieve_FileTests))
      test_suite.addTest(unittest.makeSuite(QuotingTests))
      test_suite.addTest(unittest.makeSuite(UnquotingTests))