nnfwtbn.tests package

Submodules

nnfwtbn.tests.test_cut module

class nnfwtbn.tests.test_cut.CutTestCase(methodName='runTest')[source]

Bases: unittest.case.TestCase

Test the implementation of the cut class.

__module__ = 'nnfwtbn.tests.test_cut'
setUp()[source]

Create a default dataframe for testing.

test_and()[source]

Check that two cuts can be joined logically.

test_and_bool()[source]

Check that a cut and a boolean can be joined logically.

test_and_lambda()[source]

Check that a cut and a lambda can be joined logically.

test_call()[source]

Check that calling the cut returns a dataframe containing the events rather than returning an index array.

test_call_empty_input()[source]

Check that calling the object returns an empty dataframe if the input dataframe is empty.

test_call_no_match()[source]

Check that calling the object returns an empty dataframe when no event matches the selection.

test_default_cut()[source]

Make sure that the default cut accepts very event in the dataframe.

test_init_cut()[source]

Check that a cut can be passed to the constructor.

test_init_cut_name_inherit()[source]

Check that the name of a cut passed to the constructor is inherited.

test_init_cut_name_inherit_precedence()[source]

Check that the name argument has precedence over the given cut.

test_init_with_lambda()[source]

Check that creating a cut with a lambda expression applies the uses the lambda to filter the dataframe.

test_label()[source]

Check that names specified during construction are available via the ‘name’ attribute.

test_not()[source]

Check that a cut and a boolean can be joined logically.

test_or()[source]

Check that two cuts can be joined logically.

test_or_bool()[source]

Check that a cut and a boolean can be joined logically.

test_or_lambda()[source]

Check that a cut and a lambda can be joined logically.

test_rand_lambda()[source]

Check that a cut and a lambda (from the left) can be joined logically.

test_ror_lambda()[source]

Check that a cut and a lambda (from the left) can be joined logically.

test_rxor_lambda()[source]

Check that a cut and a lambda (from the left) can be joined logically.

test_xor()[source]

Check that two cuts can be joined logically.

test_xor_bool()[source]

Check that a cut and a boolean can be joined logically.

test_xor_lambda()[source]

Check that a cut and a lambda can be joined logically.

nnfwtbn.tests.test_hist module

class nnfwtbn.tests.test_hist.HistTestBase(methodName='runTest')[source]

Bases: unittest.case.TestCase

Test the implementation of hist().

The implementation is tested by inspecting the returned uhepp objects.

__module__ = 'nnfwtbn.tests.test_hist'
setUp()[source]

Set up a toy dataframe and processes

test_yield_base()[source]

Check the bin contents

test_yiele_stat()[source]

Check the statistical uncertainties

nnfwtbn.tests.test_model module

class nnfwtbn.tests.test_model.BinaryCVTestCase(methodName='runTest')[source]

Bases: unittest.case.TestCase

Test the implementation of binary cross validation.

__module__ = 'nnfwtbn.tests.test_model'
generate_df()[source]

Generates a toy dataframe.

test_fold_info_test()[source]

Check that fold info indices are are correct

test_fold_info_training()[source]

Check that fold info indices are are correct

test_fold_info_validation()[source]

Check that fold info indices are are correct

test_saving_and_loading()[source]

Test that saving and loading a cross validator doesn’t change its configuration.

test_select_cv_set_test()[source]

Check that only the test events of each slice are returned.

test_select_cv_set_training()[source]

Check that only the training events of each slice are returned.

test_select_cv_set_validation()[source]

Check that only the validation events of each slice are returned.

test_slice_frac()[source]

Check that all events are sorted into the correct slice.

test_slice_mod()[source]

Check that all events are sorted into the correct slice.

test_test_frac()[source]

Check that only the test events of each slice are returned.

test_test_mod()[source]

Check that only the test events of each slice are returned.

test_training_frac()[source]

Check that only the training events of each slice are returned.

test_training_mod()[source]

Check that only the training events of each slice are returned.

test_validation_frac()[source]

Check that only the validation events of each slice are returned.

test_validation_mod()[source]

Check that only the validation events of each slice are returned.

class nnfwtbn.tests.test_model.CategoricalWeightNormalizerTestCase(methodName='runTest')[source]

