Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
test.test_os.StatAttributeTests Class Reference

List of all members.

Public Member Functions

def setUp
def tearDown
def check_stat_attributes
def test_stat_attributes
def test_stat_attributes_bytes
def test_statvfs_attributes
def test_utime_dir
def get_file_system
def test_1565150
def test_large_time
def test_1686475

Public Attributes

 fname

Detailed Description

Definition at line 127 of file test_os.py.


Member Function Documentation

Definition at line 139 of file test_os.py.

00139 
00140     def check_stat_attributes(self, fname):
00141         if not hasattr(os, "stat"):
00142             return
00143 
00144         import stat
00145         result = os.stat(fname)
00146 
00147         # Make sure direct access works
00148         self.assertEqual(result[stat.ST_SIZE], 3)
00149         self.assertEqual(result.st_size, 3)
00150 
00151         # Make sure all the attributes are there
00152         members = dir(result)
00153         for name in dir(stat):
00154             if name[:3] == 'ST_':
00155                 attr = name.lower()
00156                 if name.endswith("TIME"):
00157                     def trunc(x): return int(x)
00158                 else:
00159                     def trunc(x): return x
00160                 self.assertEqual(trunc(getattr(result, attr)),
00161                                   result[getattr(stat, name)])
00162                 self.assertIn(attr, members)
00163 
00164         try:
00165             result[200]
00166             self.fail("No exception thrown")
00167         except IndexError:
00168             pass
00169 
00170         # Make sure that assignment fails
00171         try:
00172             result.st_mode = 1
00173             self.fail("No exception thrown")
00174         except AttributeError:
00175             pass
00176 
00177         try:
00178             result.st_rdev = 1
00179             self.fail("No exception thrown")
00180         except (AttributeError, TypeError):
00181             pass
00182 
00183         try:
00184             result.parrot = 1
00185             self.fail("No exception thrown")
00186         except AttributeError:
00187             pass
00188 
00189         # Use the stat_result constructor with a too-short tuple.
00190         try:
00191             result2 = os.stat_result((10,))
00192             self.fail("No exception thrown")
00193         except TypeError:
00194             pass
00195 
00196         # Use the constructor with a too-long tuple.
00197         try:
00198             result2 = os.stat_result((0,1,2,3,4,5,6,7,8,9,10,11,12,13,14))
00199         except TypeError:
00200             pass

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 269 of file test_os.py.

00269 
00270         def get_file_system(path):
00271             root = os.path.splitdrive(os.path.abspath(path))[0] + '\\'
00272             import ctypes
00273             kernel32 = ctypes.windll.kernel32
00274             buf = ctypes.create_unicode_buffer("", 100)
00275             if kernel32.GetVolumeInformationW(root, None, 0, None, None, None, buf, len(buf)):
00276                 return buf.value

Here is the call graph for this function:

Definition at line 128 of file test_os.py.

00128 
00129     def setUp(self):
00130         os.mkdir(support.TESTFN)
00131         self.fname = os.path.join(support.TESTFN, "f1")
00132         f = open(self.fname, 'wb')
00133         f.write(b"ABC")
00134         f.close()

Here is the caller graph for this function:

Definition at line 135 of file test_os.py.

00135 
00136     def tearDown(self):
00137         os.unlink(self.fname)
00138         os.rmdir(support.TESTFN)

Here is the caller graph for this function:

Definition at line 278 of file test_os.py.

00278 
00279             def test_1565150(self):
00280                 t1 = 1159195039.25
00281                 os.utime(self.fname, (t1, t1))
00282                 self.assertEqual(os.stat(self.fname).st_mtime, t1)

Here is the call graph for this function:

Definition at line 288 of file test_os.py.

00288 
00289         def test_1686475(self):
00290             # Verify that an open file can be stat'ed
00291             try:
00292                 os.stat(r"c:\pagefile.sys")
00293             except WindowsError as e:
00294                 if e.errno == 2: # file does not exist; cannot run test
00295                     return
00296                 self.fail("Could not stat pagefile.sys")

Here is the call graph for this function:

Definition at line 283 of file test_os.py.

00283 
00284             def test_large_time(self):
00285                 t1 = 5000000000 # some day in 2128
00286                 os.utime(self.fname, (t1, t1))
00287                 self.assertEqual(os.stat(self.fname).st_mtime, t1)

Here is the call graph for this function:

Definition at line 201 of file test_os.py.

00201 
00202     def test_stat_attributes(self):
00203         self.check_stat_attributes(self.fname)

Here is the call graph for this function:

Definition at line 204 of file test_os.py.

00204 
00205     def test_stat_attributes_bytes(self):
00206         try:
00207             fname = self.fname.encode(sys.getfilesystemencoding())
00208         except UnicodeEncodeError:
00209             self.skipTest("cannot encode %a for the filesystem" % self.fname)
00210         self.check_stat_attributes(fname)

Here is the call graph for this function:

Definition at line 211 of file test_os.py.

00211 
00212     def test_statvfs_attributes(self):
00213         if not hasattr(os, "statvfs"):
00214             return
00215 
00216         try:
00217             result = os.statvfs(self.fname)
00218         except OSError as e:
00219             # On AtheOS, glibc always returns ENOSYS
00220             if e.errno == errno.ENOSYS:
00221                 return
00222 
00223         # Make sure direct access works
00224         self.assertEqual(result.f_bfree, result[3])
00225 
00226         # Make sure all the attributes are there.
00227         members = ('bsize', 'frsize', 'blocks', 'bfree', 'bavail', 'files',
00228                     'ffree', 'favail', 'flag', 'namemax')
00229         for value, member in enumerate(members):
00230             self.assertEqual(getattr(result, 'f_' + member), result[value])
00231 
00232         # Make sure that assignment really fails
00233         try:
00234             result.f_bfree = 1
00235             self.fail("No exception thrown")
00236         except AttributeError:
00237             pass
00238 
00239         try:
00240             result.parrot = 1
00241             self.fail("No exception thrown")
00242         except AttributeError:
00243             pass
00244 
00245         # Use the constructor with a too-short tuple.
00246         try:
00247             result2 = os.statvfs_result((10,))
00248             self.fail("No exception thrown")
00249         except TypeError:
00250             pass
00251 
00252         # Use the constructor with a too-long tuple.
00253         try:
00254             result2 = os.statvfs_result((0,1,2,3,4,5,6,7,8,9,10,11,12,13,14))
00255         except TypeError:
00256             pass

Here is the call graph for this function:

Definition at line 257 of file test_os.py.

00257 
00258     def test_utime_dir(self):
00259         delta = 1000000
00260         st = os.stat(support.TESTFN)
00261         # round to int, because some systems may support sub-second
00262         # time stamps in stat, but not in utime.
00263         os.utime(support.TESTFN, (st.st_atime, int(st.st_mtime-delta)))
00264         st2 = os.stat(support.TESTFN)
00265         self.assertEqual(st2.st_mtime, int(st.st_mtime-delta))

Here is the call graph for this function:


Member Data Documentation

Definition at line 130 of file test_os.py.


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