How to use the spidermon.exceptions.InvalidMonitor 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_suites.py View on Github external
SuiteDefinition(EmptySuite, [("S", Suite04)], 13),
]
INVALID_SUITE_DEFINITION_NON_ITERABLE = SuiteDefinition(EmptySuite, 10)
INVALID_SUITE_DEFINITION_NONE = SuiteDefinition(EmptySuite, [None])
INVALID_SUITE_DEFINITION_NUMBER = SuiteDefinition(EmptySuite, [10])
INVALID_SUITE_DEFINITION_CLASS = SuiteDefinition(EmptySuite, [object])
INVALID_SUITE_DEFINITION_TUPLE1 = SuiteDefinition(EmptySuite, [(1,)])
INVALID_SUITE_DEFINITION_TUPLE3 = SuiteDefinition(EmptySuite, [(1, 2, 3)])
INVALID_SUITE_DEFINITION_TUPLE2_WRONG1 = SuiteDefinition(EmptySuite, [(1, 2)])
INVALID_SUITE_DEFINITION_TUPLE2_WRONG2 = SuiteDefinition(EmptySuite, [("A", 2)])

INVALID_SUITE_DEFINITIONS = [
    # --------------------------------------------------------------
    # definition                                raises
    # --------------------------------------------------------------
    (INVALID_SUITE_DEFINITION_NONE, InvalidMonitor),
    (INVALID_SUITE_DEFINITION_NUMBER, InvalidMonitor),
    (INVALID_SUITE_DEFINITION_CLASS, InvalidMonitorClass),
    (INVALID_SUITE_DEFINITION_TUPLE1, InvalidMonitorTuple),
    (INVALID_SUITE_DEFINITION_TUPLE3, InvalidMonitorTuple),
    (INVALID_SUITE_DEFINITION_TUPLE2_WRONG1, InvalidMonitorTuple),
    (INVALID_SUITE_DEFINITION_TUPLE2_WRONG2, InvalidMonitor),
]


def test_creation_error_non_iterable():
    with pytest.raises(InvalidMonitorIterable):
        _test_creation_from_init(INVALID_SUITE_DEFINITION_NON_ITERABLE)
    with pytest.raises(InvalidMonitorIterable):
        _test_creation_from_add_monitors(INVALID_SUITE_DEFINITION_NON_ITERABLE)
github scrapinghub / spidermon / tests / test_loaders.py View on Github external
def test_loading_errors(loader):
    with pytest.raises(InvalidMonitor):
        loader.load_suite_from_monitor(None)
    with pytest.raises(InvalidMonitor):
        loader.load_suite_from_monitor(10)
    with pytest.raises(InvalidMonitor):
        loader.load_suite_from_monitor(object)
github scrapinghub / spidermon / spidermon / core / factories.py View on Github external
def raise_invalid_action(cls):
        raise Exception
        raise InvalidMonitor(
            "Wrong Monitor definition, it should be:\n"
            "- an instance of a Monitor/MonitorSuite object.\n"
github scrapinghub / spidermon / spidermon / exceptions.py View on Github external
pass


class NotAllowedMethod(SpidermonException):
    pass


class InvalidMonitor(SpidermonException):
    pass


class InvalidMonitorIterable(InvalidMonitor):
    pass


class InvalidMonitorClass(InvalidMonitor):
    pass


class InvalidMonitorTuple(InvalidMonitor):
    pass


class InvalidExpression(SpidermonException):
    pass


class InvalidResult(SpidermonException):
    pass


class NotConfigured(SpidermonException):
github scrapinghub / spidermon / spidermon / loaders.py View on Github external
def load_suite_from_monitor(self, monitor_class, name=None):
        if not (inspect.isclass(monitor_class) and issubclass(monitor_class, Monitor)):
            raise InvalidMonitor("monitor must be a class subclassing Monitor")
        test_function_names = self.get_testcase_names(monitor_class)
        if not test_function_names and hasattr(monitor_class, "runTest"):
            test_function_names = ["runTest"]
        monitors = [
            monitor_class(fn_name, name=name) for fn_name in test_function_names
        ]
        loaded_suite = MonitorSuite(
            monitors=monitors, order=monitor_class.options.order
        )
        return loaded_suite
github scrapinghub / spidermon / spidermon / python / factory.py View on Github external
def _create_monitor_class(expressions, monitor_class=None):
    monitor_class = monitor_class or PythonExpressionsMonitor
    if not issubclass(monitor_class, PythonExpressionsMonitor):
        msg = "Python expressions monitors must subclass PythonExpressionsMonitor"
        raise InvalidMonitor(msg)
    klass = type(monitor_class.generate_class_name(), (monitor_class,), {})
    for e in expressions:
        if isinstance(e, tuple):
            method = _create_test_method(*e)
        else:
            method = _create_test_method(e)
        setattr(klass, monitor_class.generate_method_name(), method)
    return klass
github scrapinghub / spidermon / spidermon / exceptions.py View on Github external
pass


class InvalidDataOperation(SpidermonException):
    pass


class NotAllowedMethod(SpidermonException):
    pass


class InvalidMonitor(SpidermonException):
    pass


class InvalidMonitorIterable(InvalidMonitor):
    pass


class InvalidMonitorClass(InvalidMonitor):
    pass


class InvalidMonitorTuple(InvalidMonitor):
    pass


class InvalidExpression(SpidermonException):
    pass


class InvalidResult(SpidermonException):
github scrapinghub / spidermon / spidermon / core / factories.py View on Github external
def raise_invalid_monitor(cls):
        raise InvalidMonitor(
            "Wrong Monitor definition, it should be:\n"
            "- an instance of a Monitor/MonitorSuite object.\n"
github scrapinghub / spidermon / spidermon / exceptions.py View on Github external
pass


class InvalidMonitor(SpidermonException):
    pass


class InvalidMonitorIterable(InvalidMonitor):
    pass


class InvalidMonitorClass(InvalidMonitor):
    pass


class InvalidMonitorTuple(InvalidMonitor):
    pass


class InvalidExpression(SpidermonException):
    pass


class InvalidResult(SpidermonException):
    pass


class NotConfigured(SpidermonException):
    pass


class SkipAction(SpidermonException):