def testArgumentOrder(self): self.getFileNames() with nostderrout(): statuslyx, msglyx = tablefill(template = self.lyxtemplate, input = self.input_appendix, output = self.lyxoutput) statustex, msgtex = tablefill(template = self.textemplate, input = self.input_appendix, output = self.texoutput) self.assertEqual('SUCCESS', statustex) self.assertEqual('SUCCESS', statuslyx) texfilled_data_args1 = open(self.texoutput, 'rU').readlines() lyxfilled_data_args1 = open(self.lyxoutput, 'rU').readlines() with nostderrout(): statuslyx, msglyx = tablefill(output = self.lyxoutput, template = self.lyxtemplate, input = self.input_appendix) statustex, msgtex = tablefill(output = self.lyxoutput, template = self.lyxtemplate, input = self.input_appendix) self.assertEqual('SUCCESS', statustex) self.assertEqual('SUCCESS', statuslyx) texfilled_data_args2 = open(self.texoutput, 'rU').readlines() lyxfilled_data_args2 = open(self.lyxoutput, 'rU').readlines() self.assertEqual(texfilled_data_args1, texfilled_data_args2) self.assertEqual(lyxfilled_data_args1, lyxfilled_data_args2)
def testIllegalSyntax(self): self.getFileNames() # missing arguments with nostderrout(): errorlyx, msglyx = tablefill(input = self.input_appendix, template = self.lyxtemplate) errortex, msgtex = tablefill(input = self.input_appendix, template = self.textemplate) self.assertEqual('ERROR', errortex) self.assertEqual('ERROR', errorlyx) self.assertIn('KeyError', msgtex) self.assertIn('KeyError', msglyx) # Must be strings with nostderrout(): errorlyx, msglyx = tablefill(input = [self.input_appendix], template = self.lyxtemplate, output = self.lyxoutput) errortex, msgtex = tablefill(input = [self.input_appendix], template = self.textemplate, output = self.texoutput) self.assertEqual('ERROR', errortex) self.assertEqual('ERROR', errorlyx) self.assertIn('TypeError', msgtex) self.assertIn('TypeError', msglyx) with nostderrout(): errorlyx, msglyx = tablefill(input = self.input_appendix, template = self.lyxtemplate, output = 10) errortex, msgtex = tablefill(input = self.input_appendix, template = self.textemplate, output = 10) self.assertEqual('ERROR', errortex) self.assertEqual('ERROR', errorlyx) self.assertIn('TypeError', msgtex) self.assertIn('TypeError', msglyx) # unexpected arguments are ignored with nostderrout(): statuslyx, msglyx = tablefill(input = self.input_appendix, template = self.lyxtemplate, waffle = "My Waffles are Best!", output = self.lyxoutput) statustex, msgtex = tablefill(input = self.input_appendix, template = self.textemplate, waffle = "My Waffles are Best!", output = self.texoutput) self.assertEqual('SUCCESS', statustex) self.assertEqual('SUCCESS', statuslyx)
def test_default_log(self): with nostderrout(): run_perl(program='./input/perl_test_script.pl') logfile_data = open('../output/make.log', 'r').read() self.assertIn('Test script completed', logfile_data) self.assertIn('Time : ', logfile_data) self.assertTrue(os.path.isfile('output.txt'))
def test_executable(self): with nostderrout(): run_rbatch(program='./input/R_test_script.R', executable='R CMD BATCH') logfile_data = open('../output/make.log', 'r').read() self.assertIn('Test script complete', logfile_data) self.assertTrue(os.path.isfile('output.txt'))
def test_change_dir(self): with nostderrout(): run_rbatch(program='./input/R_test_script.R', changedir=True) logfile_data = open('../output/make.log', 'r').read() self.assertIn('Test script complete', logfile_data) self.assertIn('> proc.time()', logfile_data) self.assertTrue(os.path.isfile('./input/output.txt'))
def test_default_log(self): with nostderrout(): run_lyx(program='./input/lyx_test_file.lyx') logfile_data = open('../output/make.log', 'r').read() self.assertIn('LaTeX', logfile_data) self.assertIn('Time : ', logfile_data) self.assertTrue(os.path.isfile('../output/lyx_test_file.pdf'))
def test_legal_input(self): default_makelog_file = os.path.join(self.output_dir, 'make.log') default_links_dir = '../external_links/' self.assertFalse(os.path.isdir(default_links_dir)) links = './input/links_legal.txt' with nostderrout(): make_links(links, quiet=True) self.assertTrue(os.path.isdir(default_links_dir)) links_data = open(links, 'r').readlines() comments_ct = self.find_comment_lines(links_data) wildcard_lines_ct = len([l for l in links_data if '*' in l]) wildcard_files_ct = len( [f for f in os.listdir('./input/') if f.endswith('_script.m')]) number_of_links = len(links_data) - comments_ct - wildcard_lines_ct + \ wildcard_files_ct success_count = self.get_string_count(default_makelog_file, 'Symlink successfully created.') self.assertTrue(success_count == number_of_links) prefix_files_ct = len([ f for f in os.listdir('../external_links/') if f.startswith('input_') ]) self.assertEqual(prefix_files_ct, wildcard_files_ct) f = open('../external_links/ext.txt', 'r') self.assertTrue(f.readline().startswith('11 22')) f.close() logfile_data = open(default_makelog_file, 'r').read() self.assertNotIn('Error', logfile_data)
def test_bad_executable(self): with nostderrout(): run_rinstall( package='./input/rinstall_test_package/Ecdat_0.1-6.1.tar.gz', executable='nonexistent_R_executable') logfile_data = open('../output/make.log', 'r').read() self.assertIn('executed with errors', logfile_data)
def test_nofile(self): self.assertFalse(os.path.isfile('../output/add1.txt')) with nostderrout(): add_log('../output/add1.txt', makelog='../output/make.log') logfile_data = open('../output/make.log', 'r').read() message = messages.note_nofile % '../output/add1.txt' self.assertIn(message, logfile_data)
def setUp(self): makelog_file = '../output/make.log' output_dir = '../output/' with nostderrout(): clear_output_dirs(output_dir, '') start_make_logging(makelog_file) run_stata(program='./input/stata_test_script.do')
def test_no_manifest_file(self): manifest_file = '../output/data_file_manifest.log' os.remove(manifest_file) with nostderrout(): check_manifest(manifest_file, '../output/') logfile_data = open('../output/make.log', 'r').readlines() self.assertIn('CritError:', logfile_data[-1])
def test_wildcards(self): file_list = glob.glob(os.path.join(self.private, '*')) self.assertTrue(len(file_list) >= 8) with nostderrout(): delete_files('./input/externals_delete_files/private/*') file_list = glob.glob(os.path.join(self.private, '*')) self.assertEqual(len(file_list), 0)
def test_standard(self): self.assertTrue(os.path.exists('./externals/')) file_list = os.listdir('./externals/') self.assertTrue(len(file_list) > 0) with nostderrout(): remove_dir('./externals/') self.assertFalse(os.path.exists('./externals/'))
def test_executable(self): with nostderrout(): run_matlab(program='./input/matlab_test_script.m', executable='matlab') self.assert_proper_output('../output/make.log') self.assertTrue(os.path.isfile('../output/matlab_test.mat')) self.assertTrue(os.path.isfile('../output/matlab_test.eps'))
def test_executable(self): with nostderrout(): run_rinstall( package='./input/rinstall_test_package/Ecdat_0.1-6.1.tar.gz', executable='R CMD INSTALL') self.assertTrue( self.last_line_equals('../output/make.log', '* DONE (Ecdat)\n'))
def test_option(self): with nostderrout(): run_mathematica(program='./input/mathematica_test_script.m', option='-initfile ' + './input/mathematica_init_script.m') logfile_data = open('../output/make.log', 'r').read() self.assertIn('mathematica test ended', logfile_data)
def test_options(self): with nostderrout(): run_python(program='./input/python_test_script.py', option='-h') logfile_data = open('../output/make.log', 'r').read() self.assertIn( 'Options and arguments ' + '(and corresponding environment variables):', logfile_data)
def test_change_dir(self): with nostderrout(): run_mathematica(program='./input/mathematica_test_script.m', changedir=True) logfile_data = open('../output/make.log', 'r').read() self.assertIn('mathematica test ended', logfile_data) self.assertTrue(os.path.isfile('./input/output_plot.eps'))
def test_nofile(self): os.remove('del_log.txt') with nostderrout(): del_log('del_log.txt', makelog='../output/make.log') logfile_data = open('../output/make.log', 'r').read() message = messages.note_nofile % 'del_log.txt' self.assertIn(message, logfile_data)
def test_default_log(self): with nostderrout(): run_mathematica(program='./input/mathematica_test_script.m') logfile_data = open('../output/make.log', 'r').read() self.assertIn('mathematica test ended', logfile_data) self.assertIn('Time : ', logfile_data) self.assertTrue(os.path.isfile('output_plot.eps'))
def test_executable(self): with nostderrout(): run_python(program='./input/python_test_script.py', executable='python') logfile_data = open('../output/make.log', 'r').read() self.assertIn('Test script complete', logfile_data) self.assertTrue(os.path.isfile('output.txt'))
def test_pdfout(self): with nostderrout(): run_lyx(program='./input/lyx_test_file.lyx', pdfout='../output/custom_outfile.pdf') logfile_data = open('../output/make.log', 'r').read() self.assertIn('LaTeX', logfile_data) self.assertTrue(os.path.isfile('../output/custom_outfile.pdf')) self.assertFalse(os.path.isfile('./input/lyx_test_file.pdf'))
def test_default_log(self): with nostderrout(): run_matlab(program='./input/matlab_test_script.m') self.assert_proper_output('../output/make.log') logfile_data = open('../output/make.log', 'r').read() self.assertIn('Time : ', logfile_data) self.assertTrue(os.path.isfile('../output/matlab_test.mat')) self.assertTrue(os.path.isfile('../output/matlab_test.eps'))
def test_default_log(self): with nostderrout(): run_rinstall( package='./input/rinstall_test_package/Ecdat_0.1-6.1.tar.gz') self.assertTrue( self.last_line_equals('../output/make.log', '* DONE (Ecdat)\n')) logfile_data = open('../output/make.log', 'r').read() self.assertIn('Time : ', logfile_data)
def test_option(self): with nostderrout(): run_rbatch(program='./input/R_test_script.R', option='--no-timing') logfile_data = open('../output/make.log', 'r').read() self.assertIn('Test script complete', logfile_data) self.assertIn('R version', logfile_data) self.assertNotIn('> proc.time()', logfile_data) self.assertTrue(os.path.isfile('output.txt'))
def test_single_file(self): file_list = glob.glob(os.path.join(self.delete_files, '*')) file_number = len(file_list) self.assertTrue(os.path.isfile(self.dir_mod)) with nostderrout(): delete_files(self.dir_mod) file_list = glob.glob(os.path.join(self.delete_files, '*')) self.assertEqual(len(file_list), file_number - 1) self.assertFalse(os.path.isfile(self.dir_mod))
def test_set_option(self): with nostderrout(): set_option(makelog='../customoutput/custommake.log', temp_dir='../customtemp/', output_dir='../customoutput/', manifest='../customoutput/data_file_manifest.log') clear_output_dirs() start_make_logging() run_stata(program='./input/stata_test_script_alt.do') self.remove_manifest_entry('../customoutput/data_file_manifest.log', 1) with nostderrout(): check_manifest() end_make_logging() self.assertTrue(os.path.isdir('../customoutput/')) self.assertTrue(os.path.isdir('../customtemp/')) self.assertTrue(os.path.isfile('../customoutput/custommake.log')) self.assertTrue( self.check_results('../customoutput/custommake.log', 1, 0))
def test_independent_log(self): with nostderrout(): run_rinstall( package='./input/rinstall_test_package/Ecdat_0.1-6.1.tar.gz', log='../output/R.log') self.assertTrue( self.last_line_equals('../output/make.log', '* DONE (Ecdat)\n')) self.assertTrue( self.last_line_equals('../output/R.log', '* DONE (Ecdat)\n'))
def test_custom_directories(self): self.assertFalse(os.path.isdir('../customoutput/')) self.assertFalse(os.path.isdir('../customtemp/')) with nostderrout(): clear_output_dirs('../customoutput/', '../customtemp/') start_make_logging('../customoutput/make.log') self.assertTrue(os.path.isdir('../customoutput/')) self.assertTrue(os.path.isdir('../customtemp/')) self.assertTrue(os.path.isfile('../customoutput/make.log'))
def test_independent_log(self): with nostderrout(): run_matlab(program='./input/matlab_test_script.m', log='../output/matlab.log') self.assert_proper_output('../output/make.log') self.assertTrue(os.path.isfile('../output/matlab.log')) self.assert_proper_output('../output/matlab.log') self.assertTrue(os.path.isfile('../output/matlab_test.mat')) self.assertTrue(os.path.isfile('../output/matlab_test.eps'))