Bases: unittest.case.TestCase

Test the implementation of normalize_category_weights.

__module__ = 'nnfwtbn.tests.test_model'
generate_df()[source]

Generate toy dataframe.

test_alternative_weight()[source]

Check that the constructor normalized the classes using an alternative weight variables.

test_main()[source]

Check that the constructor normalized the classes.

class nnfwtbn.tests.test_model.ClassicalCVTestCase(methodName='runTest')[source]

Bases: unittest.case.TestCase

Test the implementation of classical cross validation with k=4.

__module__ = 'nnfwtbn.tests.test_model'
generate_df()[source]

Generates a toy dataframe.

test_saving_and_loading()[source]

Test that saving and loading a cross validator doesn’t change its configuration.

test_slice_frac()[source]

Check that all events are sorted into the correct slice.

test_slice_mod()[source]

Check that all events are sorted into the correct slice.

test_test_frac()[source]

Check that only the test events of each slice are returned.

test_test_mod()[source]

Check that only the test events of each slice are returned.

test_training_frac()[source]

Check that only the training events of each slice are returned.

test_training_mod()[source]

Check that only the training events of each slice are returned.

test_validation_frac()[source]

Check that only the validation events of each slice are returned.

test_validation_mod()[source]

Check that only the validation events of each slice are returned.

class nnfwtbn.tests.test_model.CrossValidatorTestCase(methodName='runTest')[source]

Bases: unittest.case.TestCase

Test the non-abstract parts of CrossValidator class.

__module__ = 'nnfwtbn.tests.test_model'
test_equal_different_class()[source]

Check the equal operator for cross validators with different types.

test_equal_different_k()[source]

Check the equal operator for cross validators with different values for k.

test_equal_different_mode()[source]

Check the equal operator for cross validators with mod modes.

test_equal_different_variables()[source]

Check the equal operator for cross validators with different variable names.

test_equal_same_values()[source]

Check the equal operator for cross validators which are created with the same values.

test_init_both_methods()[source]

Check that an error is raised if both selection methods are used constructor.

test_init_no_variable()[source]

Check that an error is raised if no variable object is passed to the constructor.

test_init_store()[source]

Check that the constructor stores all variables passed to it.

class nnfwtbn.tests.test_model.EstimatorNormalizerTestCase(methodName='runTest')[source]

Bases: unittest.case.TestCase

Test the implementation of EstimatorNormalizer.

__module__ = 'nnfwtbn.tests.test_model'
generate_df()[source]

Generate toy dataframe.

generate_test_df()[source]

Generate toy dataframe used to test the normalization.

test_call()[source]

Check that the normalization moments are applied to the given dataframe.

test_call_other_vars()[source]

Check that columns in the dataframe are left untouched if moments are missing.

test_equal_same_values()[source]
test_init()[source]

Check that the constructor computes the normalization moments of all columns in the given dataframe if no input_list is given.

test_init_input_list()[source]

Check that the constructor computes the normalization only of the columns listed in the input_list.

test_saving_and_loading()[source]

Test that saving and loading a estimator normalizer doesn’t change its configuration.

class nnfwtbn.tests.test_model.HepNetTestCase(methodName='runTest')[source]

Bases: unittest.case.TestCase

__module__ = 'nnfwtbn.tests.test_model'
test_saving_and_loading()[source]

Test that saving and loading a neural network doesn’t change its configuration.

class nnfwtbn.tests.test_model.MixedCVTestCase(methodName='runTest')[source]

Bases: unittest.case.TestCase

Test the implementation of mixed cross validation with k=8.

__module__ = 'nnfwtbn.tests.test_model'
generate_df()[source]

Generates a toy dataframe.

test_saving_and_loading()[source]

Test that saving and loading a cross validator doesn’t change its configuration.

test_slice_frac()[source]

Check that all events are sorted into the correct slice.

test_slice_mod()[source]

Check that all events are sorted into the correct slice.

test_test_frac()[source]

Check that only the test events of each slice are returned.

test_test_mod()[source]

Check that only the test events of each slice are returned.

test_training_frac()[source]

Check that only the training events of each slice are returned.

test_training_mod()[source]

Check that only the training events of each slice are returned.

test_validation_frac()[source]

