Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@monitors.name("A Test")
def test_with_name(self):
pass
# Child Suites
# ----------------------------------
class BaseChildSuite(MonitorSuite):
monitors = [
UnnamedMonitor,
NamedMonitor,
("Instance Monitor", UnnamedMonitor),
("Instance Monitor", NamedMonitor),
]
class ChildUnnamedSuite(BaseChildSuite):
pass
@monitors.name("The Child Suite")
class ChildNamedSuite(BaseChildSuite):
pass
# ----------------------------------
# Top Suites
# ----------------------------------
class BaseTopSuite(MonitorSuite):
monitors = [
ChildUnnamedSuite,
ChildNamedSuite,
("Instance Suite Name", ChildUnnamedSuite),
("Instance Suite Name", ChildNamedSuite),
]
@monitors.name("No item validation errors")
def test_no_item_validation_errors(self):
validation_errors = getattr(
self.data.stats, "spidermon/validation/fields/errors", 0
)
self.assertEqual(
validation_errors,
0,
msg="Found validation errors in {} fields".format(validation_errors),
)
self.data.stats
@monitors.name('New items')
@monitors.level.low
def test_new_items(self):
"""Checks how many extracted items were new ones."""
pass
@monitors.name("Maximum number of errors exceeded")
def test_number_of_errors(self):
accepted_num_errors = 20
num_errors = self.data.stats.get("log_count/ERROR", 0)
msg = "The job has exceeded the maximum number of errors"
self.assertLessEqual(num_errors, accepted_num_errors, msg=msg)
@monitors.name("Should not have more item validation errors than configured.")
def test_verify_item_validation_error(self):
errors_threshold = self.crawler.settings.getint(
SPIDERMON_MAX_ITEM_VALIDATION_ERRORS, 0
)
item_validation_errors = self.stats.get("spidermon/validation/fields/errors", 0)
msg = "Found {} item validation error. Max allowed is {}.".format(
item_validation_errors, errors_threshold
)
self.assertTrue(item_validation_errors <= errors_threshold, msg=msg)
@monitors.name("Should extract the minimum amount of items")
def test_minimum_number_of_items(self):
item_extracted = getattr(self.stats, "item_scraped_count", 0)
msg = "Extracted {} items, the expected minimum is {}".format(
item_extracted, self.minimum_threshold
)
self.assertTrue(item_extracted >= self.minimum_threshold, msg=msg)