Skip to content

Commit

Permalink
chore: remove bcolors (#129)
Browse files Browse the repository at this point in the history
* remove bcolors

* remove bcolors

* fix

* deprecate instead of remove

* improve
  • Loading branch information
fpgmaas authored Sep 8, 2024
1 parent b35d932 commit 0e513ed
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 14 deletions.
9 changes: 9 additions & 0 deletions chispa/bcolors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

import warnings


class bcolors:
NC = "\033[0m" # No Color, reset all
Expand Down Expand Up @@ -31,13 +33,20 @@ class bcolors:
Bold = "\033[1m"
Underline = "\033[4m"

def __init__(self):
warnings.warn("The `bcolors` class is deprecated and will be removed in a future version.", DeprecationWarning)


def blue(s: str) -> str:
warnings.warn("The `blue` function is deprecated and will be removed in a future version.", DeprecationWarning)
return bcolors.LightBlue + str(s) + bcolors.LightRed


def underline_text(input_text: str) -> str:
"""
Takes an input string and returns a white, underlined string (based on PrettyTable formatting)
"""
warnings.warn(
"The `underline_text` function is deprecated and will be removed in a future version.", DeprecationWarning
)
return bcolors.White + bcolors.Underline + input_text + bcolors.NC + bcolors.LightRed
10 changes: 4 additions & 6 deletions chispa/column_comparer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from prettytable import PrettyTable

from chispa.bcolors import bcolors
from chispa.formatting import blue


class ColumnsNotEqualError(Exception):
Expand All @@ -20,9 +20,7 @@ def assert_column_equality(df, col_name1, col_name2):
t = PrettyTable([col_name1, col_name2])
for elements in zipped:
if elements[0] == elements[1]:
first = bcolors.LightBlue + str(elements[0]) + bcolors.LightRed
second = bcolors.LightBlue + str(elements[1]) + bcolors.LightRed
t.add_row([first, second])
t.add_row([blue(str(elements[0])), blue(str(elements[1]))])
else:
t.add_row([str(elements[0]), str(elements[1])])
raise ColumnsNotEqualError("\n" + t.get_string())
Expand All @@ -36,8 +34,8 @@ def assert_approx_column_equality(df, col_name1, col_name2, precision):
zipped = list(zip(colName1Elements, colName2Elements))
t = PrettyTable([col_name1, col_name2])
for elements in zipped:
first = bcolors.LightBlue + str(elements[0]) + bcolors.LightRed
second = bcolors.LightBlue + str(elements[1]) + bcolors.LightRed
first = blue(str(elements[0]))
second = blue(str(elements[1]))
# when one is None and the other isn't, they're not equal
if (elements[0] is None and elements[1] is not None) or (elements[0] is not None and elements[1] is None):
all_rows_equal = False
Expand Down
4 changes: 2 additions & 2 deletions chispa/formatting/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from chispa.formatting.format_string import format_string
from chispa.formatting.format_string import blue, format_string
from chispa.formatting.formats import RESET, Color, Format, Style
from chispa.formatting.formatting_config import FormattingConfig

__all__ = ("Style", "Color", "FormattingConfig", "Format", "format_string", "RESET")
__all__ = ("Style", "Color", "FormattingConfig", "Format", "format_string", "RESET", "blue")
6 changes: 5 additions & 1 deletion chispa/formatting/format_string.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from chispa.formatting.formats import RESET, Format
from chispa.formatting.formats import RESET, Color, Format


def format_string(input_string: str, format: Format) -> str:
Expand All @@ -19,3 +19,7 @@ def format_string(input_string: str, format: Format) -> str:

formatted_string = "".join(codes) + formatted_string + RESET
return formatted_string


def blue(string: str):
return Color.LIGHT_BLUE + string + Color.LIGHT_RED
10 changes: 5 additions & 5 deletions chispa/schema_comparer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from prettytable import PrettyTable

from chispa.bcolors import blue
from chispa.formatting import blue


class SchemasNotEqualError(Exception):
Expand Down Expand Up @@ -34,8 +34,8 @@ def inner(s1, s2, ignore_nullable, ignore_metadata):
t = PrettyTable(["schema1", "schema2"])
zipped = list(zip_longest(s1, s2))
for sf1, sf2 in zipped:
if are_structfields_equal(sf1, sf2, ignore_nullable, ignore_metadata):
t.add_row([blue(sf1), blue(sf2)])
if are_structfields_equal(sf1, sf2, True):
t.add_row([blue(str(sf1)), blue(str(sf2))])
else:
t.add_row([sf1, sf2])
raise SchemasNotEqualError("\n" + t.get_string())
Expand All @@ -50,7 +50,7 @@ def assert_basic_schema_equality(s1, s2):
zipped = list(zip_longest(s1, s2))
for sf1, sf2 in zipped:
if sf1 == sf2:
t.add_row([blue(sf1), blue(sf2)])
t.add_row([blue(str(sf1)), blue(str(sf2))])
else:
t.add_row([sf1, sf2])
raise SchemasNotEqualError("\n" + t.get_string())
Expand All @@ -63,7 +63,7 @@ def assert_schema_equality_ignore_nullable(s1, s2):
zipped = list(zip_longest(s1, s2))
for sf1, sf2 in zipped:
if are_structfields_equal(sf1, sf2, True):
t.add_row([blue(sf1), blue(sf2)])
t.add_row([blue(str(sf1)), blue(str(sf2))])
else:
t.add_row([sf1, sf2])
raise SchemasNotEqualError("\n" + t.get_string())
Expand Down
18 changes: 18 additions & 0 deletions tests/test_deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pytest

from chispa import DataFramesNotEqualError, assert_basic_rows_equality
from chispa.bcolors import bcolors, blue, underline_text
from chispa.default_formats import DefaultFormats
from chispa.formatting import FormattingConfig

Expand Down Expand Up @@ -66,3 +67,20 @@ class InvalidFormats:

with pytest.raises(ValueError):
FormattingConfig._from_arbitrary_dataclass(InvalidFormats())


def test_bcolors_deprecation():
with pytest.warns(DeprecationWarning, match="The `bcolors` class is deprecated"):
_ = bcolors()


def test_blue_deprecation():
with pytest.warns(DeprecationWarning, match="The `blue` function is deprecated"):
result = blue("test")
assert result == "\033[34mtest\033[31m"


def test_underline_text_deprecation():
with pytest.warns(DeprecationWarning, match="The `underline_text` function is deprecated"):
result = underline_text("test")
assert result == "\033[97m\033[4mtest\033[0m\033[31m"

0 comments on commit 0e513ed

Please sign in to comment.