Skip to content

Commit

Permalink
Removed success from OutputSuccess and added super
Browse files Browse the repository at this point in the history
  • Loading branch information
Hook25 committed Nov 8, 2023
1 parent 904f692 commit bdf7720
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
27 changes: 22 additions & 5 deletions checkbox-ng/plainbox/impl/session/system_information.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3

import abc
import json
from subprocess import run, PIPE, check_output, STDOUT, CalledProcessError

Expand Down Expand Up @@ -61,25 +62,41 @@ def collect() -> dict:
return CollectorMeta.collect()

Check warning on line 62 in checkbox-ng/plainbox/impl/session/system_information.py

View check run for this annotation

Codecov / codecov/patch

checkbox-ng/plainbox/impl/session/system_information.py#L62

Added line #L62 was not covered by tests


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
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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit bdf7720

Please sign in to comment.