Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
test.test_urllib.urlopen_FileTests Class Reference

List of all members.

Public Member Functions

def setUp
def tearDown
def test_interface
def test_read
def test_readline
def test_readlines
def test_fileno
def test_close
def test_info
def test_geturl
def test_getcode
def test_iter

Public Attributes

 text
 pathname
 returned_obj

Detailed Description

Test urlopen() opening a temporary file.

Try to test as much functionality as possible so as to cut down on reliance
on connecting to the Net for testing.

Definition at line 39 of file test_urllib.py.


Member Function Documentation

Definition at line 47 of file test_urllib.py.

00047 
00048     def setUp(self):
00049         # Create a temp file to use for testing
00050         self.text = bytes("test_urllib: %s\n" % self.__class__.__name__,
00051                           "ascii")
00052         f = open(support.TESTFN, 'wb')
00053         try:
00054             f.write(self.text)
00055         finally:
00056             f.close()
00057         self.pathname = support.TESTFN
00058         self.returned_obj = urlopen("file:%s" % self.pathname)

Here is the caller graph for this function:

Shut down the open object

Definition at line 59 of file test_urllib.py.

00059 
00060     def tearDown(self):
00061         """Shut down the open object"""
00062         self.returned_obj.close()
00063         os.remove(support.TESTFN)

Here is the caller graph for this function:

Definition at line 95 of file test_urllib.py.

00095 
00096     def test_close(self):
00097         # Test close() by calling it here and then having it be called again
00098         # by the tearDown() method for the test
00099         self.returned_obj.close()

Definition at line 88 of file test_urllib.py.

00088 
00089     def test_fileno(self):
00090         file_num = self.returned_obj.fileno()
00091         self.assertIsInstance(file_num, int, "fileno() did not return an int")
00092         self.assertEqual(os.read(file_num, len(self.text)), self.text,
00093                          "Reading on the file descriptor returned by fileno() "
00094                          "did not return the expected text")

Here is the call graph for this function:

Definition at line 106 of file test_urllib.py.

00106 
00107     def test_getcode(self):
00108         self.assertIsNone(self.returned_obj.getcode())

Here is the call graph for this function:

Definition at line 103 of file test_urllib.py.

00103 
00104     def test_geturl(self):
00105         self.assertEqual(self.returned_obj.geturl(), self.pathname)

Here is the call graph for this function:

Definition at line 100 of file test_urllib.py.

00100 
00101     def test_info(self):
00102         self.assertIsInstance(self.returned_obj.info(), email.message.Message)

Here is the call graph for this function:

Definition at line 64 of file test_urllib.py.

00064 
00065     def test_interface(self):
00066         # Make sure object returned by urlopen() has the specified methods
00067         for attr in ("read", "readline", "readlines", "fileno",
00068                      "close", "info", "geturl", "getcode", "__iter__"):
00069             self.assertTrue(hasattr(self.returned_obj, attr),
00070                          "object returned by urlopen() lacks %s attribute" %
00071                          attr)

Here is the call graph for this function:

Definition at line 109 of file test_urllib.py.

00109 
00110     def test_iter(self):
00111         # Test iterator
00112         # Don't need to count number of iterations since test would fail the
00113         # instant it returned anything beyond the first line from the
00114         # comparison.
00115         # Use the iterator in the usual implicit way to test for ticket #4608.
00116         for line in self.returned_obj:
00117             self.assertEqual(line, self.text)

Here is the call graph for this function:

Definition at line 72 of file test_urllib.py.

00072 
00073     def test_read(self):
00074         self.assertEqual(self.text, self.returned_obj.read())

Here is the call graph for this function:

Definition at line 75 of file test_urllib.py.

00075 
00076     def test_readline(self):
00077         self.assertEqual(self.text, self.returned_obj.readline())
00078         self.assertEqual(b'', self.returned_obj.readline(),
00079                          "calling readline() after exhausting the file did not"
00080                          " return an empty string")

Here is the call graph for this function:

Definition at line 81 of file test_urllib.py.

00081 
00082     def test_readlines(self):
00083         lines_list = self.returned_obj.readlines()
00084         self.assertEqual(len(lines_list), 1,
00085                          "readlines() returned the wrong number of lines")
00086         self.assertEqual(lines_list[0], self.text,
00087                          "readlines() returned improper text")

Here is the call graph for this function:


Member Data Documentation

Definition at line 56 of file test_urllib.py.

Definition at line 57 of file test_urllib.py.

Definition at line 49 of file test_urllib.py.


The documentation for this class was generated from the following file: