0001 # Copyright (C) 2003 Python Software Foundation 0002 0003 import unittest 0004 import warnings 0005 warnings.filterwarnings("ignore", "macfs.*", DeprecationWarning, __name__) 0006 import macfs 0007 import os 0008 import sys 0009 import tempfile 0010 from test import test_support 0011 0012 class TestMacfs(unittest.TestCase): 0013 0014 def setUp(self): 0015 fp = open(test_support.TESTFN, 'w') 0016 fp.write('hello world\n') 0017 fp.close() 0018 0019 def tearDown(self): 0020 try: 0021 os.unlink(test_support.TESTFN) 0022 except: 0023 pass 0024 0025 def test_fsspec(self): 0026 fss = macfs.FSSpec(test_support.TESTFN) 0027 self.assertEqual(os.path.realpath(test_support.TESTFN), fss.as_pathname()) 0028 0029 def test_fsref(self): 0030 fsr = macfs.FSRef(test_support.TESTFN) 0031 self.assertEqual(os.path.realpath(test_support.TESTFN), fsr.as_pathname()) 0032 0033 def test_fsref_unicode(self): 0034 if sys.getfilesystemencoding(): 0035 testfn_unicode = unicode(test_support.TESTFN) 0036 fsr = macfs.FSRef(testfn_unicode) 0037 self.assertEqual(os.path.realpath(test_support.TESTFN), fsr.as_pathname()) 0038 0039 def test_coercion(self): 0040 fss = macfs.FSSpec(test_support.TESTFN) 0041 fsr = macfs.FSRef(test_support.TESTFN) 0042 fss2 = fsr.as_fsspec() 0043 fsr2 = fss.as_fsref() 0044 self.assertEqual(fss.as_pathname(), fss2.as_pathname()) 0045 self.assertEqual(fsr.as_pathname(), fsr2.as_pathname()) 0046 0047 def test_dates(self): 0048 import time 0049 fss = macfs.FSSpec(test_support.TESTFN) 0050 now = int(time.time()) 0051 fss.SetDates(now, now-1, now-2) 0052 dates = fss.GetDates() 0053 self.assertEqual(dates, (now, now-1, now-2)) 0054 0055 def test_ctor_type(self): 0056 fss = macfs.FSSpec(test_support.TESTFN) 0057 fss.SetCreatorType('Pyth', 'TEXT') 0058 filecr, filetp = fss.GetCreatorType() 0059 self.assertEqual((filecr, filetp), ('Pyth', 'TEXT')) 0060 0061 def test_alias(self): 0062 fss = macfs.FSSpec(test_support.TESTFN) 0063 alias = fss.NewAlias() 0064 fss2, changed = alias.Resolve() 0065 self.assertEqual(changed, 0) 0066 self.assertEqual(fss.as_pathname(), fss2.as_pathname()) 0067 0068 0069 def test_fss_alias(self): 0070 fss = macfs.FSSpec(test_support.TESTFN) 0071 0072 0073 def test_main(): 0074 test_support.run_unittest(TestMacfs) 0075 0076 0077 if __name__ == '__main__': 0078 test_main() 0079
Generated by PyXR 0.9.4