representation
– Transform test results into items
This module contains code that converts a test result into some kind of human-readable representation (table, plots, etc.).
Todo
Possible improvement: turn Representer
into an ABC; loop over
the classes in eponine
that inherit from :class:`~.TestResult
and add @abstractmethod methods in Representer
. This way, if
a new TestResult
is added to eponine
, it will no longer
be possible to instantiate any of the classes that derive from
Representer
, pointing to the fact that the code in this module
needs to be extended to handle the new class. This is better than silently
falling back to some default do-nothing implementation, which may lead to
bugs.
This module uses the Strategy design pattern. The Representation
class plays the role of Context, Representer
plays the role of
Strategy and the classes derived from Representer
(such as
TableRepresenter
, PlotRepresenter
, etc.) play the role of
ConcreteStrategy. See E. Gamma et al., “Design Patterns” (1995),
ISBN 0-201-63361-2, Addison-Weasley, USA.
Currently we have 3 main Representer
classes:
Representer
: parent class of all others, containing the defaultRepresenter.__call__
method, calling the class method named'repr_' + class.name
of the test;TableRepresenter
: inherited fromRepresenter
, designed as a parent class for user’s own representations of tables. ItsTableRepresenter.__call__
method first looks for a method called'repr_' + class.name
; if it does not exist call the default method from the catalogue of table representation accessible intable_repr
;PlotRepresenter
: inherited fromRepresenter
, designed as a parent class for user’s own representations of plots. ItsPlotRepresenter.__call__
method first looks for a method called'repr_' + class.name
; if it does not exist call the default method from the catalogue of plot representation accessible inplot_repr
.
An example of use of the Representer
objects can be seen in the
FullTableRepresenter
. In this table representation, for the Bonferroni
test result, the input test result is first represented in a table, then the
Bonferroni itself is represented in a second table.
Thus the use of the Representer
is foreseen as:
use the default methods provided in
TableRepresenter
andPlotRepresenter
;if customisation is needed, you can easily call the additional method available in
table_repr
andplot_repr
;you can also write your own representation method provided they follow the naming convention
'repr_' + class.name
;valjean
calls theRepresenter
classes through theRepresentation
class.
- class valjean.javert.representation.Representation(representer, verbosity=Verbosity.DEFAULT)[source]
Class for representing test results as templates calling the available representers (tables or plots).
This class corresponds to the Context role in the Strategy design pattern.
- __init__(representer, verbosity=Verbosity.DEFAULT)[source]
‘Initilialisation of the
Representation
class with the Representer to use.- Parameters:
Representer – representer to use (table, plots, both, etc)
- class valjean.javert.representation.Representer[source]
Base class for representing test results as templates (in the sense of the
templates
module).This class corresponds to the Strategy role in the Strategy design pattern. Its subclasses play the role of ConcreteStrategy.
- class valjean.javert.representation.ExternalRepresenter[source]
This class is the default representation class for external tests, i.e. tests defined by the users who already defined the test representation as templates.
- class valjean.javert.representation.TableRepresenter[source]
This class is the default representation class for tables. It contains the overridden
Representer.__call__
.Advice: users willing to customize the behaviour of TableRepresenter for specific test results should subclass TableRepresenter and define the relevant
repr_*
methods.
- class valjean.javert.representation.FullTableRepresenter[source]
Class to define the specific methods for full representation of tables. This only involve few cases needing the
TableRepresenter.__call__
method like in Bonferroni and Holm-Bonferroni test results.- repr_testresultbonferroni(result, verbosity=Verbosity.DEFAULT)[source]
Represent the result of a
TestBonferroni
test in two tables:First test result (Student, equal, etc)
Bonferroni test result
- Parameters:
result (TestResultBonferroni) – a test result.
- Returns:
Representation of a
TestResultBonferroni
as two tables (the first test result and the Bonferroni result).- Return type:
- repr_testresultholmbonferroni(result, verbosity=Verbosity.DEFAULT)[source]
Represent the result of a
TestHolmBonferroni
test in two tables:First test result (Student, equal, etc)
Holm-Bonferroni test result
- Parameters:
result (TestResultHolmBonferroni) – a test result.
- Returns:
Representation of a
TestResultHolmBonferroni
as two tables (the first test result and the Holm-Bonferroni result).- Return type:
- class valjean.javert.representation.PlotRepresenter(post='default')[source]
This class is the default representation class for plots. It contains the overridden
Representer.__call__
.Advice: users willing to customize the behaviour of
PlotRepresenter
for specific test results should subclassPlotRepresenter
and define the relevantrepr_*
methods.- __call__(result, verbosity=Verbosity.DEFAULT)[source]
Dispatch handling of result to the appropriate subclass method, based on the name of the class of result. This methods essentially implements a simplified, run-time version of the Visitor pattern.
- repr_testresultbonferroni(result, verbosity=Verbosity.DEFAULT)[source]
Represent the result of a
TestBonferroni
test one a plot (only the input test for the moment) (Student, equal, etc)- Parameters:
result (TestResultBonferroni) – a test result.
- Returns:
Representation of a
TestResultBonferroni
as a plot (the first test result).- Return type:
- repr_testresultholmbonferroni(result, verbosity=Verbosity.DEFAULT)[source]
Represent the result of a
TestHolmBonferroni
test as a plot (Student, equal, etc)- Parameters:
result (TestResultHolmBonferroni) – a test result.
- Returns:
Representation of a
TestResultHolmBonferroni
as a plot (the first test result).- Return type:
- class valjean.javert.representation.FullPlotRepresenter(post='default')[source]
Class to define the specific methods for full representation of plots. This only involve few cases needing the
PlotRepresenter.__call__
method like in Bonferroni and Holm-Bonferroni test results.- repr_testresultbonferroni(result, verbosity=Verbosity.DEFAULT)[source]
Represent the result of a
TestBonferroni
test one a plot (only the input test for the moment) (Student, equal, etc)- Parameters:
result (TestResultBonferroni) – a test result.
- Returns:
Representation of a
TestResultBonferroni
as a plot (the first test result).- Return type:
- repr_testresultholmbonferroni(result, verbosity=Verbosity.DEFAULT)[source]
Represent the result of a
TestHolmBonferroni
test as a plot (Student, equal, etc)- Parameters:
result (TestResultHolmBonferroni) – a test result.
- Returns:
Representation of a
TestResultHolmBonferroni
as a plot (the first test result).- Return type:
- class valjean.javert.representation.EmptyRepresenter[source]
Class that does not generate any templates for any test result.
- class valjean.javert.representation.FullRepresenter(post=<function post_treatment>)[source]
This class generates the fullest possible representation for test results. If anything can be represented as an template,
FullRepresenter
will do it.- __init__(post=<function post_treatment>)[source]
Initialisation of
FullRepresenter
.Two instance objects are built: a
FullTableRepresenter
and aPlotRepresenter
.
- __call__(result, verbosity=Verbosity.DEFAULT)[source]
Dispatch handling of result to all the Representer subclass instance attributes of
FullRepresenter
, based on the name of the class of result.If the representer does not exist in
table_repr
orplot_repr
aNone
is returned and replaced here by an empty list. If none of them exist the global return will be an empty list (noNone
returned from this step).