-
Notifications
You must be signed in to change notification settings - Fork 48
The SuiteRule class
Bryan Oakley edited this page Jan 5, 2015
·
5 revisions
The SuiteRule class is an abstract class that should be inherited by all rules that operate on a Suite. When the rule is applied (ie: the apply method is called), an instance of the Suite will be passed as a parameter. The class has an attribute named severity which defines the severity of the rule. The default severity is WARNING but may be overridden in the concrete class.
Every class that inherits from this class must define a method named apply. This method must take exactly one parameter, a Suite object.
For example, here is a suite rule that that checks for duplicate test names:
from rflint.common import SuiteRule, ERROR
def normalize_name(string):
'''convert to lowercase, remove spaces and underscores'''
return string.replace(" ", "").replace("_", "").lower()
class DuplicateTestNames(SuiteRule):
'''Verify that no tests have a name of an existing test in the same suite'''
severity = ERROR
def apply(self, suite):
cache = []
for testcase in suite.testcases:
# normalize the name, so we catch things like
# Smoke Test vs Smoke_Test, vs SmokeTest, which
# robot thinks are all the same
name = normalize_name(testcase.name)
if name in cache:
self.report(suite, "Duplicate testcase name '%s'" % testcase.name, testcase.linenumber)
cache.append(name)