def test_run_pass(self): """Test run with passing config.""" with open(os.devnull, "w") as fd: checker = PolicyChecker(self.p, "tests/checker/checker-valid.ini") # create additional disabled mock test newcheck = Mock() newcheck.checkname = "disabled" newcheck.disable = True newcheck.validate_config.return_value = None newcheck.run.return_value = [] checker.checks.append(newcheck) self.assertEqual(4, len(checker.checks)) result = checker.run(output=fd) self.assertEqual(0, result) newcheck.run.assert_not_called()
def test_run_fail(self): """Test run with failing config.""" with open(os.devnull, "w") as fd: checker = PolicyChecker(self.p, "tests/checker/checker-valid.ini") # create additional failing mock test newcheck = Mock() newcheck.checkname = "failing test" newcheck.disable = False newcheck.validate_config.return_value = None newcheck.run.return_value = list(range(13)) checker.checks.append(newcheck) self.assertEqual(4, len(checker.checks)) result = checker.run(output=fd) newcheck.run.assert_called() self.assertEqual(13, result)
def test_config_check_invalid_value(self): """Test check invalid check type""" with self.assertRaises(InvalidCheckValue): PolicyChecker(self.p, "tests/checker/checker-invalidvalue.ini")
def test_config_check_invalid_option(self): """Test check invalid check option""" with self.assertRaises(InvalidCheckOption): PolicyChecker(self.p, "tests/checker/checker-invalidoption.ini")
def test_config_check_missing_type(self): """Test check missing check type""" with self.assertRaises(InvalidCheckerModule): PolicyChecker(self.p, "tests/checker/checker-missingtype.ini")
def test_config_empty(self): """Test empty config file""" with self.assertRaises(InvalidCheckerConfig): PolicyChecker(self.p, "/dev/null")