Stanislaw and I have had a long discussion on IRC today. We have agreed
on a new interface to the test (a. k. a. check) object to be a bunch of
properties and a single run() method. Compared to today, it means that
the is_applicable() function is no more part of the interface. Instead,
run() returns 'not_applicable' as needed.
Unfortunately, we have designed two ways to implement this in the python
context: one based on inheritance, and one based on decorators. Noone of
us sees it as a major problem to select any solution, but we must
decide. And needs some input.
First method is based on inheritance.
-------------------------------------------------
CheckBase:
def run(self):
if self.is_applicable():
self.run_if_applicable()
else:
self.set_passed('not_applicable')
JavaCheckBase(CheckBase):
def is_applicable(self):
if self.has_files("*.jar") or self.has_files("*.pom"):
return True
else:
return False
A standard test overrides .run_if_applicable(), which only is called if
is_applicable() is true.
def run_if_applicable(self):
name = self.get_files_by_pattern("/usr/share/javadoc/%s" %
self.spec.name)
....
self.set_passed('pass')
A test which needs to specify if it's applicable or not can do so by
overriding is_applicable as
today or, more straight-forward, by overriding run()
def run(self):
if not self.has_files("*.pom"):
self.set_passed('not_applicable')
return
...
self.set_passed( "pass")
The other way is based on decorators:
-----------------------------------------------------
CheckBase:
def run(self):
self.set_passed('inconclusive')
JavaCheckBase(CheckBase):
@staticmethod
def if_javapackage(run_f):
def wrapper(self, *args, **kwargs):
if self.has_files("*.jar") or self.has_files("*.pom"):
return run_f(self, *args, **kwargs)
else:
self.set_passed('not_applicable')
return wrapper
A standard test uses a decorator to run as applicable:
@JavaCheckBase.if_javapackage
def run(self):
files = self.get_files_by_pattern("/usr/share/javadoc/%s/*.html" %
self.spec.name)
....
self.set_passed(...)
but can instead choose to handle applicability itself:
def run(self):
if not self.spec.find(self.skip_regex):
self.set_passed('not_applicable')
return
......
self.set_passed(....)
------------------------------------------------------------------
Both methods have their pros and cons. We really need some input to
select a way of doing this. Anyone, out there?
On behalf of Stan
--alec