Check that only the validation events of each slice are returned.

test_validation_mod()[source]

Check that only the validation events of each slice are returned.

class nnfwtbn.tests.test_model.NoTestCVTestCase(methodName='runTest')[source]

Bases: unittest.case.TestCase

Test the implementation of no-test cross validation.

__module__ = 'nnfwtbn.tests.test_model'
generate_df()[source]

Generates a toy dataframe.

test_saving_and_loading()[source]

Test that saving and loading a cross validator doesn’t change its configuration.

test_slice_frac()[source]

Check that all events are sorted into the correct slice.

test_slice_frac_k2()[source]

Check that all events are sorted into the correct slice.

test_slice_mod()[source]

Check that all events are sorted into the correct slice.

test_slice_mod_k2()[source]

Check that all events are sorted into the correct slice.

test_test_frac()[source]

Check that only the test events of each slice are returned.

test_test_mod()[source]

Check that only the test events of each slice are returned.

test_training_frac()[source]

Check that only the training events of each slice are returned.

test_training_mod()[source]

Check that only the training events of each slice are returned.

test_validation_frac()[source]

Check that only the validation events of each slice are returned.

test_validation_mod()[source]

Check that only the validation events of each slice are returned.

class nnfwtbn.tests.test_model.StubCrossValidator(k, mod_var=None, frac_var=None)[source]

Bases: nnfwtbn.model.CrossValidator

__abstractmethods__ = frozenset({})
__module__ = 'nnfwtbn.tests.test_model'
select_slice(df, slice_i)[source]

Returns the index array to select all events from the dataset of a given slice.

NB: This method is for internal usage only. There might be more than k slices.

select_test(df, fold_i)[source]

Returns the index array to select all test events from the dataset for the given fold.

select_training(df, fold_i)[source]

Returns the index array to select all training events from the dataset for the given fold.

select_validation(df, fold_i)[source]

Returns the index array to select all validation events from the dataset for the given fold.

nnfwtbn.tests.test_plot module

class nnfwtbn.tests.test_plot.DaskComputeTestCase(methodName='runTest')[source]

Bases: unittest.case.TestCase

Test the implementation of _dask_compute()

__module__ = 'nnfwtbn.tests.test_plot'
test_dask()[source]

Check that the return value is correct

test_pandas()[source]

Check that the input can pandas

class nnfwtbn.tests.test_plot.HelperMethodsTestCase(methodName='runTest')[source]

Bases: unittest.case.TestCase

Check that helper methods are implemented correctly

__module__ = 'nnfwtbn.tests.test_plot'
test_human_readable()[source]

Check start or end chars are removed

class nnfwtbn.tests.test_plot.PlotTestCases(methodName='runTest')[source]

Bases: unittest.case.TestCase

Test the implementation of the functions in the plot module. These are actual tests, not only survival tests.

__module__ = 'nnfwtbn.tests.test_plot'
test_fill_labels()[source]

Check that fill_labels() substitutes None with the module string.

test_roc_area()[source]

Check that roc() returns the area and an uncertainty estimate for a toy example.

class nnfwtbn.tests.test_plot.SurvivalTestCase(methodName='runTest')[source]

Bases: unittest.case.TestCase

Test that calling the plotting methods does not cause a crash.

(Testing plotting methods is notoriously difficult.)

__module__ = 'nnfwtbn.tests.test_plot'
test_atlasify()[source]

Check that calling atlasify() does not raise an error.

test_confusion_matrix()[source]

Check that calling confusion_matrix() does not raise an exception.

test_confusion_matrix_argument_reverse()[source]

Check that confusion_matrix does not change the arguments.

test_confusion_matrix_return()[source]

Check that the return value is not None.

test_hist()[source]

Check that calling hist() does not raise an exception.

test_hist_facory()[source]

Check that calling a HistogramFactory does not raise an exception.

test_hist_return()[source]

Check that the return value is not None.

test_hist_return_wo_ratio()[source]

Check that the return value is not None if there is no ratio plot.

test_hist_wo_ratio()[source]

Check that creating a plot without ratio plot does not crash.

test_roc()[source]

Check that calling roc() does not crash.

test_roc_custom_axis()[source]

Check that calling roc() with an existing axis does not crash.

