python-2.5.2/win32/Lib/test/test_macfs.py
changeset 0 ae805ac0140d
equal deleted inserted replaced
-1:000000000000 0:ae805ac0140d
       
     1 # Copyright (C) 2003 Python Software Foundation
       
     2 
       
     3 import unittest
       
     4 import warnings
       
     5 warnings.filterwarnings("ignore", "macfs.*", DeprecationWarning, __name__)
       
     6 import macfs
       
     7 import os
       
     8 import sys
       
     9 import tempfile
       
    10 from test import test_support
       
    11 
       
    12 class TestMacfs(unittest.TestCase):
       
    13 
       
    14     def setUp(self):
       
    15         fp = open(test_support.TESTFN, 'w')
       
    16         fp.write('hello world\n')
       
    17         fp.close()
       
    18 
       
    19     def tearDown(self):
       
    20         try:
       
    21             os.unlink(test_support.TESTFN)
       
    22         except:
       
    23             pass
       
    24 
       
    25     def test_fsspec(self):
       
    26         fss = macfs.FSSpec(test_support.TESTFN)
       
    27         self.assertEqual(os.path.realpath(test_support.TESTFN), fss.as_pathname())
       
    28 
       
    29     def test_fsref(self):
       
    30         fsr = macfs.FSRef(test_support.TESTFN)
       
    31         self.assertEqual(os.path.realpath(test_support.TESTFN), fsr.as_pathname())
       
    32 
       
    33     def test_fsref_unicode(self):
       
    34         if sys.getfilesystemencoding():
       
    35             testfn_unicode = unicode(test_support.TESTFN)
       
    36             fsr = macfs.FSRef(testfn_unicode)
       
    37             self.assertEqual(os.path.realpath(test_support.TESTFN), fsr.as_pathname())
       
    38 
       
    39     def test_coercion(self):
       
    40         fss = macfs.FSSpec(test_support.TESTFN)
       
    41         fsr = macfs.FSRef(test_support.TESTFN)
       
    42         fss2 = fsr.as_fsspec()
       
    43         fsr2 = fss.as_fsref()
       
    44         self.assertEqual(fss.as_pathname(), fss2.as_pathname())
       
    45         self.assertEqual(fsr.as_pathname(), fsr2.as_pathname())
       
    46 
       
    47     def test_dates(self):
       
    48         import time
       
    49         fss = macfs.FSSpec(test_support.TESTFN)
       
    50         now = int(time.time())
       
    51         fss.SetDates(now, now+1, now+2)
       
    52         dates = fss.GetDates()
       
    53         self.assertEqual(dates, (now, now+1, now+2))
       
    54 
       
    55     def test_ctor_type(self):
       
    56         fss = macfs.FSSpec(test_support.TESTFN)
       
    57         fss.SetCreatorType('Pyth', 'TEXT')
       
    58         filecr, filetp = fss.GetCreatorType()
       
    59         self.assertEqual((filecr, filetp), ('Pyth', 'TEXT'))
       
    60 
       
    61     def test_alias(self):
       
    62         fss = macfs.FSSpec(test_support.TESTFN)
       
    63         alias = fss.NewAlias()
       
    64         fss2, changed = alias.Resolve()
       
    65         self.assertEqual(changed, 0)
       
    66         self.assertEqual(fss.as_pathname(), fss2.as_pathname())
       
    67 
       
    68 
       
    69     def test_fss_alias(self):
       
    70         fss = macfs.FSSpec(test_support.TESTFN)
       
    71 
       
    72 
       
    73 def test_main():
       
    74     test_support.run_unittest(TestMacfs)
       
    75 
       
    76 
       
    77 if __name__ == '__main__':
       
    78     test_main()