def test_log_creation(self, mock_check_output): '''Test build_python()'s behaviour when given standard inputs.''' mock_check_output.side_effect = fx.python_side_effect helpers.standard_test(self, gs.build_python, 'py', system_mock=mock_check_output)
def test_stata_executable_unix(self, mock_check): mock_check.side_effect = fx.make_stata_side_effect('stata-mp') env = {'stata_executable': 'stata-mp'} helpers.standard_test(self, gs.build_stata, 'do', env=env, system_mock=mock_check)
def test_nonexistent_input(self): ''' Test build_python()'s behaviour when the source script doesn't exist. ''' if os.path.exists('test.py'): os.remove('test.py') with self.assertRaises(ExecCallError): helpers.standard_test(self, gs.build_python, source='test.py')
def test_windows(self, mock_copy, mock_check_output): ''' Test that build_matlab() creates a log and properly submits a matlab system command on a Windows machine. ''' mock_copy.side_effect = fx.matlab_copy_effect mock_check_output.side_effect = fx.make_matlab_side_effect(True) helpers.standard_test(self, gs.build_matlab, 'm') self.check_call(mock_check_output, ['-nosplash', '-minimize', '-wait'])
def test_unix(self, mock_copy, mock_check_output): ''' Test that build_matlab() creates a log and properly submits a matlab system command on a Unix machine. ''' # Mock copy so that it just creates the destination file mock_copy.side_effect = fx.matlab_copy_effect mock_check_output.side_effect = fx.make_matlab_side_effect(True) helpers.standard_test(self, gs.build_matlab, 'm') self.check_call(mock_check_output, ['-nosplash', '-nodesktop'])
def test_default(self, mock_system): ''' Test that build_lyx() behaves correctly when provided with standard inputs. ''' mock_system.side_effect = fx.lyx_side_effect target = './build/lyx.pdf' helpers.standard_test(self, gs.build_lyx, 'lyx', system_mock = mock_system, target = target) self.assertTrue(os.path.isfile(target))
def test_unix(self, mock_check, mock_path): '''Test build_stata()'s standard behaviour on Unix machines''' mock_check.side_effect = fx.make_stata_side_effect('stata-mp') # Mock is_in_path() to finds just one executable of Stata mock_path.side_effect = fx.make_stata_path_effect('stata-mp') env = {'stata_executable': None} helpers.standard_test(self, gs.build_stata, 'do', env=env, system_mock=mock_check)
def test_no_executable(self, mock_check_output): ''' Check build_r()'s behaviour when R is not recognised as an executable. ''' mock_check_output.side_effect = \ fx.make_r_side_effect(recognized = False) with self.assertRaises(ExecCallError): helpers.standard_test(self, gs.build_r, 'R', system_mock=mock_check_output)
def test_list_arguments(self, mock_system): ''' Check that build_lyx() works when its source and target arguments are lists ''' mock_system.side_effect = fx.lyx_side_effect target = ['./build/lyx.pdf'] helpers.standard_test(self, gs.build_lyx, 'lyx', system_mock = mock_system, source = ['./test_script.lyx'], target = target) self.assertTrue(os.path.isfile(target[0]))
def test_standard(self, mock_check_output): '''Test build_r()'s behaviour when given standard inputs.''' mock_check_output.side_effect = fx.make_r_side_effect(True) helpers.standard_test(self, gs.build_r, 'R', system_mock=mock_check_output) # With a list of targets targets = ['./test_output.txt'] helpers.standard_test(self, gs.build_r, 'R', system_mock=mock_check_output, target=targets)
def test_clarg(self, mock_copy, mock_check_output): ''' Test that build_matlab() properly sets command-line arguments in its env argument as system environment variables. ''' mock_copy.side_effect = fx.matlab_copy_effect mock_check_output.side_effect = fx.make_matlab_side_effect(True) env = {'CL_ARG': 'COMMANDLINE'} helpers.standard_test(self, gs.build_matlab, 'm', system_mock=mock_check_output, env=env) self.assertEqual(os.environ['CL_ARG'], env['CL_ARG'])
def test_windows(self, mock_is_64, mock_check, mock_path): ''' Test that build_stata() behaves correctly on a Windows machine when given appropriate inputs. ''' mock_check.side_effect = fx.make_stata_side_effect('StataMP-64.exe') mock_path.side_effect = fx.make_stata_path_effect('StataMP-64.exe') mock_is_64.return_value = False env = {'stata_executable': None} helpers.standard_test(self, gs.build_stata, 'do', env=env, system_mock=mock_check)