Silence a py3k warning claiming to affect Lib/calendar.py
[python.git] / Lib / test / test_macos.py
blobce5f858dde9fbb573891062fc40bc3a148559d33
1 import unittest
2 from test import test_support
3 import os
4 import subprocess
6 MacOS = test_support.import_module('MacOS')
7 #The following should exist if MacOS exists.
8 import Carbon.File
10 TESTFN2 = test_support.TESTFN + '2'
12 class TestMacOS(unittest.TestCase):
14 def testGetCreatorAndType(self):
15 if not os.path.exists('/Developer/Tools/SetFile'):
16 return
18 try:
19 fp = open(test_support.TESTFN, 'w')
20 fp.write('\n')
21 fp.close()
23 subprocess.call(
24 ['/Developer/Tools/SetFile', '-t', 'ABCD', '-c', 'EFGH',
25 test_support.TESTFN])
27 cr, tp = MacOS.GetCreatorAndType(test_support.TESTFN)
28 self.assertEquals(tp, 'ABCD')
29 self.assertEquals(cr, 'EFGH')
31 finally:
32 os.unlink(test_support.TESTFN)
34 def testSetCreatorAndType(self):
35 if not os.path.exists('/Developer/Tools/GetFileInfo'):
36 return
38 try:
39 fp = open(test_support.TESTFN, 'w')
40 fp.write('\n')
41 fp.close()
43 MacOS.SetCreatorAndType(test_support.TESTFN,
44 'ABCD', 'EFGH')
46 cr, tp = MacOS.GetCreatorAndType(test_support.TESTFN)
47 self.assertEquals(cr, 'ABCD')
48 self.assertEquals(tp, 'EFGH')
50 data = subprocess.Popen(["/Developer/Tools/GetFileInfo", test_support.TESTFN],
51 stdout=subprocess.PIPE).communicate()[0]
53 tp = None
54 cr = None
55 for ln in data.splitlines():
56 if ln.startswith('type:'):
57 tp = ln.split()[-1][1:-1]
58 if ln.startswith('creator:'):
59 cr = ln.split()[-1][1:-1]
61 self.assertEquals(cr, 'ABCD')
62 self.assertEquals(tp, 'EFGH')
64 finally:
65 os.unlink(test_support.TESTFN)
68 def testOpenRF(self):
69 try:
70 fp = open(test_support.TESTFN, 'w')
71 fp.write('hello world\n')
72 fp.close()
74 rfp = MacOS.openrf(test_support.TESTFN, '*wb')
75 rfp.write('goodbye world\n')
76 rfp.close()
79 fp = open(test_support.TESTFN, 'r')
80 data = fp.read()
81 fp.close()
82 self.assertEquals(data, 'hello world\n')
84 rfp = MacOS.openrf(test_support.TESTFN, '*rb')
85 data = rfp.read(100)
86 data2 = rfp.read(100)
87 rfp.close()
88 self.assertEquals(data, 'goodbye world\n')
89 self.assertEquals(data2, '')
92 finally:
93 os.unlink(test_support.TESTFN)
95 def test_main():
96 test_support.run_unittest(TestMacOS)
99 if __name__ == '__main__':
100 test_main()