diff --git a/plinth/app.py b/plinth/app.py index cb5eff328..70c027639 100644 --- a/plinth/app.py +++ b/plinth/app.py @@ -104,6 +104,24 @@ class App: if not component.is_leader: component.set_enabled(enabled) + def diagnose(self): + """Run diagnostics and return results. + + Return value must be a list of results. Each result is a two-tuple with + first value as user visible description of the test followed by the + result. The test result is a string enumeration from 'failed', 'passed' + and 'error'. + + Results are typically collected by diagnosing each component of the app + and then supplementing the results with any app level diagnostic tests. + + """ + results = [] + for component in self.components.values(): + results.extend(component.diagnose()) + + return results + class Component: """Interface for an app component.""" @@ -121,6 +139,17 @@ class Component: """Run operations to enable the component.""" def disable(self): """Run operations to disable the component.""" + @staticmethod + def diagnose(): + """Run diagnostics and return results. + + Return value must be a list of results. Each result is a two-tuple with + first value as user visible description of the test followed by the + result. The test result is a string enumeration from 'failed', 'passed' + and 'error'. + + """ + return [] class FollowerComponent(Component): diff --git a/plinth/tests/test_app.py b/plinth/tests/test_app.py index d727a15b3..ceebb3df8 100644 --- a/plinth/tests/test_app.py +++ b/plinth/tests/test_app.py @@ -34,6 +34,10 @@ class LeaderTest(FollowerComponent): """Test class for using LeaderComponent in tests.""" is_leader = True + def diagnose(self): + """Return diagnostic results.""" + return [('test-result-' + self.component_id, 'success')] + @pytest.fixture(name='app_with_components') def fixture_app_with_components(): @@ -182,6 +186,13 @@ def test_app_set_enabled(app_with_components): assert app.components['test-leader-1'].is_enabled() +def test_app_diagnose(app_with_components): + """Test running diagnostics on an app.""" + results = app_with_components.diagnose() + assert results == [('test-result-test-leader-1', 'success'), + ('test-result-test-leader-2', 'success')] + + def test_component_initialization(): """Test that component is initialized properly.""" with pytest.raises(ValueError): @@ -192,6 +203,12 @@ def test_component_initialization(): assert not component.is_leader +def test_component_diagnose(): + """Test running diagnostics on component.""" + component = Component('test-component') + assert component.diagnose() == [] + + def test_follower_component_initialization(): """Test that follower component is initialized properly.""" component = FollowerComponent('test-follower-1')