Skip to content

Commit

Permalink
Add few tests, update codecov yml (#480)
Browse files Browse the repository at this point in the history
* Add few tests, update codecov yml

* Fix coverage config
  • Loading branch information
amrit110 authored Sep 7, 2023
1 parent 5b1c745 commit b3bc280
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 7 deletions.
9 changes: 3 additions & 6 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
codecov:
after_n_builds: 2
require_ci_to_pass: true
notify:
after_n_builds: 2
wait_for_ci: yes
comment:
behavior: default
layout: reach,diff,flags,tree,reach
show_carryforward_flags: false
require_changes: true
coverage:
precision: 2
range:
- 55.0
- 100.0
round: down
status:
changes: true
default_rules:
Expand Down
22 changes: 21 additions & 1 deletion cyclops/query/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def __post_init__(self) -> None:


def _addindent(s_: str, num_spaces: int = 4) -> str:
"""Add spaces to a string.
"""Add spaces to a string except the first line.
Parameters
----------
Expand Down Expand Up @@ -259,6 +259,26 @@ def __repr__(self) -> str:

return main_str

def __getattr__(self, name: str) -> "QueryOp":
"""Get an attribute.
Parameters
----------
name
Name of the attribute.
Returns
-------
QueryOp
The child operation with the given name.
"""
if name in self._ops:
return self._ops[name]
raise AttributeError(
f"'{self.__class__.__name__}' object has no attribute '{name}'",
)


def _chain_ops(
query: Subquery,
Expand Down
61 changes: 61 additions & 0 deletions tests/cyclops/query/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@
Literal,
Or,
OrderBy,
QueryOp,
Rename,
ReorderAfter,
Sequential,
Substring,
Trim,
Union,
_addindent,
_none_add,
_process_checks,
)
Expand Down Expand Up @@ -84,6 +86,65 @@ def test__process_checks(table_input):
_process_checks(table_input, cols_not_in=["a"])


class TestAddndent:
"""Test _addindent fn."""

def test_addindent_multiple_lines(self):
"""Test _addindent fn with multiple lines."""
input_string = "This is a\nmultiline\nstring"
expected_output = "This is a\n multiline\n string"
assert _addindent(input_string, 4) == expected_output

def test_addindent_single_line(self):
"""Test _addindent fn with single line."""
input_string = "This is a single line string"
assert _addindent(input_string, 4) == input_string


class TestQueryOp:
"""Test QueryOp class."""

def test_add_child_operation(self):
"""Test adding a child operation."""
query_op = QueryOp()
child_op = QueryOp()
query_op._add_op("child", child_op)
assert query_op.child == child_op

def test_get_query_op_name(self):
"""Test getting the name of the query op."""
query_op = QueryOp()
assert query_op._get_name() == "QueryOp"

def test_set_attribute(self):
"""Test setting an attribute of the query op."""
query_op = QueryOp()
child_op = QueryOp()
query_op.child = child_op
assert query_op.child == child_op

def test_string_representation(self):
"""Test string representation of the query op."""
query_op = QueryOp()
child_op = QueryOp()
query_op._add_op("child", child_op)
assert repr(query_op) == "QueryOp(\n (child): QueryOp()\n)"

def test_add_child_operation_empty_name(self):
"""Test adding a child operation with an empty name."""
query_op = QueryOp()
child_op = QueryOp()
with pytest.raises(KeyError):
query_op._add_op("", child_op)

def test_add_child_operation_dot_name(self):
"""Test adding a child operation with a dot in the name."""
query_op = QueryOp()
child_op = QueryOp()
with pytest.raises(KeyError):
query_op._add_op("child.name", child_op)


@pytest.mark.integration_test()
def test_drop(visits_input):
"""Test Drop."""
Expand Down

0 comments on commit b3bc280

Please sign in to comment.