| 
									
										
										
										
											2003-01-28 21:39:28 +00:00
										 |  |  | # Copyright (C) 2003 Python Software Foundation | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import unittest | 
					
						
							|  |  |  | import macostools | 
					
						
							| 
									
										
										
										
											2003-02-27 23:18:46 +00:00
										 |  |  | import Carbon.File | 
					
						
							| 
									
										
										
										
											2003-01-28 21:39:28 +00:00
										 |  |  | import MacOS | 
					
						
							|  |  |  | import os | 
					
						
							| 
									
										
										
										
											2003-01-28 23:54:05 +00:00
										 |  |  | import sys | 
					
						
							| 
									
										
										
										
											2003-01-28 21:39:28 +00:00
										 |  |  | from test import test_support | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TESTFN2 = test_support.TESTFN + '2' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class TestMacostools(unittest.TestCase): | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def setUp(self): | 
					
						
							|  |  |  |         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() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def tearDown(self): | 
					
						
							|  |  |  |         try: | 
					
						
							|  |  |  |             os.unlink(test_support.TESTFN) | 
					
						
							|  |  |  |         except: | 
					
						
							|  |  |  |             pass | 
					
						
							|  |  |  |         try: | 
					
						
							|  |  |  |             os.unlink(TESTFN2) | 
					
						
							|  |  |  |         except: | 
					
						
							|  |  |  |             pass | 
					
						
							| 
									
										
										
										
											2003-02-19 02:35:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-28 21:39:28 +00:00
										 |  |  |     def compareData(self): | 
					
						
							|  |  |  |         fp = open(test_support.TESTFN, 'r') | 
					
						
							|  |  |  |         data1 = fp.read() | 
					
						
							|  |  |  |         fp.close() | 
					
						
							|  |  |  |         fp = open(TESTFN2, 'r') | 
					
						
							|  |  |  |         data2 = fp.read() | 
					
						
							|  |  |  |         fp.close() | 
					
						
							|  |  |  |         if data1 != data2: | 
					
						
							|  |  |  |             return 'Data forks differ' | 
					
						
							|  |  |  |         rfp = MacOS.openrf(test_support.TESTFN, '*rb') | 
					
						
							|  |  |  |         data1 = rfp.read(1000) | 
					
						
							|  |  |  |         rfp.close() | 
					
						
							|  |  |  |         rfp = MacOS.openrf(TESTFN2, '*rb') | 
					
						
							|  |  |  |         data2 = rfp.read(1000) | 
					
						
							|  |  |  |         rfp.close() | 
					
						
							|  |  |  |         if data1 != data2: | 
					
						
							|  |  |  |             return 'Resource forks differ' | 
					
						
							|  |  |  |         return '' | 
					
						
							| 
									
										
										
										
											2003-02-19 02:35:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-28 21:39:28 +00:00
										 |  |  |     def test_touched(self): | 
					
						
							|  |  |  |         # This really only tests that nothing unforeseen happens. | 
					
						
							| 
									
										
										
										
											2007-05-20 23:17:38 +00:00
										 |  |  |         import warnings | 
					
						
							| 
									
										
										
										
											2007-08-14 17:53:30 +00:00
										 |  |  |         with test_support.catch_warning(): | 
					
						
							| 
									
										
										
										
											2007-05-20 23:17:38 +00:00
										 |  |  |             warnings.filterwarnings('ignore', 'macostools.touched*', | 
					
						
							|  |  |  |                                     DeprecationWarning) | 
					
						
							|  |  |  |             macostools.touched(test_support.TESTFN) | 
					
						
							| 
									
										
										
										
											2003-02-19 02:35:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-28 21:39:28 +00:00
										 |  |  |     def test_copy(self): | 
					
						
							|  |  |  |         try: | 
					
						
							|  |  |  |             os.unlink(TESTFN2) | 
					
						
							|  |  |  |         except: | 
					
						
							|  |  |  |             pass | 
					
						
							|  |  |  |         macostools.copy(test_support.TESTFN, TESTFN2) | 
					
						
							|  |  |  |         self.assertEqual(self.compareData(), '') | 
					
						
							| 
									
										
										
										
											2003-02-19 02:35:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-28 23:54:05 +00:00
										 |  |  |     def test_mkalias(self): | 
					
						
							|  |  |  |         try: | 
					
						
							|  |  |  |             os.unlink(TESTFN2) | 
					
						
							|  |  |  |         except: | 
					
						
							|  |  |  |             pass | 
					
						
							|  |  |  |         macostools.mkalias(test_support.TESTFN, TESTFN2) | 
					
						
							| 
									
										
										
										
											2003-02-27 23:18:46 +00:00
										 |  |  |         fss, _, _ = Carbon.File.ResolveAliasFile(TESTFN2, 0) | 
					
						
							| 
									
										
										
										
											2003-02-05 11:14:16 +00:00
										 |  |  |         self.assertEqual(fss.as_pathname(), os.path.realpath(test_support.TESTFN)) | 
					
						
							| 
									
										
										
										
											2003-02-19 02:35:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-28 23:54:05 +00:00
										 |  |  |     def test_mkalias_relative(self): | 
					
						
							|  |  |  |         try: | 
					
						
							|  |  |  |             os.unlink(TESTFN2) | 
					
						
							|  |  |  |         except: | 
					
						
							|  |  |  |             pass | 
					
						
							| 
									
										
										
										
											2004-12-06 06:08:59 +00:00
										 |  |  |         # If the directory doesn't exist, then chances are this is a new | 
					
						
							|  |  |  |         # install of Python so don't create it since the user might end up | 
					
						
							|  |  |  |         # running ``sudo make install`` and creating the directory here won't | 
					
						
							|  |  |  |         # leave it with the proper permissions. | 
					
						
							|  |  |  |         if not os.path.exists(sys.prefix): | 
					
						
							|  |  |  |             return | 
					
						
							| 
									
										
										
										
											2003-01-28 23:54:05 +00:00
										 |  |  |         macostools.mkalias(test_support.TESTFN, TESTFN2, sys.prefix) | 
					
						
							| 
									
										
										
										
											2003-02-27 23:18:46 +00:00
										 |  |  |         fss, _, _ = Carbon.File.ResolveAliasFile(TESTFN2, 0) | 
					
						
							| 
									
										
										
										
											2003-02-05 11:14:16 +00:00
										 |  |  |         self.assertEqual(fss.as_pathname(), os.path.realpath(test_support.TESTFN)) | 
					
						
							| 
									
										
										
										
											2003-02-19 02:35:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-28 21:39:28 +00:00
										 |  |  | def test_main(): | 
					
						
							| 
									
										
										
										
											2008-06-19 21:39:06 +00:00
										 |  |  |     # Skip on wide unicode | 
					
						
							|  |  |  |     if len(u'\0'.encode('unicode-internal')) == 4: | 
					
						
							|  |  |  |         raise test_support.TestSkipped("test_macostools is broken in USC4") | 
					
						
							| 
									
										
										
										
											2003-01-28 21:39:28 +00:00
										 |  |  |     test_support.run_unittest(TestMacostools) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if __name__ == '__main__': | 
					
						
							|  |  |  |     test_main() |