def test_diagnostic_composite_includes_attributes(): diagnostic = MockDiagnostic() diagnostic.inputs = ('input1', ) diagnostic.diagnostics = ('diagnostic1', ) composite = DiagnosticComposite(diagnostic) assert composite.inputs == ('input1', ) assert composite.diagnostics == ('diagnostic1', )
def test_diagnostic_composite_calls_one_diagnostic(mock_call): mock_call.return_value = {'foo': 50.} diagnostic_composite = DiagnosticComposite(MockDiagnostic()) state = {'air_temperature': 273.15} diagnostics = diagnostic_composite(state) assert mock_call.called assert diagnostics == {'foo': 50.}
def test_diagnostic_composite_includes_attributes(): diagnostic = MockDiagnostic() diagnostic.input_properties = {'input1': {}} diagnostic.diagnostic_properties = {'diagnostic1': {}} composite = DiagnosticComposite(diagnostic) assert composite.inputs == ('input1', ) assert composite.diagnostics == ('diagnostic1', )
def test_diagnostic_composite_call(mock_call): mock_call.return_value = {'foo': 5.} state = {'bar': 10.} diagnostics = DiagnosticComposite(MockDiagnostic()) new_state = diagnostics(state) assert list(state.keys()) == ['bar'] assert state['bar'] == 10. assert list(new_state.keys()) == ['foo'] assert new_state['foo'] == 5.
def test_diagnostic_composite_cannot_use_prognostic(): try: DiagnosticComposite(MockPrognostic()) except TypeError: pass except Exception as err: raise err else: raise AssertionError('TypeError should have been raised')
def test_diagnostic_composite_merges_attributes(): diagnostic1 = MockDiagnostic() diagnostic1.inputs = ('input1', ) diagnostic1.diagnostics = ('diagnostic1', ) diagnostic2 = MockDiagnostic() diagnostic2.inputs = ('input1', 'input2') diagnostic2.diagnostics = ('diagnostic2', ) composite = DiagnosticComposite(diagnostic1, diagnostic2) assert same_list(composite.inputs, ('input1', 'input2')) assert same_list(composite.diagnostics, ('diagnostic1', 'diagnostic2'))
def test_diagnostic_composite_merges_attributes(): diagnostic1 = MockDiagnostic() diagnostic1.input_properties = {'input1': {}} diagnostic1.diagnostic_properties = {'diagnostic1': {}} diagnostic2 = MockDiagnostic() diagnostic2.input_properties = {'input1': {}, 'input2': {}} diagnostic2.diagnostic_properties = {'diagnostic2': {}} composite = DiagnosticComposite(diagnostic1, diagnostic2) assert same_list(composite.inputs, ('input1', 'input2')) assert same_list(composite.diagnostics, ('diagnostic1', 'diagnostic2'))
def test_diagnostic_composite_ensures_valid_state(): diagnostic1 = MockDiagnostic() diagnostic1.inputs = ('input1', ) diagnostic1.diagnostics = ('diagnostic1', ) diagnostic2 = MockDiagnostic() diagnostic2.inputs = ('input1', 'input2') diagnostic2.diagnostics = ('diagnostic1', ) try: DiagnosticComposite(diagnostic1, diagnostic2) except SharedKeyException: pass except Exception as err: raise err else: raise AssertionError( 'Should not be able to have overlapping diagnostics in composite')
def test_empty_diagnostic_composite(): diagnostic_composite = DiagnosticComposite() state = {'air_temperature': 273.15} diagnostics = diagnostic_composite(state) assert len(diagnostics) == 0 assert isinstance(diagnostics, dict)