Changeset 7745
- Timestamp:
- May 25, 2010, 2:20:32 PM (15 years ago)
- Location:
- anuga_core/source/anuga
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/abstract_2d_finite_volumes/util.py
r7737 r7745 309 309 310 310 311 # FIXME (DSG): Add unit test, make general, not just 2 files, 312 # but any number of files. 313 ## 314 # @brief ?? 315 # @param dir_name ?? 316 # @param filename1 ?? 317 # @param filename2 ?? 318 # @return ?? 319 # @note TEMP 320 def copy_code_files(dir_name, filename1, filename2): 321 """Temporary Interface to new location""" 322 323 from anuga.shallow_water.data_manager import \ 324 copy_code_files as dm_copy_code_files 325 log.critical('copy_code_files has moved from util.py.') 326 log.critical('Please use "from anuga.shallow_water.data_manager import ' 327 'copy_code_files"') 328 329 return dm_copy_code_files(dir_name, filename1, filename2) 330 311 def copy_code_files(dir_name, filename1, filename2, verbose=False): 312 """Copies "filename1" and "filename2" to "dir_name". 313 314 Each 'filename' may be a string or list of filename strings. 315 316 Filenames must be absolute pathnames 317 """ 318 319 ## 320 # @brief copies a file or sequence to destination directory. 321 # @param dest The destination directory to copy to. 322 # @param file A filename string or sequence of filename strings. 323 def copy_file_or_sequence(dest, file): 324 if hasattr(file, '__iter__'): 325 for f in file: 326 shutil.copy(f, dir_name) 327 if verbose: 328 log.critical('File %s copied' % f) 329 else: 330 shutil.copy(file, dir_name) 331 if verbose: 332 log.critical('File %s copied' % file) 333 334 # check we have a destination directory, create if necessary 335 if not os.path.isdir(dir_name): 336 if verbose: 337 log.critical('Make directory %s' % dir_name) 338 mkdir(dir_name, 0777) 339 340 if verbose: 341 log.critical('Output directory: %s' % dir_name) 342 343 copy_file_or_sequence(dir_name, filename1) 344 345 if not filename2 is None: 346 copy_file_or_sequence(dir_name, filename2) 331 347 332 348 ## -
anuga_core/source/anuga/shallow_water/test_data_manager.py
r7744 r7745 7546 7546 assert len(iterate)==4 7547 7547 7548 def test_screen_catcher(self):7549 7550 stdout_orginal = sys.stdout7551 stderr_orginal = sys.stderr7552 7553 output_dir = tempfile.mkdtemp('','output_test')7554 #print output_dir7555 start_screen_catcher(output_dir+sep,verbose=False)7556 7557 print 'hello screen catcher'7558 print 'goodbye screen catcher'7559 7560 sys.stdout = stdout_orginal7561 sys.stderr = stderr_orginal7562 7563 output_file = output_dir+sep+'screen_output.txt'7564 assert access(output_file,F_OK)7565 7566 fid = open(output_file)7567 file_line1 = fid.readline()7568 file_line2 = fid.readline()7569 7570 #print 'file contents',file_line1, file_line27571 assert (file_line1 == 'hello screen catcher\n')7572 assert (file_line2 == 'goodbye screen catcher\n')7573 7574 7548 7575 7549 def test_points2polygon(self): … … 7771 7745 assert float(values[id]) == float(floors[id]) 7772 7746 7773 7774 def test_copy_code_files(self): 7775 '''test that the copy_code_files() function is sane.''' 7776 7777 def create_file(f): 7778 fd = open(f, 'w') 7779 fd.write('%s\n' % f) 7780 fd.close() 7781 7782 # create working directories and test files 7783 work_dir = tempfile.mkdtemp() 7784 dst_dir = tempfile.mkdtemp(dir=work_dir) 7785 src_dir = tempfile.mkdtemp(dir=work_dir) 7786 7787 f1 = 'file1' 7788 filename1 = os.path.join(src_dir, f1) 7789 create_file(filename1) 7790 f2 = 'file2' 7791 filename2 = os.path.join(src_dir, f2) 7792 create_file(filename2) 7793 f3 = 'file3' 7794 filename3 = os.path.join(src_dir, f3) 7795 create_file(filename3) 7796 f4 = 'file4' 7797 filename4 = os.path.join(src_dir, f4) 7798 create_file(filename4) 7799 f5 = 'file5' 7800 filename5 = os.path.join(src_dir, f5) 7801 create_file(filename5) 7802 7803 # exercise the copy function 7804 copy_code_files(dst_dir, filename1) 7805 copy_code_files(dst_dir, filename1, filename2) 7806 copy_code_files(dst_dir, (filename4, filename5, filename3)) 7807 7808 # test that files were actually copied 7809 self.failUnless(access(os.path.join(dst_dir, f1), F_OK)) 7810 self.failUnless(access(os.path.join(dst_dir, f2), F_OK)) 7811 self.failUnless(access(os.path.join(dst_dir, f3), F_OK)) 7812 self.failUnless(access(os.path.join(dst_dir, f4), F_OK)) 7813 self.failUnless(access(os.path.join(dst_dir, f5), F_OK)) 7814 7815 # clean up 7816 shutil.rmtree(work_dir) 7817 7747 7818 7748 #------------------------------------------------------------- 7819 7749 -
anuga_core/source/anuga/utilities/file_utils.py
r7744 r7745 391 391 392 392 return Y 393 394
Note: See TracChangeset
for help on using the changeset viewer.