def test_makelog(self): with no_stderrout(): paths = self.make_paths() start_makelog(paths) write_to_makelog(paths, 'Hello, World!') end_makelog(paths) self.check_makelog(paths)
def test_log_output_depth_one(self): with no_stderrout(): paths = self.make_paths( output_path='test/raw/log_outputs/dir_depth') log_files_in_output(paths, depth=1) self.assertIn('depth_1.txt', read_file(paths['output_statslog'])) self.assertIn('depth_2.txt', read_file(paths['output_statslog']))
def setup_directories(self): with no_stderrout(): remove_dir(['test/external/', 'test/input/']) clear_dir(['test/output/', 'test/log/']) if not os.path.isdir('test/raw/move_sources/dir/'): os.makedirs('test/raw/move_sources/dir/')
def test_makelog_character(self): with no_stderrout(): paths = self.make_paths(makelog_path='test/log/make_╬▓.log') start_makelog(paths) write_to_makelog(paths, 'Hello, World! ╬▓') end_makelog(paths) self.check_makelog(paths)
def make_paths(self, makelog_path = 'test/log/make.log'): paths = {'makelog': makelog_path} with no_stderrout(): start_makelog(paths) return(paths)
def test_error_bad_paths(self): with self.assertRaises(Exception): with no_stderrout(): paths = {} start_makelog(paths) write_to_makelog(paths, 'Hello, World!') end_makelog(paths)
def test_zip_to_not_exist_file(self): # Zip directory with no_stderrout(): zip_dir('test/output/', 'test/output/zipped.zip') # Check zip self.assertTrue(os.path.isfile('test/output/zipped.zip'))
def test_program(self): with no_stderrout(): paths = self.make_paths() program_name = 'test/raw/run_program/%s_script.%s' % (self.app, self.ext) run_function(paths, program = program_name) self.check_output(paths)
def test_program_space(self): with no_stderrout(): paths = self.make_paths(makelog_path = 'test/log/make space.log') program_name = 'test/raw/run_program/%s_script space.%s' % (self.app, self.ext) run_function(paths, program = program_name) self.check_output(paths)
def test_log_output_no_log(self): with no_stderrout(): paths = self.make_paths(output_path='test/raw/log_outputs/dir', output_statslog='') log_files_in_output(paths) self.check_makelog(paths) self.assertFalse(os.path.isfile(paths['output_statslog']))
def test_makelog_space(self): with no_stderrout(): paths = self.make_paths(makelog_path='test/log/make space.log') start_makelog(paths) write_to_makelog(paths, 'Hello, World!') end_makelog(paths) self.check_makelog(paths)
def test_log_space(self): with no_stderrout(): paths = self.make_paths() program_name = 'test/raw/run_program/%s_script.%s' % (self.app, self.ext) run_function(paths, program = program_name, log = 'test/output/log space.log') self.check_output(paths) self.assertIn('Test script complete', read_file('test/output/log space.log'))
def test_program_handout(self): with no_stderrout(): paths = self.make_paths() program_name = 'test/raw/run_program/%s_file_handout.%s' % ( self.app, self.ext) run_function(paths, program=program_name, doctype='handout') self.check_output(paths, '%s_file_handout.pdf' % self.app)
def test_log_output_depth_one(self): with no_stderrout(): paths = self.make_paths() inputs = link_inputs(paths, ['test/raw/log_sources/move_depth.txt']) write_source_logs(paths, inputs, depth=1) self.assertIn('depth_1.txt', read_file(paths['source_statslog'])) self.assertIn('depth_2.txt', read_file(paths['source_statslog']))
def test_error_bad_arg(self): try: with no_stderrout(): paths = self.make_paths() program_name = 'test/raw/run_program/%s_script.%s' % (self.app, self.ext) run_function(paths, program = program_name, arg = []) except Exception as e: self.assertRaises(Exception, e)
def test_log_output_character(self): with no_stderrout(): paths = self.make_paths() inputs = link_inputs(paths, ['test/raw/log_sources/move_╬▓.txt']) write_source_logs(paths, inputs) self.check_makelog(paths) self.assertIn('dir_╬▓', read_file(paths['source_maplog'])) self.assertIn('file_╬▓.txt', read_file(paths['source_statslog']))
def test_error_program_wrong_extension(self): try: with no_stderrout(): paths = self.make_paths() program_name = 'test/raw/run_program/wrong_extension.txt' run_function(paths, program = program_name) except Exception as e: self.assertRaises(Exception, e)
def test_error_bad_path(self): with no_stderrout(): try: paths = {} log_files_in_output(paths) self.check_logs(paths) except Exception as e: self.assertRaises(Exception, e)
def test_program_character(self): with no_stderrout(): paths = self.make_paths(makelog_path='test/log/make_╬▓.log') program_name = 'test/raw/run_program/%s_file_╬▓.%s' % (self.app, self.ext) run_function(paths, program=program_name) self.check_output(paths, '%s_file_╬▓.pdf' % self.app)
def test_log_output_space(self): with no_stderrout(): paths = self.make_paths( output_path='test/raw/log_outputs/dir space') log_files_in_output(paths) self.check_makelog(paths) self.assertIn('file space.txt', read_file(paths['output_statslog']))
def test_error_bad_path(self): with no_stderrout(): try: paths = {} inputs = link_inputs(paths, ['test/raw/log_sources/move space.txt']) write_source_logs(paths, inputs) except Exception as e: self.assertRaises(Exception, e)
def test_error_program_missing(self): try: with no_stderrout(): paths = self.make_paths() program_name = 'test/raw/run_program/%s_file_missing.%s' % ( self.app, self.ext) run_function(paths, program=program_name) except Exception as e: self.assertRaises(Exception, e)
def test_no_log(self): with no_stderrout(): paths = self.make_paths(makelog_path = '') program_name = 'test/raw/run_program/%s_script.%s' % (self.app, self.ext) run_function(paths, program = program_name, log = '') self.assertFalse(os.path.isfile(paths['makelog'])) self.assertFalse(os.path.isfile('test/output/log.log')) self.assertTrue(os.path.isfile('test/output/output.csv'))
def make_paths(self, makelog_path='test/log/make.log', output_dir='test/output'): paths = {'makelog': makelog_path, 'output_dir': output_dir} with no_stderrout(): start_makelog(paths) return (paths)
def test_log_output_local_string(self): with no_stderrout(): paths = self.make_paths( output_path='test/raw/log_outputs/dir', output_local_path='test/raw/log_outputs/dir_local') log_files_in_output(paths) self.check_logs(paths) self.assertIn('file_local.txt', read_file(paths['output_statslog']))
def test_program_arg(self): with no_stderrout(): paths = self.make_paths() program_name = 'test/raw/run_program/%s_script_arg.%s' % (self.app, self.ext) run_function(paths, program = program_name, args = self.arg) self.check_output(paths) output = read_file('test/output/output.csv') self.assertTrue(re.search('arg', output))
def test_log_output_no_log(self): with no_stderrout(): paths = self.make_paths(source_maplog_path='', source_statslog_path='') inputs = link_inputs(paths, ['test/raw/log_sources/move space.txt']) write_source_logs(paths, inputs) self.check_makelog(paths) self.assertFalse(os.path.isfile(paths['source_maplog'])) self.assertFalse(os.path.isfile(paths['source_statslog']))
def test_zip_to_exist_file(self): create_file('test/output/zipped.zip') with no_stderrout(): zip_dir('test/output/', 'test/output/zipped.zip') # Check zip self.assertTrue(os.path.isfile('test/output/zipped.zip')) unzip('test/output/unzip.zip', 'test/output/unzipped/') self.assertTrue(os.path.isfile('test/output/unzipped/file.txt'))
def test_program_executable(self): with no_stderrout(): paths = self.make_paths() program_name = 'test/raw/run_program/%s_file.%s' % (self.app, self.ext) run_function(paths, program=program_name, executable=self.executable) self.check_output(paths)
def test_error_corrupt_paths(self): with self.assertRaises(Exception): with no_stderrout(): paths = {'makelog': 'test/log/make.log', 'input_dir': 'test/input/', 'external_dir': 'test/external/', 'bad_key': []} self.move_function(paths, ['test/raw/move_sources/move_file.txt']) self.check_move(paths)