table_repr – Transform test results into TableTemplate

Module containing all available methods to convert a test result in a table to be converted in rst.

valjean.javert.table_repr.repr_bins(dsref)[source]

Representation of bins in tables.

When bins are given by edges, representation is min - max, when they are given at center, representation is center.

Trivial dimensions are not represented, i.e. dimensions where there is only one bin.

If there are more than one non-trivial dimensions, some repetition is expected. For example with two non-trivial dimensions of two bins each one point will be defined by its coordinated in the two dimensions and we expect all the bins to possibily be shown in a table. We expected 4 bins and their associated values in that case.

Let’s consider the following dataset: >>> from valjean.eponine.dataset import Dataset >>> import numpy as np >>> from collections import OrderedDict

>>> vals = np.arange(6).reshape(1, 2, 1, 3, 1)
>>> errs = np.array([0.1]*6).reshape(1, 2, 1, 3, 1)
>>> bins = OrderedDict([('bacon', np.array([0, 1])),
...                     ('egg', np.array([0, 2, 4])),
...                     ('sausage', np.array([10, 20])),
...                     ('spam', np.array([-5, 0, 5])),
...                     ('tomato', np.array([-2, 2]))])
>>> ds = Dataset(vals, errs, bins=bins)
>>> names, rbins = repr_bins(ds)
>>> print(list(ds.bins.keys()))
['bacon', 'egg', 'sausage', 'spam', 'tomato']
>>> print(names)
['egg', 'spam']
>>> print(ds.shape)
(1, 2, 1, 3, 1)
>>> print([rb.shape for rb in rbins])
[(1, 2, 1, 3, 1), (1, 2, 1, 3, 1)]

'bacon' and 'sausage' are trivial dimensions, so won’t be represented in the table, but we expect 6 values corresponding to 2 bins in 'egg' and 3 in 'spam'. Each value corresponds to a line in the table so each columns should have the same size and the same shape, the shape of the given dataset without trivial dimensions. We then have 3 'spam' bins in each 'egg' bins or 2 'egg' bins in each 'spam' bins. Each couple appears only once.

>>> for name, rbin in zip(names, rbins):
...     print(name, ':', rbin.flatten())
egg : ['0 - 2' '0 - 2' '0 - 2' '2 - 4' '2 - 4' '2 - 4']
spam : ['-5' '0' '5' '-5' '0' '5']

As expected from the bins, 'egg' bins are given by edges (min - max) while 'spam' bins are given by center (center).

Parameters:

dsref (Dataset) – dataset

Returns:

list of the non-trivial dimensions and a tuple of the bins

Return type:

(list(str), tuple(numpy.ndarray))

The tuple must have the same length as the list of dimensions and the bins inside must have the same shape as dsref.value.

valjean.javert.table_repr.repr_testresultequal(result, verbosity=Verbosity.DEFAULT)[source]

Represent the result of a TestEqual test.

Parameters:
Returns:

list of templates representing a TestResultEqual

valjean.javert.table_repr.repr_equal_summary(result)[source]

Function to generate a summary table for the equal test (only tells if the test was successful or not).

Parameters:

result (TestResultEqual) – a test result.

Return type:

list(TextTemplate)

valjean.javert.table_repr.repr_equal(result)[source]

Representation of equal test.

Parameters:

result (TestResultEqual) – a test result.

Returns:

Representation of a TestResultEqual as a table.

Return type:

list(TableTemplate)

valjean.javert.table_repr.repr_testresultapproxequal(result, verbosity=Verbosity.DEFAULT)[source]

Represent the result of a TestApproxEqual test.

Parameters:
Returns:

list of templates representing a TestResultApproxEqual

valjean.javert.table_repr.repr_approx_equal_summary(result)[source]

Function to generate a summary table for the approx equal test (only tells if the test was successful or not).

Parameters:

result (TestResultApproxEqual) – a test result.

Return type:

list(TextTemplate)

valjean.javert.table_repr.repr_approx_equal(result)[source]

Representation of approx equal test.

Parameters:

result (TestResultApproxEqual) – a test result.

Returns:

Representation of a TestResultApproxEqual as a table.

Return type:

list(TableTemplate)

valjean.javert.table_repr.repr_testresultstudent(result, verbosity=Verbosity.DEFAULT)[source]

Represent the result of a TestStudent test.

Parameters:
Returns:

list of templates representing a TestResultStudent

valjean.javert.table_repr.repr_student(result)[source]

Representation of Student test result.

Parameters:

result (TestResultStudent) – a test result.

Returns:

Representation of a TestResultStudent as a table.

Return type:

list(TableTemplate)

valjean.javert.table_repr.repr_student_silent(_result)[source]

Function to generate a silent table for the Student test (only tells if the test was successful or not).

Parameters:

result (TestResultStudent) – a Student test result.

Returns:

empty list

valjean.javert.table_repr.repr_student_summary(result)[source]

Function to generate a summary table for the Student test (only tells if the test was successful or not).

Parameters:

result (TestResultStudent) – a Student test result.

Return type:

list(TextTemplate)

valjean.javert.table_repr.repr_student_intermediate(result)[source]

Function to generate an intermediate table for the Student test: print all the failing results.

Parameters:

result (TestResultStudent) – a Student test result.

Return type:

list(TableTemplate)

valjean.javert.table_repr.repr_testresultbonferroni(result, verbosity=Verbosity.DEFAULT)[source]

Represent the result of a TestBonferroni test.

Only represents the Bonferroni result, not the input test result.

Parameters:
Returns:

list of templates representing a TestResultBonferroni

valjean.javert.table_repr.repr_bonferroni(result)[source]

Reprensetation of Bonferroni test result.

Only represents the Bonferroni result, not the input test result.

Parameters:

