geoDSS.tests.unit_test module
# -*- coding: utf-8 -*- from ..tests.test import test class unit_test(test): ''' This test provides sort of a unit test. Definition ---------- definition is expected to be a dict having at least: `report_template` (string): String to be reported when the test is True. Rule example ------------ a useful yaml snippet for this test would be: rules: test123: type: tests.unit_test title: unit test description: unit test testing report_template: Test evaluated to True, so probably some action is reported here Subject example --------------- a useful subject for this would be: subject = {'result': True} ''' def execute(self, subject): ''' Executes the test. `subject` is expected a dict having: `result` (bool): the intended result of the test ''' self.logger.debug('Result asked: %s' % subject['result']) if subject['result']: self.result.append(self.definition["report_template"]) self.decision = True else: self.result.append("Expected key 'result' was not found in subject.") self.executed = True return self._finish_execution(subject)
Classes
class unit_test
This test provides sort of a unit test.
Definition
definition is expected to be a dict having at least:
report_template
(string): String to be reported when the test is True.
Rule example
a useful yaml snippet for this test would be:
rules: test123: type: tests.unit_test title: unit test description: unit test testing report_template: Test evaluated to True, so probably some action is reported here
Subject example
a useful subject for this would be:
subject = {'result': True}
class unit_test(test): ''' This test provides sort of a unit test. Definition ---------- definition is expected to be a dict having at least: `report_template` (string): String to be reported when the test is True. Rule example ------------ a useful yaml snippet for this test would be: rules: test123: type: tests.unit_test title: unit test description: unit test testing report_template: Test evaluated to True, so probably some action is reported here Subject example --------------- a useful subject for this would be: subject = {'result': True} ''' def execute(self, subject): ''' Executes the test. `subject` is expected a dict having: `result` (bool): the intended result of the test ''' self.logger.debug('Result asked: %s' % subject['result']) if subject['result']: self.result.append(self.definition["report_template"]) self.decision = True else: self.result.append("Expected key 'result' was not found in subject.") self.executed = True return self._finish_execution(subject)
Ancestors (in MRO)
- unit_test
- geoDSS.tests.test.test
- __builtin__.object
Methods
def __init__(
self, name, definition, logger, rules, settings=None)
def __init__(self, name, definition, logger, rules, settings = None): self.name = name self.definition = definition self.decision = False self.result = [] self.executed = False self.logger = logger self.rules = rules # this is an object with references to executed rules eg. self.rules.rule_1 if not 'break_on_error' in self.definition: self.definition['break_on_error'] = False if not 'report' in self.definition: self.definition['report'] = True if settings: for key, value in settings.items(): if not key in self.definition: self.definition[key] = value
def execute(
self, subject)
Executes the test.
subject
is expected a dict having:
result
(bool): the intended result of the test
def execute(self, subject): ''' Executes the test. `subject` is expected a dict having: `result` (bool): the intended result of the test ''' self.logger.debug('Result asked: %s' % subject['result']) if subject['result']: self.result.append(self.definition["report_template"]) self.decision = True else: self.result.append("Expected key 'result' was not found in subject.") self.executed = True return self._finish_execution(subject)