How to use the spidermon.settings.MONITOR function in spidermon

To help you get started, we’ve selected a few spidermon examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github scrapinghub / spidermon / tests / test_levels.py View on Github external
from __future__ import absolute_import
from spidermon import settings

from .fixtures.levels import *

HIGH = settings.MONITOR.LEVEL.HIGH
NORMAL = settings.MONITOR.LEVEL.NORMAL
LOW = settings.MONITOR.LEVEL.LOW


LEVEL_TESTS = [
    # ---------------------------------------------------------------------------------------
    # suite                     monitor/methods                                expected level
    # ---------------------------------------------------------------------------------------
    # Suite No Level
    (Suites.NoLevelSuite, Monitors.NoLevelMonitor.NoLevelMethod, NORMAL),
    (Suites.NoLevelSuite, Monitors.NoLevelMonitor.HighLevelMethod, HIGH),
    (Suites.NoLevelSuite, Monitors.NoLevelMonitor.NormalLevelMethod, NORMAL),
    (Suites.NoLevelSuite, Monitors.NoLevelMonitor.LowLevelMethod, LOW),
    (Suites.NoLevelSuite, Monitors.HighLevelMonitor.NoLevelMethod, HIGH),
    (Suites.NoLevelSuite, Monitors.HighLevelMonitor.HighLevelMethod, HIGH),
    (Suites.NoLevelSuite, Monitors.HighLevelMonitor.NormalLevelMethod, NORMAL),
github scrapinghub / spidermon / spidermon / core / monitors.py View on Github external
def level(self):
        return (
            self.method_level
            or self.monitor_level
            or self.parent_level
            or settings.MONITOR.LEVELS.DEFAULT
        )
github scrapinghub / spidermon / spidermon / results / text.py View on Github external
from __future__ import absolute_import
import sys

from spidermon import settings
from spidermon.utils.text import line_title

from .monitor import MonitorResult, monitors_step_required, actions_step_required


DOTS = {
    # Monitors
    settings.MONITOR.STATUS.SUCCESS: ".",
    settings.MONITOR.STATUS.ERROR: "E",
    settings.MONITOR.STATUS.FAILURE: "F",
    settings.MONITOR.STATUS.SKIPPED: "s",
    settings.MONITOR.STATUS.EXPECTED_FAILURE: "x",
    settings.MONITOR.STATUS.UNEXPECTED_SUCCESS: "u",
    # Actions
    settings.ACTION.STATUS.SUCCESS: ".",
    settings.ACTION.STATUS.ERROR: "E",
    settings.ACTION.STATUS.SKIPPED: "s",
}


class TextMonitorResult(MonitorResult):

    SEPARATOR_BOLD = "="
    SEPARATOR_LIGHT = "-"
    LINE_LENGTH = 70
github scrapinghub / spidermon / spidermon / results / steps.py View on Github external
for error_status in self.error_statuses:
            results += self.items_for_status(error_status)
        return results

    @property
    def successful(self):
        return not self.has_errors

    @property
    def has_errors(self):
        return len(self.error_results) > 0


class MonitorStep(Step):
    item_result_class = MonitorResult
    successful_statuses = settings.MONITOR.STATUSES.SUCCESSFUL
    error_statuses = settings.MONITOR.STATUSES.ERROR

    def get_infos(self):
        return {
            "failures": len(self.items_for_status(settings.MONITOR.STATUS.FAILURE)),
            "errors": len(self.items_for_status(settings.MONITOR.STATUS.ERROR)),
            "skipped": len(self.items_for_status(settings.MONITOR.STATUS.SKIPPED)),
            "expected failures": len(
                self.items_for_status(settings.MONITOR.STATUS.EXPECTED_FAILURE)
            ),
            "unexpected successes": len(
                self.items_for_status(settings.MONITOR.STATUS.UNEXPECTED_SUCCESS)
            ),
        }
github scrapinghub / spidermon / spidermon / decorators / monitors.py View on Github external
from __future__ import absolute_import
from spidermon.core.options import MonitorOptions
from spidermon import settings
from spidermon.decorators import OptionsDecorator, DecoratorWithAttributes


class LevelDecorator(DecoratorWithAttributes):
    name = "level"
    attributes = {
        "high": OptionsDecorator.set_fixed_value(
            MonitorOptions, name, settings.MONITOR.LEVEL.HIGH
        ),
        "normal": OptionsDecorator.set_fixed_value(
            MonitorOptions, name, settings.MONITOR.LEVEL.NORMAL
        ),
        "low": OptionsDecorator.set_fixed_value(
            MonitorOptions, name, settings.MONITOR.LEVEL.LOW
        ),
    }


name = OptionsDecorator.set_value(MonitorOptions, "name")
description = OptionsDecorator.set_value(MonitorOptions, "description")
order = OptionsDecorator.set_value(MonitorOptions, "order")
level = LevelDecorator()
github scrapinghub / spidermon / spidermon / results / monitor.py View on Github external
def addError(self, test, error):
        super(MonitorResult, self).addError(test, error)
        self.step[test].status = settings.MONITOR.STATUS.ERROR
        self.step[test].error = self._exc_info_to_string(error, test)
github scrapinghub / spidermon / spidermon / core / suites.py View on Github external
def parent_level(self):
        if self.parent:
            return self.parent.level
        return settings.MONITOR.LEVELS.DEFAULT
github scrapinghub / spidermon / spidermon / core / monitors.py View on Github external
def method_description(self):
        return (
            self.method.options.description
            or self.method.__func__.__doc__
            or settings.MONITOR.DEFAULT_DESCRIPTION
        )
github scrapinghub / spidermon / spidermon / results / text.py View on Github external
from __future__ import absolute_import
import sys

from spidermon import settings
from spidermon.utils.text import line_title

from .monitor import MonitorResult, monitors_step_required, actions_step_required


DOTS = {
    # Monitors
    settings.MONITOR.STATUS.SUCCESS: ".",
    settings.MONITOR.STATUS.ERROR: "E",
    settings.MONITOR.STATUS.FAILURE: "F",
    settings.MONITOR.STATUS.SKIPPED: "s",
    settings.MONITOR.STATUS.EXPECTED_FAILURE: "x",
    settings.MONITOR.STATUS.UNEXPECTED_SUCCESS: "u",
    # Actions
    settings.ACTION.STATUS.SUCCESS: ".",
    settings.ACTION.STATUS.ERROR: "E",
    settings.ACTION.STATUS.SKIPPED: "s",
}


class TextMonitorResult(MonitorResult):

    SEPARATOR_BOLD = "="
    SEPARATOR_LIGHT = "-"
github scrapinghub / spidermon / spidermon / python / factory.py View on Github external
def create_monitor_class_from_dict(monitor_dict, monitor_class=None):
    tests = []
    for test in monitor_dict.get("tests", []):
        tests.append(
            (
                test["expression"],
                test.get("name", None),
                test.get("description", None),
                test.get("fail_message", None),
            )
        )
    klass = _create_monitor_class(tests, monitor_class)
    klass.options.name = monitor_dict.get("name", settings.MONITOR.DEFAULT_NAME)
    klass.options.description = monitor_dict.get(
        "description", settings.MONITOR.DEFAULT_DESCRIPTION
    )
    return klass