def double_initialize_test(self): """Test for the error ocuring when the same error measure is initialized twice.""" data = [[0.0, 0.0], [1, 0.1], [2, 0.2], [3, 0.3], [4, 0.4]] tsOrg = TimeSeries.from_twodim_list(data) tsCalc = TimeSeries.from_twodim_list(data) bem = BaseErrorMeasure() bem_calculate = bem._calculate bem_local_error = bem.local_error def return_zero(ignoreMe, ignoreMeToo): return 0 # remove the NotImplementedErrors for initialization bem.local_error = return_zero bem._calculate = return_zero # correct initialize call bem.initialize(tsOrg, tsCalc) # incorrect initialize call for cnt in xrange(10): try: bem.initialize(tsOrg, tsCalc) except StandardError: pass else: assert False # pragma: no cover bem.local_error = bem_calculate bem._calculate = bem_local_error
def double_initialize_test(self): """Test for the error ocuring when the same error measure is initialized twice.""" data = [[0.0, 0.0], [1, 0.1], [2, 0.2], [3, 0.3], [4, 0.4]] tsOrg = TimeSeries.from_twodim_list(data) tsCalc = TimeSeries.from_twodim_list(data) bem = BaseErrorMeasure() bem_calculate = bem._calculate bem_local_error = bem.local_error def return_zero(ignoreMe, ignoreMeToo): return 0 # remove the NotImplementedErrors for initialization bem.local_error = return_zero bem._calculate = return_zero # correct initialize call bem.initialize(tsOrg, tsCalc) # incorrect initialize call for cnt in range(10): try: bem.initialize(tsOrg, tsCalc) except Exception: pass else: assert False # pragma: no cover bem.local_error = bem_calculate bem._calculate = bem_local_error
def test_optimization_enabled(self): error = BaseErrorMeasure() error._enable_instance_optimization() cerror.initialize = Mock() error.initialize(None, None) #parameters irrelevant for this test assert cerror.initialize.called, "If optimization is enabled the c method should be called"
def test_optimization_disabled(self): error = BaseErrorMeasure() error._disable_instance_optimization() cerror.initialize = Mock() try: error.initialize(None, None) #parameters irrelevant for this test except: pass assert not cerror.initialize.called, "If optimization is disabled the c method should not be called"
def test_optimization_disabled(self): error = BaseErrorMeasure() error._disable_instance_optimization cerror.initialize = Mock() try: error.initialize(None, None) #parameters irrelevant for this test except: pass assert not cerror.initialize.called, "If optimization is disabled the c method should not be called"
def initialize_test(self): """Test if calculate throws an error as expected.""" data = [[0.0, 0.0], [1, 0.1], [2, 0.2], [3, 0.3], [4, 0.4]] tsOrg = TimeSeries.from_twodim_list(data) tsCalc = TimeSeries.from_twodim_list(data) bem = BaseErrorMeasure() try: bem.initialize(tsOrg, tsCalc) except NotImplementedError: pass else: assert False # pragma: no cover assert not bem.initialize(tsOrg, TimeSeries())
def test_function_call_is_transparent(self): """ With and without optimization the method should be called with the same parameters. """ old_error = BaseErrorMeasure.local_error BaseErrorMeasure.local_error = Mock() ts = TimeSeries.from_twodim_list([[1,1]]) error = BaseErrorMeasure() error._enable_instance_optimization() error.initialize(ts, ts) error = BaseErrorMeasure() error._disable_instance_optimization() error.initialize(ts, ts)
def test_function_call_is_transparent(self): """ With and without optimization the method should be called with the same parameters. """ oldError = BaseErrorMeasure.local_error BaseErrorMeasure.local_error = Mock() ts = TimeSeries.from_twodim_list([[1, 1]]) error = BaseErrorMeasure() error._enable_instance_optimization() error.initialize(ts, ts) error = BaseErrorMeasure() error._disable_instance_optimization() error.initialize(ts, ts) BaseErrorMeasure.local_error = oldError
def get_error_parameter_test(self): """Test for the parameter validity of get_error().""" data = [[0.0, 0.0], [1, 0.1], [2, 0.2], [3, 0.3], [4, 0.4]] tsOrg = TimeSeries.from_twodim_list(data) tsCalc = TimeSeries.from_twodim_list(data) bem = BaseErrorMeasure() bem_calculate = bem._calculate bem_local_error = bem.local_error def return_zero(ignoreMe, ignoreMeToo, andMe=None, andMeToo=None): return 0 # remove the NotImplementedErrors for initialization bem.local_error = return_zero bem._calculate = return_zero bem.initialize(tsOrg, tsCalc) bem.local_error = bem_local_error bem._calculate = bem_calculate try: bem.get_error(10.0, 90.0) except NotImplementedError: pass else: assert False # pragma: no cover for start in [-1.0, 80.0, 103.0]: for end in [-5.0, 10.0, 105.0]: try: bem.get_error(start, end) except ValueError: pass else: assert False # pragma: no cover