2008-06-05 09:58:24 -03:00
|
|
|
import unittest
|
|
|
|
from test import test_support
|
|
|
|
import os
|
2009-01-02 10:10:20 -04:00
|
|
|
import subprocess
|
2008-06-05 09:58:24 -03:00
|
|
|
|
2009-03-30 16:04:00 -03:00
|
|
|
MacOS = test_support.import_module('MacOS')
|
|
|
|
|
2008-06-05 09:58:24 -03:00
|
|
|
TESTFN2 = test_support.TESTFN + '2'
|
|
|
|
|
|
|
|
class TestMacOS(unittest.TestCase):
|
2013-12-10 16:09:20 -04:00
|
|
|
@unittest.skipUnless(os.path.exists('/Developer/Tools/SetFile'),
|
|
|
|
'/Developer/Tools/SetFile does not exist')
|
2009-01-02 10:10:20 -04:00
|
|
|
def testGetCreatorAndType(self):
|
|
|
|
try:
|
|
|
|
fp = open(test_support.TESTFN, 'w')
|
|
|
|
fp.write('\n')
|
|
|
|
fp.close()
|
|
|
|
|
|
|
|
subprocess.call(
|
|
|
|
['/Developer/Tools/SetFile', '-t', 'ABCD', '-c', 'EFGH',
|
|
|
|
test_support.TESTFN])
|
|
|
|
|
|
|
|
cr, tp = MacOS.GetCreatorAndType(test_support.TESTFN)
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(tp, 'ABCD')
|
|
|
|
self.assertEqual(cr, 'EFGH')
|
2009-01-02 10:10:20 -04:00
|
|
|
|
|
|
|
finally:
|
|
|
|
os.unlink(test_support.TESTFN)
|
|
|
|
|
2013-12-10 16:09:20 -04:00
|
|
|
@unittest.skipUnless(os.path.exists('/Developer/Tools/GetFileInfo'),
|
|
|
|
'/Developer/Tools/GetFileInfo does not exist')
|
2009-01-02 10:10:20 -04:00
|
|
|
def testSetCreatorAndType(self):
|
|
|
|
try:
|
|
|
|
fp = open(test_support.TESTFN, 'w')
|
|
|
|
fp.write('\n')
|
|
|
|
fp.close()
|
|
|
|
|
|
|
|
MacOS.SetCreatorAndType(test_support.TESTFN,
|
|
|
|
'ABCD', 'EFGH')
|
|
|
|
|
|
|
|
cr, tp = MacOS.GetCreatorAndType(test_support.TESTFN)
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(cr, 'ABCD')
|
|
|
|
self.assertEqual(tp, 'EFGH')
|
2009-01-02 10:10:20 -04:00
|
|
|
|
|
|
|
data = subprocess.Popen(["/Developer/Tools/GetFileInfo", test_support.TESTFN],
|
|
|
|
stdout=subprocess.PIPE).communicate()[0]
|
|
|
|
|
|
|
|
tp = None
|
|
|
|
cr = None
|
|
|
|
for ln in data.splitlines():
|
|
|
|
if ln.startswith('type:'):
|
|
|
|
tp = ln.split()[-1][1:-1]
|
|
|
|
if ln.startswith('creator:'):
|
|
|
|
cr = ln.split()[-1][1:-1]
|
|
|
|
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(cr, 'ABCD')
|
|
|
|
self.assertEqual(tp, 'EFGH')
|
2009-01-02 10:10:20 -04:00
|
|
|
|
|
|
|
finally:
|
|
|
|
os.unlink(test_support.TESTFN)
|
|
|
|
|
|
|
|
|
2008-06-05 09:58:24 -03:00
|
|
|
def testOpenRF(self):
|
|
|
|
try:
|
|
|
|
fp = open(test_support.TESTFN, 'w')
|
|
|
|
fp.write('hello world\n')
|
|
|
|
fp.close()
|
|
|
|
|
|
|
|
rfp = MacOS.openrf(test_support.TESTFN, '*wb')
|
|
|
|
rfp.write('goodbye world\n')
|
|
|
|
rfp.close()
|
|
|
|
|
|
|
|
|
|
|
|
fp = open(test_support.TESTFN, 'r')
|
|
|
|
data = fp.read()
|
|
|
|
fp.close()
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(data, 'hello world\n')
|
2008-06-05 09:58:24 -03:00
|
|
|
|
|
|
|
rfp = MacOS.openrf(test_support.TESTFN, '*rb')
|
|
|
|
data = rfp.read(100)
|
|
|
|
data2 = rfp.read(100)
|
|
|
|
rfp.close()
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(data, 'goodbye world\n')
|
|
|
|
self.assertEqual(data2, '')
|
2008-06-05 09:58:24 -03:00
|
|
|
|
|
|
|
|
|
|
|
finally:
|
|
|
|
os.unlink(test_support.TESTFN)
|
|
|
|
|
|
|
|
def test_main():
|
|
|
|
test_support.run_unittest(TestMacOS)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
test_main()
|