test_roc_custom_selection()[source]

Check that calling roc() with a custom selection does not crash.

test_roc_return()[source]

Check that the return valueis not None

class nnfwtbn.tests.test_plot.TransposeTesCase(methodName='runTest')[source]

Bases: unittest.case.TestCase

Test the implementation of _transpose()

__module__ = 'nnfwtbn.tests.test_plot'
tes_col()[source]

Check that a column is turned into a row

test_empty()[source]

Check that a empty list and a list of an empty list handled

test_non_modify()[source]

Check that the original arrays are not modified

test_rect()[source]

Check that a rectangular array is transposed.

test_row()[source]

Check that a row is turned into a column

test_single()[source]

Check that a single-item-list is no changed.

test_square()[source]

Check that a square array is transposed.

nnfwtbn.tests.test_process module

class nnfwtbn.tests.test_process.ProcessTestCase(methodName='runTest')[source]

Bases: unittest.case.TestCase

Test the implementation of the Process class.

__module__ = 'nnfwtbn.tests.test_process'
generate_df()[source]

Generate a toy dataframe.

test_call()[source]

Check that calling a process returns a dataframe with selected events.

test_default_range_var()[source]

Check that the default range_var value is taken from the class property.

test_idx_array()[source]

Check that calling idx_array() returns an index array with selected events.

test_init()[source]

Check that all arguments are stored internally.

test_init_selection_and_range()[source]

Check that an error is raised if both selection and range is passed to the constructor.

test_lambda()[source]

Check that a lambda selection is converted to a cut object.

test_no_color()[source]

Check that processes don’t accept the ‘color’ argument.

test_no_selection()[source]

Check that an issue is raised if no selection method is used.

test_no_type()[source]

Check that processes don’t accept the ‘type’ argument.

test_range_type()[source]

Check that an exception is raised if the range argument is not a tuple of two numbers.

test_range_var_store()[source]

Check that the range_var argument takes precedence over the class constant.

test_repr_cut()[source]

Check that the expected string representation is returned when the object uses a selection cut.

test_repr_range()[source]

Check that the expected string representation is returned when the object uses a range selection.

nnfwtbn.tests.test_stack module

class nnfwtbn.tests.test_stack.TestStack(methodName='runTest')[source]

Bases: unittest.case.TestCase

Test the implementation of the Stack class.

__module__ = 'nnfwtbn.tests.test_stack'
test_add_process_append_kwds()[source]

Check that adding a process appends the custom kwds to the internal lists.

test_add_process_append_process()[source]

Check that adding a process appends the new process to the internal lists.

test_add_process_store_kwds()[source]

Check that add_process() stores the custom kwds of the process.

test_add_process_store_process()[source]

Check that add_process() stores the new process.

test_data_stack()[source]

Check that data_stack and generic stack agree. mc.

test_data_stack_raises()[source]

Check that data_stack raises an exception if the data_uncertainty argument is used.

test_get_aux_custom()[source]

Check that get_aux() returns the default aux values when the process was added with custom aux values.

test_get_aux_default()[source]

Check that get_aux() returns the default aux values when the process was added without a custom aux value.

test_get_aux_init_process()[source]

Check that get_aux() returns the default aux values when the process was passed to the constructor.

test_get_aux_none_overwrite()[source]

Check that passing None as an aux keyword overwrites the default.

test_get_aux_not_modify_outer()[source]

Check that calling get_aux() does not modify dicts from the constructor, add_process() or the internal one.

test_get_histtype_custom()[source]

Check that get_histtype() returns the default histtype when the process was added with a custom histtype.

test_get_histtype_default()[source]

Check that get_histtype() returns the default histtype when the process was added without a custom histtype.

test_get_histtype_init_process()[source]

Check that get_histtype() returns the default histtype when the process was passed to the constructor.

test_hist()[source]

Check that get_hist() returns the histogram for a single progress when the i argument is used.

test_init_defaults()[source]

Check that the default values fr histtype and data_uncertainty are not None.

test_init_store_kwds()[source]

Check that the keyword arguments passed to the constructor are stored.

test_init_store_processes()[source]

Check that the constructor stores the processes passed to it.

test_init_store_processes_empty()[source]

