Skip to content

Commit

Permalink
remove print statements, expand test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
fvankrieken committed Oct 8, 2024
1 parent 2d6e745 commit 67266f6
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 51 deletions.
106 changes: 57 additions & 49 deletions dcpy/test/utils/test_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ def test_deep_merge():
class Inner(BaseModel, arbitrary_types_allowed=True):
g: str
i: list
l: dict[str, str] # noqa: E741
q: pd.DataFrame
m: dict[str, str]
r: pd.DataFrame


class Outer(BaseModel, arbitrary_types_allowed=True):
Expand All @@ -27,32 +27,36 @@ class Outer(BaseModel, arbitrary_types_allowed=True):

class TestIndentedPrint:
df = pd.DataFrame({"x": [1, 2], "y": [3, 4]})
inner = Inner(g="h", i=["j", "k"], l={"m": "n", "o": "p"}, q=df)
inner = Inner(g="h", i=[["j"], {"k", "l"}], m={"n": "o", "p": "q"}, r=df)
outer = Outer(a={"b", "c"}, d=df, e={}, f=inner)

def test(self):
assert collections.flatten_and_indent(self.outer.model_dump()) == [
"a",
" b",
" c",
"d",
" x y",
" 0 1 3",
" 1 2 4",
"e: None",
"f",
" g: h",
" i",
" j",
" k",
" l",
" m: n",
" o: p",
" q",
" x y",
" 0 1 3",
" 1 2 4",
]
assert (
collections.flatten_and_indent(self.outer.model_dump())
== [
"a",
" b",
" c",
"d",
" x y",
" 0 1 3",
" 1 2 4",
"e: None",
"f",
" g: h",
" i",
" j", # list of lists are a little awkward. Not really a common use case though
" k",
" l",
" m",
" n: o",
" p: q",
" r",
" x y",
" 0 1 3",
" 1 2 4",
]
)

def test_custom_indent_and_offset(self):
assert collections.flatten_and_indent(
Expand All @@ -69,12 +73,13 @@ def test_custom_indent_and_offset(self):
" f",
" g: h",
" i",
" j",
" k",
" l",
" m: n",
" o: p",
" q",
" j",
" k",
" l",
" m",
" n: o",
" p: q",
" r",
" x y",
" 0 1 3",
" 1 2 4",
Expand All @@ -99,12 +104,13 @@ def test_line_breaks(self):
"f",
" g: h",
" i",
" j",
" k",
" l",
" m: n",
" o: p",
" q",
" j",
" k",
" l",
" m",
" n: o",
" p: q",
" r",
" x y",
" 0 1 3",
" 1 2 4",
Expand All @@ -125,12 +131,13 @@ def test_pretty_print(self):
"F",
" G: h",
" I",
" j",
" k",
" L",
" M: n",
" O: p",
" Q",
" j",
" k",
" l",
" M",
" N: o",
" P: q",
" R",
" x y",
" 0 1 3",
" 1 2 4",
Expand All @@ -148,12 +155,13 @@ def test_to_report(self):
f
g: h
i
j
k
l
m: n
o: p
q
j
k
l
m
n: o
p: q
r
x y
0 1 3
1 2 4"""
2 changes: 0 additions & 2 deletions dcpy/utils/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,9 @@ def flatten(li: list | dict, level: int) -> list:
current_node = li[0]

if isinstance(current_node, list) or isinstance(current_node, dict):
print("node is list or dict")
first = flatten(current_node, level + 1)

elif isinstance(current_node, set):
print("node is set")
first = flatten(sorted(list(current_node)), level + 1)

elif isinstance(current_node, DataFrame):
Expand Down

0 comments on commit 67266f6

Please sign in to comment.