This commit is contained in:
Yonatan Most 2019-10-31 13:19:38 +02:00
Родитель 4d4dc782d5
Коммит 3f02aa0f24
4 изменённых файлов: 17 добавлений и 6 удалений

Просмотреть файл

@ -1,5 +1,6 @@
import logging
import sys
from typing import Callable
from unittest import TestCase
from pykusto.utils import logger
@ -16,3 +17,13 @@ class TestBase(TestCase):
def setUp(self):
logger.info("Running test: " + self._testMethodName)
def assertRaises(self, expected_exception: BaseException, test_callable: Callable, *args, **kwargs):
expected_exception_type = type(expected_exception)
expected_exception_message = str(expected_exception)
with super().assertRaises(expected_exception_type) as cm:
test_callable(*args, **kwargs)
self.assertEqual(
expected_exception_message,
str(cm.exception)
)

Просмотреть файл

@ -70,7 +70,7 @@ class TestExpressions(TestBase):
def test_method_does_not_exist(self):
self.assertRaises(
AttributeError,
AttributeError("No such method: non_existant_method"),
col.foo.non_existant_method,
)

Просмотреть файл

@ -137,14 +137,14 @@ class TestQuery(TestBase):
def test_join_no_joined_table(self):
self.assertRaises(
JoinException,
JoinException("The joined query must have a table"),
Query().where(col.foo > 4).take(5).join(
Query().take(2), kind=JoinKind.INNER).on(col.col0).on(col.col1, col.col2).render
)
def test_join_no_on(self):
self.assertRaises(
JoinException,
JoinException("A call to join() must be followed by a call to on()"),
Query().where(col.foo > 4).take(5).join(
Query().take(2), kind=JoinKind.INNER).render
)
@ -201,7 +201,7 @@ class TestQuery(TestBase):
def test_mv_expand_no_args(self):
self.assertRaises(
ValueError,
ValueError("Please specify one or more columns for mv-expand"),
Query().mv_expand
)

Просмотреть файл

@ -34,7 +34,7 @@ class TestTable(TestBase):
def test_execute_no_table(self):
self.assertRaises(
RuntimeError,
RuntimeError("No table supplied"),
Query().take(5).execute
)
@ -43,7 +43,7 @@ class TestTable(TestBase):
table = PyKustoClient(mock_kusto_client)['test_db']['test_table']
self.assertRaises(
RuntimeError,
RuntimeError("This table is already bound to a query"),
Query(table).take(5).execute,
table
)