result (TestResultBonferroni) – a test result.

Returns:

Representation of a TestResultBonferroni as a table.

Return type:

list(TableTemplate)

valjean.javert.table_repr.repr_bonferroni_summary(result)[source]

Represent the result of a TestBonferroni test for the SUMMARY level of verbosity.

Parameters:

result (TestResultBonferroni) – a test result.

Returns:

Representation of a TestResultBonferroni as a table.

Return type:

list(TextTemplate)

valjean.javert.table_repr.repr_testresultholmbonferroni(result, verbosity=Verbosity.DEFAULT)[source]

Represent the result of a TestHolmBonferroni test.

Parameters:
Returns:

list of templates representing a TestResultHolmBonferroni

valjean.javert.table_repr.repr_holm_bonferroni(result)[source]

Reprensetation of Holm-Bonferroni test result.

Only represents the Holm-Bonferroni result, not the input test result.

Parameters:

result (TestResultHolmBonferroni) – a test result.

Returns:

Representation of a TestResultHolmBonferroni as a table.

Return type:

list(TableTemplate)

valjean.javert.table_repr.repr_holm_bonferroni_summary(result)[source]

Represent the result of a TestHolmBonferroni test for the SUMMARY level of verbosity.

Parameters:

result (TestResultHolmBonferroni) – a test result.

Returns:

Representation of a TestResultHolmBonferroni as a table.

Return type:

list(TextTemplate)

valjean.javert.table_repr.percent_fmt(num, den)[source]

Format a fraction as a percentage. Example:

>>> percent_fmt(2, 4)
'2/4 (50.0%)'
>>> percent_fmt(0, 3)
'0/3 (0.0%)'
>>> percent_fmt(7, 7)
'7/7 (100.0%)'
>>> percent_fmt(0, 0)
'0/0 (???%)'
Parameters:
  • num (int) – the numerator.

  • den (int) – the denominator.

Return type:

str

valjean.javert.table_repr.repr_testresultstatstasks(result, verbosity=Verbosity.DEFAULT)[source]

Represent a TestResultStatsTasks as a table. The table breaks down the tasks by status.

Parameters:
Returns:

list of templates representing the test result.

valjean.javert.table_repr.repr_testresultstatstests(result, verbosity=Verbosity.DEFAULT)[source]

Represent a TestResultStatsTests as a table. The table breaks down the tests by success status.

Parameters:
Returns:

the tables representing the test result.

Return type:

list(TableTemplate)

valjean.javert.table_repr.repr_testresultstats(result, status_ok, label)[source]

Helper function for repr_testresultstatstests and repr_testresultstatstasks. It generates a table with the status_ok value in the first row. Non-null results in other rows are considered as failures, and are highlighted if the count is non-zero. Null results are omitted from the table.

Parameters:
  • result (TestResultStatsTasks or TestResultStatsTests) – the test result to represent.

  • status_ok – the status value that must be considered as a success.

  • label (str) – the type of things that we are testing ('tests' or 'tasks')

Returns:

the tables representing the test result.

Return type:

list(TableTemplate)

valjean.javert.table_repr.repr_testresultstatstestsbylabels(result, verbosity=Verbosity.DEFAULT)[source]

Represent a TestResultStatsTestsByLabels as tables. Shape of the table may change according to the number of flags required.

Parameters:
Returns:

the tables representing the test result.

Return type:

list(TableTemplate)

valjean.javert.table_repr.repr_testresultstatsbylabels(result)[source]

Function to print detailed statistics on tests, per category and sample run.

Parameters:

result (TestResultStatsTestsByLabels) – the test result to represent.

Returns:

the tables representing the test result.

Return type:

list(TableTemplate)

valjean.javert.table_repr.repr_testresultstatsbylabels_summary(result)[source]

Function to print detailed statistics on tests, per category and sample run in summary case: only print failed cases.

Parameters:

result (TestResultStatsTestsByLabels) – the test result to represent.

Returns:

the tables representing the test result.

Return type:

list(TableTemplate), list(TextTemplate)

valjean.javert.table_repr.repr_testresultmetadata(result, verbosity=Verbosity.DEFAULT)[source]

Represent the result of a TestMetadata test.

Parameters:
Returns:

list of templates representing a TestResultMetadata

valjean.javert.table_repr.repr_metadata(result)[source]

Function to generate a table from the metadata test results.

Parameters:

result (TestResultMetadata) – a test result.

Return type:

list(TableTemplate)

valjean.javert.table_repr.repr_metadata_full_details(result)[source]

Function to generate a table from the metadata test results.

Parameters:

result (TestResultMetadata) – a test result.

Return type:

list(TableTemplate)

valjean.javert.table_repr.repr_metadata_intermediate(result)[source]

Function to generate a table from the metadata test results.

Parameters:

result (TestResultMetadata) – a test result.

Return type:

list(TableTemplate)

valjean.javert.table_repr.repr_metadata_summary(result)[source]

Function to generate a table from the metadata test results.

Parameters:

result (TestResultMetadata) – a test result.

Return type:

list(TextTemplate)

valjean.javert.table_repr.repr_metadata_silent(_result)[source]

Function to generate a table from the metadata test results.

Parameters:

result (TestResultMetadata) – a test result.

Returns:

empty list

valjean.javert.table_repr.repr_testresultexternal(_result, _verbosity=Verbosity.DEFAULT)[source]

Represent external test as tables -> no table done.

If tables are required they are already done. Their representation in the report is done by ExternalRepresenter.

Returns:

empty list

valjean.javert.table_repr.repr_testresultfailed(result, _verbosity=Verbosity.DEFAULT)[source]

Represent a failed result as rst text.

Parameters:

result (TestResultFailed) – a failed test result.

Return type:

list(TextTemplate)