Back to index

python3.2  3.2.2
Public Member Functions
test.test_largefile.LargeFileTest Class Reference

List of all members.

Public Member Functions

def test_seek
def test_osstat
def test_seek_read
def test_lseek
def test_truncate
def test_seekable

Detailed Description

Test that each file function works as expected for a large
(i.e. > 2GB, do  we have to check > 4GB) files.

NOTE: the order of execution of the test methods is important! test_seek
must run first to create the test file. File cleanup must also be handled
outside the test instances because of this.

Definition at line 26 of file test_largefile.py.


Member Function Documentation

Definition at line 87 of file test_largefile.py.

00087 
00088     def test_lseek(self):
00089         if verbose:
00090             print('play around with os.lseek() with the built largefile')
00091         with self.open(TESTFN, 'rb') as f:
00092             self.assertEqual(os.lseek(f.fileno(), 0, 0), 0)
00093             self.assertEqual(os.lseek(f.fileno(), 42, 0), 42)
00094             self.assertEqual(os.lseek(f.fileno(), 42, 1), 84)
00095             self.assertEqual(os.lseek(f.fileno(), 0, 1), 84)
00096             self.assertEqual(os.lseek(f.fileno(), 0, 2), size+1+0)
00097             self.assertEqual(os.lseek(f.fileno(), -10, 2), size+1-10)
00098             self.assertEqual(os.lseek(f.fileno(), -size-1, 2), 0)
00099             self.assertEqual(os.lseek(f.fileno(), size, 0), size)
00100             # the 'a' that was written at the end of file above
00101             self.assertEqual(f.read(1), b'a')

Here is the call graph for this function:

Definition at line 49 of file test_largefile.py.

00049 
00050     def test_osstat(self):
00051         if verbose:
00052             print('check file size with os.stat')
00053         self.assertEqual(os.stat(TESTFN)[stat.ST_SIZE], size+1)

Here is the call graph for this function:

Definition at line 36 of file test_largefile.py.

00036 
00037     def test_seek(self):
00038         if verbose:
00039             print('create large file via seek (may be sparse file) ...')
00040         with self.open(TESTFN, 'wb') as f:
00041             f.write(b'z')
00042             f.seek(0)
00043             f.seek(size)
00044             f.write(b'a')
00045             f.flush()
00046             if verbose:
00047                 print('check file size with os.fstat')
00048             self.assertEqual(os.fstat(f.fileno())[stat.ST_SIZE], size+1)

Here is the call graph for this function:

Definition at line 54 of file test_largefile.py.

00054 
00055     def test_seek_read(self):
00056         if verbose:
00057             print('play around with seek() and read() with the built largefile')
00058         with self.open(TESTFN, 'rb') as f:
00059             self.assertEqual(f.tell(), 0)
00060             self.assertEqual(f.read(1), b'z')
00061             self.assertEqual(f.tell(), 1)
00062             f.seek(0)
00063             self.assertEqual(f.tell(), 0)
00064             f.seek(0, 0)
00065             self.assertEqual(f.tell(), 0)
00066             f.seek(42)
00067             self.assertEqual(f.tell(), 42)
00068             f.seek(42, 0)
00069             self.assertEqual(f.tell(), 42)
00070             f.seek(42, 1)
00071             self.assertEqual(f.tell(), 84)
00072             f.seek(0, 1)
00073             self.assertEqual(f.tell(), 84)
00074             f.seek(0, 2)  # seek from the end
00075             self.assertEqual(f.tell(), size + 1 + 0)
00076             f.seek(-10, 2)
00077             self.assertEqual(f.tell(), size + 1 - 10)
00078             f.seek(-size-1, 2)
00079             self.assertEqual(f.tell(), 0)
00080             f.seek(size)
00081             self.assertEqual(f.tell(), size)
00082             # the 'a' that was written at the end of file above
00083             self.assertEqual(f.read(1), b'a')
00084             f.seek(-size-1, 1)
00085             self.assertEqual(f.read(1), b'z')
00086             self.assertEqual(f.tell(), 1)

Here is the call graph for this function:

Definition at line 136 of file test_largefile.py.

00136 
00137     def test_seekable(self):
00138         # Issue #5016; seekable() can return False when the current position
00139         # is negative when truncated to an int.
00140         for pos in (2**31-1, 2**31, 2**31+1):
00141             with self.open(TESTFN, 'rb') as f:
00142                 f.seek(pos)
00143                 self.assertTrue(f.seekable())
00144 

Here is the call graph for this function:

Definition at line 102 of file test_largefile.py.

00102 
00103     def test_truncate(self):
00104         if verbose:
00105             print('try truncate')
00106         with self.open(TESTFN, 'r+b') as f:
00107             # this is already decided before start running the test suite
00108             # but we do it anyway for extra protection
00109             if not hasattr(f, 'truncate'):
00110                 raise unittest.SkipTest("open().truncate() not available on this system")
00111             f.seek(0, 2)
00112             # else we've lost track of the true size
00113             self.assertEqual(f.tell(), size+1)
00114             # Cut it back via seek + truncate with no argument.
00115             newsize = size - 10
00116             f.seek(newsize)
00117             f.truncate()
00118             self.assertEqual(f.tell(), newsize)  # else pointer moved
00119             f.seek(0, 2)
00120             self.assertEqual(f.tell(), newsize)  # else wasn't truncated
00121             # Ensure that truncate(smaller than true size) shrinks
00122             # the file.
00123             newsize -= 1
00124             f.seek(42)
00125             f.truncate(newsize)
00126             self.assertEqual(f.tell(), 42)
00127             f.seek(0, 2)
00128             self.assertEqual(f.tell(), newsize)
00129             # XXX truncate(larger than true size) is ill-defined
00130             # across platform; cut it waaaaay back
00131             f.seek(0)
00132             f.truncate(1)
00133             self.assertEqual(f.tell(), 0)       # else pointer moved
00134             f.seek(0)
00135             self.assertEqual(len(f.read()), 1)  # else wasn't truncated

Here is the call graph for this function:


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