Changeset 6873 for anuga_core/source
- Timestamp:
- Apr 22, 2009, 11:19:26 AM (16 years ago)
- Location:
- anuga_core/source/anuga/shallow_water
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/shallow_water/data_manager.py
r6711 r6873 6675 6675 6676 6676 6677 # FIXME (DSG): Add unit test, make general, not just 2 files,6678 # but any number of files.6679 6677 ## 6680 6678 # @brief Copy a file to a directory, and optionally append another file to it. … … 6682 6680 # @param filename Path to file to copy to directory 'dir_name'. 6683 6681 # @param filename2 Optional path to file to append to copied file. 6684 def copy_code_files(dir_name, filename1, filename2=None): 6682 # @param verbose True if this function is to be verbose. 6683 # @note Allow filenames to be either a string or sequence of strings. 6684 def copy_code_files(dir_name, filename1, filename2=None, verbose=False): 6685 6685 """Copies "filename1" and "filename2" to "dir_name". 6686 Very useful for information management 6687 filename1 and filename2 are both absolute pathnames 6688 """ 6689 6686 6687 Each 'filename' may be a string or list of filename strings. 6688 6689 Filenames must be absolute pathnames 6690 """ 6691 6692 ## 6693 # @brief copies a file or sequence to destination directory. 6694 # @param dest The destination directory to copy to. 6695 # @param file A filename string or sequence of filename strings. 6696 def copy_file_or_sequence(dest, file): 6697 if hasattr(file, '__iter__'): 6698 for f in file: 6699 shutil.copy(f, dir_name) 6700 if verbose: 6701 print 'File %s copied' % (f) 6702 else: 6703 shutil.copy(file, dir_name) 6704 if verbose: 6705 print 'File %s copied' % (file) 6706 6707 # check we have a destination directory, create if necessary 6690 6708 if access(dir_name, F_OK) == 0: 6691 print 'Make directory %s' % dir_name 6692 mkdir (dir_name,0777) 6693 6694 shutil.copy(filename1, dir_name + sep + basename(filename1)) 6695 6696 if filename2 != None: 6697 shutil.copy(filename2, dir_name + sep + basename(filename2)) 6698 print 'Files %s and %s copied' %(filename1, filename2) 6699 else: 6700 print 'File %s copied' %(filename1) 6709 mkdir(dir_name, 0777) 6710 6711 copy_file_or_sequence(dir_name, filename1) 6712 6713 if not filename2 is None: 6714 copy_file_or_sequence(dir_name, filename2) 6701 6715 6702 6716 -
anuga_core/source/anuga/shallow_water/test_data_manager.py
r6752 r6873 15 15 from struct import pack, unpack 16 16 from sets import ImmutableSet 17 import shutil 17 18 18 19 from anuga.shallow_water import * … … 11627 11628 11628 11629 11630 def test_copy_code_files(self): 11631 '''test that the copy_code_files() function is sane.''' 11632 11633 def create_file(f): 11634 fd = open(f, 'w') 11635 fd.write('%s\n' % f) 11636 fd.close() 11637 11638 # create working directories and test files 11639 work_dir = tempfile.mkdtemp() 11640 dst_dir = tempfile.mkdtemp(dir=work_dir) 11641 src_dir = tempfile.mkdtemp(dir=work_dir) 11642 11643 f1 = 'file1' 11644 filename1 = os.path.join(src_dir, f1) 11645 create_file(filename1) 11646 f2 = 'file2' 11647 filename2 = os.path.join(src_dir, f2) 11648 create_file(filename2) 11649 f3 = 'file3' 11650 filename3 = os.path.join(src_dir, f3) 11651 create_file(filename3) 11652 f4 = 'file4' 11653 filename4 = os.path.join(src_dir, f4) 11654 create_file(filename4) 11655 f5 = 'file5' 11656 filename5 = os.path.join(src_dir, f5) 11657 create_file(filename5) 11658 11659 # exercise the copy function 11660 copy_code_files(dst_dir, filename1) 11661 copy_code_files(dst_dir, filename1, filename2) 11662 copy_code_files(dst_dir, (filename4, filename5, filename3)) 11663 11664 # test that files were actually copied 11665 self.failUnless(access(os.path.join(dst_dir, f1), F_OK)) 11666 self.failUnless(access(os.path.join(dst_dir, f2), F_OK)) 11667 self.failUnless(access(os.path.join(dst_dir, f3), F_OK)) 11668 self.failUnless(access(os.path.join(dst_dir, f4), F_OK)) 11669 self.failUnless(access(os.path.join(dst_dir, f5), F_OK)) 11670 11671 # clean up 11672 shutil.rmtree(work_dir) 11629 11673 11630 11674 #------------------------------------------------------------- … … 11632 11676 11633 11677 suite = unittest.makeSuite(Test_Data_Manager,'test') 11634 #suite = unittest.makeSuite(Test_Data_Manager,'test_file_boundary_sts')11635 #suite = unittest.makeSuite(Test_Data_Manager,'test_get_flow_through_cross_section_with_geo')11636 #suite = unittest.makeSuite(Test_Data_Manager,'covered_')11637 #suite = unittest.makeSuite(Test_Data_Manager,'test_urs2sts_individual_sources')11638 #suite = unittest.makeSuite(Test_Data_Manager,'test_urs2sts_ordering_different_sources')11639 11640 #suite = unittest.makeSuite(Test_Data_Manager,'test_read_mux_platform_problem3')11641 #suite = unittest.makeSuite(Test_Data_Manager,'test_file_boundary_stsIV')11642 11643 11678 11644 11679 if len(sys.argv) > 1 and sys.argv[1][0].upper() == 'V':
Note: See TracChangeset
for help on using the changeset viewer.