Files
Charly Delay c53730d781 gnathub: introduce Runner & Reporter interface
The GNAThub.Plugin class is no longer an abstract class and
GNAThub.Runner & GNAThub.Reporter are two new interfaces exposing
respectively run() and report(). Plugins now have tools execution
done in run() methods, and results collection done in report() methods
(when it make sense for the plugin, ie. coverage plugins only implement
the GNAThub.Reporter interface whereas eg. CodePeer plugin implements
both GNAThub.Runner and GNAThub.Reporter interfaces).

Change-Id: Ic702a98eb3bb02e7f7416b5ff3c998f9b20eaefc
TN: P720-035
2017-01-18 16:04:50 -05:00

91 lines
2.4 KiB
Python

"""Check the integrity of the GNAThub Python module."""
import GNAThub
from support.asserts import assertEqual, assertRaises
# Global variables supposedly updated by MyCustomPlugin
MY_RUN_VARIABLE = False
MY_REPORT_VARIABLE = False
class MyIncompleteRunnerPlugin(GNAThub.Plugin, GNAThub.Runner):
"""Declare a custom plugin that extends the GNAThub Plugin interface.
However, do not implement the RUN method to test error case.
"""
name = 'My Incomplete Plugin'
class MyIncompleteReporterPlugin(GNAThub.Plugin, GNAThub.Reporter):
"""Declare a custom plugin that extends the GNAThub Plugin interface.
However, do not implement the REPORT method to test error case.
"""
name = 'My Incomplete Plugin'
class MyCustomReporterPlugin(GNAThub.Plugin, GNAThub.Reporter):
"""Declare a custom plugin that extends the GNAThub reporter interface."""
name = 'My Custom Plugin'
def report(self):
"""Overridden."""
pass
class MyCustomRunnerPlugin(GNAThub.Plugin, GNAThub.Runner):
"""Declare a custom plugin that extends the GNAThub runner interface."""
name = 'My Custom Plugin'
def run(self):
"""Overridden."""
pass
class MyCustomPlugin(GNAThub.Plugin, GNAThub.Runner, GNAThub.Reporter):
"""Declare a custom plugin that extends the GNAThub Plugin interface."""
name = 'My Custom Plugin'
def run(self):
"""Overridden."""
global MY_RUN_VARIABLE
MY_RUN_VARIABLE = True
def report(self):
"""Overridden."""
global MY_REPORT_VARIABLE
MY_REPORT_VARIABLE = True
# GNAThub.Runner interface not implemented
with assertRaises(TypeError):
# A type error occurs when the RUN method is not overridden
MyIncompleteRunnerPlugin()
# GNAThub.Reporter interface not implemented
with assertRaises(TypeError):
# A type error occurs when the REPORT method is not overridden
MyIncompleteReporterPlugin()
MyCustomRunnerPlugin() # Fails if it raises an exception
MyCustomReporterPlugin() # Fails if it raises an exception
PLUGIN = MyCustomPlugin()
# GNAThub.Plugin.name
assertEqual(PLUGIN.name, 'My Custom Plugin')
# GNAThub.Plugin.exec_status (getter)
assertEqual(PLUGIN.exec_status, GNAThub.NOT_EXECUTED)
# GNAThub.Plugin.exec_status (setter)
with assertRaises(GNAThub.Error):
PLUGIN.exec_status = 'invalid value'
PLUGIN.exec_status = GNAThub.EXEC_SUCCESS