From bdf77202e2114f4e5e0b58728a21be34d8e9015b Mon Sep 17 00:00:00 2001 From: Hook25 Date: Wed, 8 Nov 2023 11:06:39 +0100 Subject: [PATCH] Removed success from OutputSuccess and added super --- .../impl/session/system_information.py | 27 +++++++++++++++---- .../impl/session/test_system_information.py | 2 +- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/checkbox-ng/plainbox/impl/session/system_information.py b/checkbox-ng/plainbox/impl/session/system_information.py index c11382403..82243f0b5 100755 --- a/checkbox-ng/plainbox/impl/session/system_information.py +++ b/checkbox-ng/plainbox/impl/session/system_information.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 +import abc import json from subprocess import run, PIPE, check_output, STDOUT, CalledProcessError @@ -61,17 +62,33 @@ def collect() -> dict: return CollectorMeta.collect() -class OutputSuccess: +class OutputABC: + + @abc.abstractmethod + def to_dict(self): + """ + Creates a dictionary from the class + """ + raise NotImplementedError + + @classmethod + @abc.abstractmethod + def from_dict(cls, dct) -> "OutputABC": + """ + Creates this class from a dictionary + """ + raise NotImplementedError + + +class OutputSuccess(OutputABC): def __init__(self, json_output: dict, stderr: str): self.json_output = json_output self.stderr = stderr - self.success = True def to_dict(self): return { "json_output": self.json_output, "stderr": self.stderr, - "success": self.success, } @classmethod @@ -79,7 +96,7 @@ def from_dict(cls, dct): return cls(dct["json_output"], dct["stderr"]) -class OutputFailure: +class OutputFailure(OutputABC): def __init__(self, stdout: str, stderr: str, return_code: int): self.stdout = stdout self.stderr = stderr @@ -101,7 +118,7 @@ class CollectionOutput: def __init__( self, tool_version: str, - outputs: "OutputSuccess|OutputFailure", + outputs: "OutputABC", ): self.tool_version = tool_version self.outputs = outputs diff --git a/checkbox-ng/plainbox/impl/session/test_system_information.py b/checkbox-ng/plainbox/impl/session/test_system_information.py index eeafa3a0d..f7cf4e70b 100644 --- a/checkbox-ng/plainbox/impl/session/test_system_information.py +++ b/checkbox-ng/plainbox/impl/session/test_system_information.py @@ -190,7 +190,7 @@ def test_from_dict_success(self): collection_output.outputs.json_output, {"key": "value"} ) self.assertEqual(collection_output.outputs.stderr, "") - self.assertTrue(collection_output.outputs.success) + self.assertTrue(collection_output.success) def test_from_dict_failure(self): input_dict = {