Jack Jansen | 10882f6 | 2003-01-28 21:39:28 +0000 | [diff] [blame] | 1 | # Copyright (C) 2003 Python Software Foundation |
| 2 | |
| 3 | import unittest |
| 4 | import macfs |
| 5 | import os |
| 6 | import tempfile |
| 7 | from test import test_support |
| 8 | |
| 9 | class TestMacfs(unittest.TestCase): |
| 10 | |
| 11 | def setUp(self): |
| 12 | fp = open(test_support.TESTFN, 'w') |
| 13 | fp.write('hello world\n') |
| 14 | fp.close() |
| 15 | |
| 16 | def tearDown(self): |
| 17 | try: |
| 18 | os.unlink(test_support.TESTFN) |
| 19 | except: |
| 20 | pass |
| 21 | |
| 22 | def test_fsspec(self): |
| 23 | fss = macfs.FSSpec(test_support.TESTFN) |
| 24 | self.assertEqual(os.path.abspath(test_support.TESTFN), fss.as_pathname()) |
| 25 | |
| 26 | def test_fsref(self): |
| 27 | fsr = macfs.FSRef(test_support.TESTFN) |
| 28 | self.assertEqual(os.path.abspath(test_support.TESTFN), fsr.as_pathname()) |
| 29 | |
| 30 | def test_coercion(self): |
| 31 | fss = macfs.FSSpec(test_support.TESTFN) |
| 32 | fsr = macfs.FSRef(test_support.TESTFN) |
| 33 | fss2 = fsr.as_fsspec() |
| 34 | fsr2 = fss.as_fsref() |
| 35 | self.assertEqual(fss.as_pathname(), fss2.as_pathname()) |
| 36 | self.assertEqual(fsr.as_pathname(), fsr2.as_pathname()) |
| 37 | |
| 38 | def test_dates(self): |
| 39 | import time |
| 40 | fss = macfs.FSSpec(test_support.TESTFN) |
| 41 | now = int(time.time()) |
| 42 | fss.SetDates(now, now-1, now-2) |
| 43 | dates = fss.GetDates() |
| 44 | self.assertEqual(dates, (now, now-1, now-2)) |
| 45 | |
| 46 | def test_ctor_type(self): |
| 47 | fss = macfs.FSSpec(test_support.TESTFN) |
| 48 | fss.SetCreatorType('Pyth', 'TEXT') |
| 49 | filecr, filetp = fss.GetCreatorType() |
| 50 | self.assertEqual((filecr, filetp), ('Pyth', 'TEXT')) |
| 51 | |
| 52 | def test_alias(self): |
| 53 | fss = macfs.FSSpec(test_support.TESTFN) |
| 54 | alias = fss.NewAlias() |
| 55 | fss2, changed = alias.Resolve() |
| 56 | self.assertEqual(changed, 0) |
| 57 | self.assertEqual(fss.as_pathname(), fss2.as_pathname()) |
| 58 | |
| 59 | |
| 60 | def test_fss_alias(self): |
| 61 | fss = macfs.FSSpec(test_support.TESTFN) |
| 62 | |
| 63 | |
| 64 | def test_main(): |
| 65 | test_support.run_unittest(TestMacfs) |
| 66 | |
| 67 | |
| 68 | if __name__ == '__main__': |
| 69 | test_main() |