home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 June / maximum-cd-2011-06.iso / DiscContents / LibO_3.3.1_Win_x86_install_multi.exe / libreoffice1.cab / test_macostools.py < prev    next >
Encoding:
Python Source  |  2011-02-15  |  2.9 KB  |  102 lines

  1. # Copyright (C) 2003 Python Software Foundation
  2.  
  3. import unittest
  4. import macostools
  5. import Carbon.File
  6. import MacOS
  7. import os
  8. import sys
  9. from test import test_support
  10.  
  11. TESTFN2 = test_support.TESTFN + '2'
  12.  
  13. class TestMacostools(unittest.TestCase):
  14.  
  15.     def setUp(self):
  16.         fp = open(test_support.TESTFN, 'w')
  17.         fp.write('hello world\n')
  18.         fp.close()
  19.         rfp = MacOS.openrf(test_support.TESTFN, '*wb')
  20.         rfp.write('goodbye world\n')
  21.         rfp.close()
  22.  
  23.     def tearDown(self):
  24.         try:
  25.             os.unlink(test_support.TESTFN)
  26.         except:
  27.             pass
  28.         try:
  29.             os.unlink(TESTFN2)
  30.         except:
  31.             pass
  32.  
  33.     def compareData(self):
  34.         fp = open(test_support.TESTFN, 'r')
  35.         data1 = fp.read()
  36.         fp.close()
  37.         fp = open(TESTFN2, 'r')
  38.         data2 = fp.read()
  39.         fp.close()
  40.         if data1 != data2:
  41.             return 'Data forks differ'
  42.         rfp = MacOS.openrf(test_support.TESTFN, '*rb')
  43.         data1 = rfp.read(1000)
  44.         rfp.close()
  45.         rfp = MacOS.openrf(TESTFN2, '*rb')
  46.         data2 = rfp.read(1000)
  47.         rfp.close()
  48.         if data1 != data2:
  49.             return 'Resource forks differ'
  50.         return ''
  51.  
  52.     def test_touched(self):
  53.         # This really only tests that nothing unforeseen happens.
  54.         import warnings
  55.         with warnings.catch_warnings():
  56.             warnings.filterwarnings('ignore', 'macostools.touched*',
  57.                                     DeprecationWarning)
  58.             macostools.touched(test_support.TESTFN)
  59.  
  60.     def test_copy(self):
  61.         try:
  62.             os.unlink(TESTFN2)
  63.         except:
  64.             pass
  65.         macostools.copy(test_support.TESTFN, TESTFN2)
  66.         self.assertEqual(self.compareData(), '')
  67.  
  68.     def test_mkalias(self):
  69.         try:
  70.             os.unlink(TESTFN2)
  71.         except:
  72.             pass
  73.         macostools.mkalias(test_support.TESTFN, TESTFN2)
  74.         fss, _, _ = Carbon.File.ResolveAliasFile(TESTFN2, 0)
  75.         self.assertEqual(fss.as_pathname(), os.path.realpath(test_support.TESTFN))
  76.  
  77.     def test_mkalias_relative(self):
  78.         try:
  79.             os.unlink(TESTFN2)
  80.         except:
  81.             pass
  82.         # If the directory doesn't exist, then chances are this is a new
  83.         # install of Python so don't create it since the user might end up
  84.         # running ``sudo make install`` and creating the directory here won't
  85.         # leave it with the proper permissions.
  86.         if not os.path.exists(sys.prefix):
  87.             return
  88.         macostools.mkalias(test_support.TESTFN, TESTFN2, sys.prefix)
  89.         fss, _, _ = Carbon.File.ResolveAliasFile(TESTFN2, 0)
  90.         self.assertEqual(fss.as_pathname(), os.path.realpath(test_support.TESTFN))
  91.  
  92.  
  93. def test_main():
  94.     # Skip on wide unicode
  95.     if len(u'\0'.encode('unicode-internal')) == 4:
  96.         raise test_support.TestSkipped("test_macostools is broken in USC4")
  97.     test_support.run_unittest(TestMacostools)
  98.  
  99.  
  100. if __name__ == '__main__':
  101.     test_main()
  102.