From c841804f7848db96a5b33d0873ad28f26ff11095 Mon Sep 17 00:00:00 2001 From: Daniel Flehner Heen Date: Thu, 27 Jun 2024 00:25:04 +0200 Subject: [PATCH] Prepare for unit test refactor. (#27) Converted Base class to regular class Updated all subclasses to adapt to the change Signed-off-by: apetrynet --- src/pyfdl/base.py | 14 ++++++++------ src/pyfdl/canvas.py | 1 + src/pyfdl/canvas_template.py | 1 + src/pyfdl/context.py | 1 + src/pyfdl/framing_decision.py | 1 + src/pyfdl/framing_intent.py | 1 + src/pyfdl/header.py | 1 + src/pyfdl/pyfdl.py | 1 + 8 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/pyfdl/base.py b/src/pyfdl/base.py index 6144820..c6851d3 100644 --- a/src/pyfdl/base.py +++ b/src/pyfdl/base.py @@ -13,7 +13,7 @@ NO_ROUNDING = {} -class Base(ABC): +class Base: # Holds a list of known attributes attributes = [] # Maps attribute names that clash with reserved builtin functions to safe alternatives (id -> id_) @@ -30,8 +30,7 @@ class Base(ABC): # The rounding strategy is used when rounding dimensions rounding_strategy = None - @abstractmethod - def __init__(self, *args: Any, **kwargs: Any): + def __init__(self): """Base class not to be instanced directly. Args: @@ -50,7 +49,7 @@ def __init__(self, *args: Any, **kwargs: Any): subclasses of [Base](#Base) """ - pass + ... def apply_defaults(self) -> None: """Applies default values defined in the `defaults` attribute to attributes that are `None`""" @@ -196,9 +195,8 @@ def set_rounding_strategy(cls, rules: Union[dict, None] = DEFAULT_ROUNDING_STRAT def generate_uuid(): return str(uuid.uuid4()) - @abstractmethod def __repr__(self) -> str: - pass + return f'{self.__class__.__name__}' def __str__(self) -> str: return str(self.to_dict()) @@ -315,6 +313,7 @@ def __init__(self, width: float, height: float): width: height: """ + super().__init__() self.width = width self.height = height @@ -361,6 +360,7 @@ def __init__(self, width: int, height: int): width: height: """ + super().__init__() self.width = width.__int__() self.height = height.__int__() @@ -411,6 +411,7 @@ def __init__(self, x: float, y: float): x: y: """ + super().__init__() self.x = x self.y = y @@ -446,6 +447,7 @@ def __init__(self, even: str = None, mode: str = None): Raises: FDLError: if you provide a value other than the ones listed above """ + super().__init__() self.even = even self.mode = mode diff --git a/src/pyfdl/canvas.py b/src/pyfdl/canvas.py index 929a5ff..39b21f1 100644 --- a/src/pyfdl/canvas.py +++ b/src/pyfdl/canvas.py @@ -49,6 +49,7 @@ def __init__( anamorphic_squeeze: float = None, framing_decisions: TypedCollection = None ): + super().__init__() self.label = label self.id = id_ self.source_canvas_id = source_canvas_id diff --git a/src/pyfdl/canvas_template.py b/src/pyfdl/canvas_template.py index 8b944d6..43b293f 100644 --- a/src/pyfdl/canvas_template.py +++ b/src/pyfdl/canvas_template.py @@ -58,6 +58,7 @@ def __init__( pad_to_maximum: bool = None, round_: RoundStrategy = None ): + super().__init__() self.label = label self.id = id_ self.target_dimensions = target_dimensions diff --git a/src/pyfdl/context.py b/src/pyfdl/context.py index 0765e6c..d07afdf 100644 --- a/src/pyfdl/context.py +++ b/src/pyfdl/context.py @@ -8,6 +8,7 @@ class Context(Base): id_attribute = "label" def __init__(self, label: str = None, context_creator: str = None, canvases: TypedCollection = None): + super().__init__() self.label = label self.context_creator = context_creator self.canvases = canvases or TypedCollection(Canvas) diff --git a/src/pyfdl/framing_decision.py b/src/pyfdl/framing_decision.py index efaff05..6271c8d 100644 --- a/src/pyfdl/framing_decision.py +++ b/src/pyfdl/framing_decision.py @@ -30,6 +30,7 @@ def __init__( protection_dimensions: DimensionsFloat = None, protection_anchor_point: Point = None ): + super().__init__() self.label = label self.id = id_ self.framing_intent_id = framing_intent_id diff --git a/src/pyfdl/framing_intent.py b/src/pyfdl/framing_intent.py index 03a0ddc..93204b4 100644 --- a/src/pyfdl/framing_intent.py +++ b/src/pyfdl/framing_intent.py @@ -18,6 +18,7 @@ def __init__( aspect_ratio: DimensionsInt = None, protection: float = None ): + super().__init__() self.id = id_ self.label = label self.aspect_ratio = aspect_ratio diff --git a/src/pyfdl/header.py b/src/pyfdl/header.py index 140cb4f..e748210 100644 --- a/src/pyfdl/header.py +++ b/src/pyfdl/header.py @@ -16,6 +16,7 @@ def __init__( fdl_creator: str = None, default_framing_intent: str = None ): + super().__init__() self.uuid = _uuid self.version = version self.fdl_creator = fdl_creator diff --git a/src/pyfdl/pyfdl.py b/src/pyfdl/pyfdl.py index 8695af4..c00fc94 100644 --- a/src/pyfdl/pyfdl.py +++ b/src/pyfdl/pyfdl.py @@ -47,6 +47,7 @@ def __init__( contexts: TypedCollection = None, canvas_templates: TypedCollection = None ): + super().__init__() self.uuid = _uuid self.version = version self.fdl_creator = fdl_creator