def test_handle_analysis_failure(self): """Test that we properly handle an analysis script failing.""" check_test_health.run_prep_scripts(mox.IgnoreArg()).AndReturn(True) check_test_health.run_analysis_scripts( mox.IgnoreArg()).AndReturn(False) self.mox.ReplayAll() self.assertEqual(check_test_health.main(), 1)
def test_do_not_run_other_scripts_after_one_fails(self): """Test that the other prep scripts are not ran if one fails.""" scripts = [['script1.sh', 'arg'], ['script2.sh']] logging.info(mox.IgnoreArg(), mox.IgnoreArg()) subprocess.call(['script1.sh', 'arg']).AndReturn(1) logging.error(mox.IgnoreArg(), mox.IgnoreArg()) self.mox.ReplayAll() check_test_health.run_prep_scripts(scripts)
def test_given_scripts_are_called(self): """Test that all the scripts passed in are called when they pass.""" scripts = [['script1.sh', 'arg'], ['script2.sh']] logging.info(mox.IgnoreArg(), mox.IgnoreArg()) subprocess.call(['script1.sh', 'arg']).AndReturn(0) logging.info(mox.IgnoreArg(), mox.IgnoreArg()) subprocess.call(['script2.sh']).AndReturn(0) self.mox.ReplayAll() check_test_health.run_prep_scripts(scripts)
def test_script_information_logging(self): """Test that we log prep running and failure.""" scripts = [['pass.py'], ['fail.sh', 'arg']] logging.info('Running %s', 'pass.py') subprocess.call(['pass.py']).AndReturn(0) logging.info('Running %s', 'fail.sh arg') subprocess.call(['fail.sh', 'arg']).AndReturn(1) logging.error('\'%s\' failed with return code %d', ('fail.sh arg', 1)) self.mox.ReplayAll() check_test_health.run_prep_scripts(scripts)
def test_all_functions_called_if_there_are_no_errors(self): """Test that all the script calling functions are called by default.""" check_test_health.PREP_SCRIPTS = [['test_prep']] check_test_health.ANALYSIS_SCRIPTS = [['test_analysis']] check_test_health.run_prep_scripts( check_test_health.PREP_SCRIPTS).AndReturn(True) check_test_health.run_analysis_scripts( check_test_health.ANALYSIS_SCRIPTS).AndReturn(True) self.mox.ReplayAll() self.assertEqual(check_test_health.main(), 0)
def test_return_true_if_all_scripts_suceed(self): """Test that True is returned when all the scripts succeed.""" scripts = [['script.sh']] logging.info(mox.IgnoreArg(), mox.IgnoreArg()) subprocess.call(mox.IgnoreArg()).AndReturn(0) self.mox.ReplayAll() self.assertTrue(check_test_health.run_prep_scripts(scripts))
def test_return_false_if_script_fails(self): """Test that False is returned if a preparation step fails.""" scripts = [['script.sh']] logging.info(mox.IgnoreArg(), mox.IgnoreArg()) subprocess.call(mox.IgnoreArg()).AndReturn(1) logging.error(mox.IgnoreArg(), mox.IgnoreArg()) self.mox.ReplayAll() self.assertFalse(check_test_health.run_prep_scripts(scripts))