2 from test
import test_support
6 MacOS
= test_support
.import_module('MacOS')
7 #The following should exist if MacOS exists.
10 TESTFN2
= test_support
.TESTFN
+ '2'
12 class TestMacOS(unittest
.TestCase
):
14 def testGetCreatorAndType(self
):
15 if not os
.path
.exists('/Developer/Tools/SetFile'):
19 fp
= open(test_support
.TESTFN
, 'w')
24 ['/Developer/Tools/SetFile', '-t', 'ABCD', '-c', 'EFGH',
27 cr
, tp
= MacOS
.GetCreatorAndType(test_support
.TESTFN
)
28 self
.assertEquals(tp
, 'ABCD')
29 self
.assertEquals(cr
, 'EFGH')
32 os
.unlink(test_support
.TESTFN
)
34 def testSetCreatorAndType(self
):
35 if not os
.path
.exists('/Developer/Tools/GetFileInfo'):
39 fp
= open(test_support
.TESTFN
, 'w')
43 MacOS
.SetCreatorAndType(test_support
.TESTFN
,
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]
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')
65 os
.unlink(test_support
.TESTFN
)
70 fp
= open(test_support
.TESTFN
, 'w')
71 fp
.write('hello world\n')
74 rfp
= MacOS
.openrf(test_support
.TESTFN
, '*wb')
75 rfp
.write('goodbye world\n')
79 fp
= open(test_support
.TESTFN
, 'r')
82 self
.assertEquals(data
, 'hello world\n')
84 rfp
= MacOS
.openrf(test_support
.TESTFN
, '*rb')
88 self
.assertEquals(data
, 'goodbye world\n')
89 self
.assertEquals(data2
, '')
93 os
.unlink(test_support
.TESTFN
)
96 test_support
.run_unittest(TestMacOS
)
99 if __name__
== '__main__':