Skip to content

Commit

Permalink
Add binder unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xzdandy committed Sep 11, 2023
1 parent a696af6 commit a196a44
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion test/unit_tests/binder/test_statement_binder.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import unittest
from unittest.mock import MagicMock, patch
from unittest.mock import MagicMock, Mock, patch

from evadb.binder.binder_utils import BinderError
from evadb.binder.statement_binder import StatementBinder
Expand All @@ -26,6 +26,20 @@
from evadb.parser.create_statement import ColumnDefinition


def assert_not_called_with(self, *args, **kwargs):
try:
self.assert_called_with(*args, **kwargs)
except AssertionError:
return
raise AssertionError(
"Expected %s to not have been called."
% self._format_mock_call_signature(args, kwargs)
)


Mock.assert_not_called_with = assert_not_called_with


class StatementBinderTests(unittest.TestCase):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand Down Expand Up @@ -272,6 +286,17 @@ def test_bind_select_statement(self, is_groupable_mock, groupby_mock):
for mock in mocks:
mock_binder.assert_any_call(mock)

def test_bind_select_statement_without_from(self):
with patch.object(StatementBinder, "bind") as mock_binder:
binder = StatementBinder(StatementBinderContext(MagicMock()))
expr = MagicMock()
from evadb.parser.select_statement import SelectStatement

select_statement = SelectStatement(target_list=[expr])
binder._bind_select_statement(select_statement)
mock_binder.assert_not_called_with(select_statement.from_table)
mock_binder.assert_any_call(expr)

@patch("evadb.binder.statement_binder.StatementBinderContext")
def test_bind_select_statement_union_starts_new_context(self, mock_ctx):
with patch.object(StatementBinder, "bind"):
Expand Down

0 comments on commit a196a44

Please sign in to comment.