Check that passing no processes to the constructor works.

test_is_data_uncertainty_custom()[source]

Check that is_data_uncertainty() returns the default uncertainty value when the process was added with a custom data_uncertainty value.

test_is_data_uncertainty_default()[source]

Check that is_data_uncertainty() returns the default uncertainty value when the process was added without a custom data_uncertainty value.

test_is_data_uncertainty_init_process()[source]

Check that is_data_uncertainty() returns the default uncertainty vlaue when the process was passed to the constructor.

test_len_add()[source]

Check that len() returns the number of processes passed to the constructor when add_process() is not called.

test_len_init()[source]

Check that len() returns the number of processes passed to the constructor when add_process() is not called.

test_mc_stack()[source]

Check that mc_stack and generic stack agree. mc.

test_mc_stack_raises()[source]

Check that mc_stack raises an exception if the data_uncertainty argument is used.

test_not_none_or_default_False()[source]

Check that not_none_or_default() returns the value if the value is False.

test_not_none_or_default_None()[source]

Check that not_none_or_default() returns the default if the value is None.

test_not_none_or_default_NoneDefault()[source]

Check that not_none_or_default() returns the value if the value is a non-empty string.

test_not_none_or_default_NotNone()[source]

Check that not_none_or_default() returns the value if the value is a non-empty string.

test_total()[source]

Check that get_total() returns the correct bin entries.

test_uncertainty_only_data()[source]

Check that get_total_uncertainty() returns sqrt(N) of when all processes are data.

test_uncertainty_only_mc()[source]

Check that get_total_uncertainty() returns sqrt(sum w2) when all processes are mc.

nnfwtbn.tests.test_toydata module

class nnfwtbn.tests.test_toydata.DrawTestCase(methodName='runTest')[source]

Bases: unittest.case.TestCase

Test the implementation of draw().

__module__ = 'nnfwtbn.tests.test_toydata'
setUp()[source]

Instantiate a random number generator.

test_draw_len()[source]

Check that draw returns the number of samples given by the size parameter.

test_draw_limits()[source]

Check that the returned numbers are withing the limit.

test_draw_limits_2()[source]

Check that the returned numbers are withing the limit.

test_draw_reproducible()[source]

Check that draw returns the same array when called with identical arguments.

test_draw_seed()[source]

Check that different arrays are returned when different seeds are given.

nnfwtbn.tests.test_variable module

class nnfwtbn.tests.test_variable.RangeBlindingTestCase(methodName='runTest')[source]

Bases: unittest.case.TestCase

Test the implementation of the RangeBlinding class.

__module__ = 'nnfwtbn.tests.test_variable'
generate_df()[source]

Returns a toy dataframe.

test_bin_border()[source]

Check that the blind range is extended to match the bin borders.

test_bin_border_left()[source]

Check that the blinding does not break if the blinding is left of the first bin.

test_bin_border_right()[source]

Check that the blinding does not break if the blinding is left of the first bin.

test_event_blinding()[source]

Check that events in the given region are removed.

test_init_store()[source]

Check that the constructor stores all arguments.

class nnfwtbn.tests.test_variable.VariableTestCase(methodName='runTest')[source]

Bases: unittest.case.TestCase

Test the implementation of the variable class.

__module__ = 'nnfwtbn.tests.test_variable'
generate_df()[source]

Generate a toy dataframe.

test_call_column()[source]

Check that calling the variable extracts the given column name.

test_call_lambda()[source]

Check that calling the variable called the given lambda.

test_equal_different_definition()[source]

Check that variables with a different definition are not equal.

test_equal_different_name()[source]

Check that variables with a different name are not equal.

test_equal_different_unit()[source]

Check that variables with a different unit are not equal.

test_equal_same_values()[source]

Check the equal operator for variables which are created with the same values.

test_init_blinding_type()[source]

Check that an error is thrown if the blinding object is not an instance of the abstract blinding class.

test_init_definition_string()[source]

Check that a string used as the variable definition is wrapped into a lambda.

test_init_store()[source]

Check that all arguments are stored in the object.

test_repr()[source]

Check that the string representation contains the name of the variable.

test_saving_and_loading()[source]

Test that saving and loading a variable doesn’t change the variable.

Module contents