Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Lib/test/test_macos.py

    r2 r391  
    11import unittest
    2 import MacOS
    3 import Carbon.File
    42from test import test_support
    53import os
     4import subprocess
     5
     6MacOS = test_support.import_module('MacOS')
    67
    78TESTFN2 = test_support.TESTFN + '2'
    89
    910class TestMacOS(unittest.TestCase):
     11
     12    def testGetCreatorAndType(self):
     13        if not os.path.exists('/Developer/Tools/SetFile'):
     14            return
     15
     16        try:
     17            fp = open(test_support.TESTFN, 'w')
     18            fp.write('\n')
     19            fp.close()
     20
     21            subprocess.call(
     22                    ['/Developer/Tools/SetFile', '-t', 'ABCD', '-c', 'EFGH',
     23                        test_support.TESTFN])
     24
     25            cr, tp = MacOS.GetCreatorAndType(test_support.TESTFN)
     26            self.assertEqual(tp, 'ABCD')
     27            self.assertEqual(cr, 'EFGH')
     28
     29        finally:
     30            os.unlink(test_support.TESTFN)
     31
     32    def testSetCreatorAndType(self):
     33        if not os.path.exists('/Developer/Tools/GetFileInfo'):
     34            return
     35
     36        try:
     37            fp = open(test_support.TESTFN, 'w')
     38            fp.write('\n')
     39            fp.close()
     40
     41            MacOS.SetCreatorAndType(test_support.TESTFN,
     42                    'ABCD', 'EFGH')
     43
     44            cr, tp = MacOS.GetCreatorAndType(test_support.TESTFN)
     45            self.assertEqual(cr, 'ABCD')
     46            self.assertEqual(tp, 'EFGH')
     47
     48            data = subprocess.Popen(["/Developer/Tools/GetFileInfo", test_support.TESTFN],
     49                    stdout=subprocess.PIPE).communicate()[0]
     50
     51            tp = None
     52            cr = None
     53            for  ln in data.splitlines():
     54                if ln.startswith('type:'):
     55                    tp = ln.split()[-1][1:-1]
     56                if ln.startswith('creator:'):
     57                    cr = ln.split()[-1][1:-1]
     58
     59            self.assertEqual(cr, 'ABCD')
     60            self.assertEqual(tp, 'EFGH')
     61
     62        finally:
     63            os.unlink(test_support.TESTFN)
     64
    1065
    1166    def testOpenRF(self):
     
    2378            data = fp.read()
    2479            fp.close()
    25             self.assertEquals(data, 'hello world\n')
     80            self.assertEqual(data, 'hello world\n')
    2681
    2782            rfp = MacOS.openrf(test_support.TESTFN, '*rb')
     
    2984            data2 = rfp.read(100)
    3085            rfp.close()
    31             self.assertEquals(data, 'goodbye world\n')
    32             self.assertEquals(data2, '')
     86            self.assertEqual(data, 'goodbye world\n')
     87            self.assertEqual(data2, '')
    3388
    3489
Note: See TracChangeset for help on using the changeset viewer.