Skip to content

Commit

Permalink
PrinterValidator
Browse files Browse the repository at this point in the history
  • Loading branch information
faissaloux committed Dec 1, 2023
1 parent d1ee87a commit d754f91
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 25 deletions.
29 changes: 4 additions & 25 deletions termspark/termspark.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
from .exceptions.lenNotSupportedException import LenNotSupportedException
from .exceptions.minNotReachedException import MinNotReachedException
from .exceptions.multiplePositionsNotSupported import MultiplePositionsNotSupported
from .exceptions.printerArgException import PrinterArgException
from .helpers.existenceChecker import ExistenceChecker
from .painter.painter import Painter
from .structurer.structurer import Structurer
from .validators.printerValidator import PrinterValidator


class TermSpark:
Expand Down Expand Up @@ -45,14 +45,7 @@ def __init__(self):
def print_left(
self, content: str, color: Optional[str] = None, highlight: Optional[str] = None
):
if any(
[
isinstance(content, list),
isinstance(color, list),
isinstance(highlight, list),
]
):
raise PrinterArgException("left")
PrinterValidator().validate(content, color, highlight)

self.spark_left([content, color, highlight]) # type: ignore

Expand All @@ -61,14 +54,7 @@ def print_left(
def print_right(
self, content: str, color: Optional[str] = None, highlight: Optional[str] = None
):
if any(
[
isinstance(content, list),
isinstance(color, list),
isinstance(highlight, list),
]
):
raise PrinterArgException("right")
PrinterValidator().validate(content, color, highlight)

self.spark_right([content, color, highlight]) # type: ignore

Expand All @@ -77,14 +63,7 @@ def print_right(
def print_center(
self, content: str, color: Optional[str] = None, highlight: Optional[str] = None
):
if any(
[
isinstance(content, list),
isinstance(color, list),
isinstance(highlight, list),
]
):
raise PrinterArgException("center")
PrinterValidator().validate(content, color, highlight)

self.spark_center([content, color, highlight]) # type: ignore

Expand Down
Empty file.
13 changes: 13 additions & 0 deletions termspark/validators/printerValidator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from ..exceptions.printerArgException import PrinterArgException


class PrinterValidator:
def validate(self, content, color, highlight):
if any(
[
isinstance(content, list),
isinstance(color, list),
isinstance(highlight, list),
]
):
raise PrinterArgException("left")
22 changes: 22 additions & 0 deletions tests/printer_validaor_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import pytest

from termspark.exceptions.printerArgException import PrinterArgException
from termspark.validators.printerValidator import PrinterValidator


class TestPrinterValidator:
def test_validate_content(self):
with pytest.raises(PrinterArgException):
PrinterValidator().validate(["termspark"], "black", "green")

def test_validate_color(self):
with pytest.raises(PrinterArgException):
PrinterValidator().validate("termspark", ["black"], "green")

def test_validate_highlight(self):
with pytest.raises(PrinterArgException):
PrinterValidator().validate("termspark", "black", ["green"])

def test_validate_all(self):
with pytest.raises(PrinterArgException):
PrinterValidator().validate(["termspark"], ["black"], ["green"])

0 comments on commit d754f91

Please sign in to comment.