CR fixes - fixed bug with not raising an exception and adding test coverage for wrong arguments type

This commit is contained in:
Ofri Kleinfeld 2021-07-20 15:00:47 +03:00
Родитель 439dd3cb19
Коммит 0afc492248
2 изменённых файлов: 21 добавлений и 3 удалений

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

@ -553,11 +553,11 @@ class _JoinQuery(Query):
def _inner_on_with_or_without_table(self, col: Union[BaseColumn, Tuple[BaseColumn, BaseColumn]]) -> '_JoinQuery': def _inner_on_with_or_without_table(self, col: Union[BaseColumn, Tuple[BaseColumn, BaseColumn]]) -> '_JoinQuery':
if isinstance(col, BaseColumn): if isinstance(col, BaseColumn):
return self._inner_on(col) return self._inner_on(col)
elif isinstance(col, tuple) and isinstance(col[0], BaseColumn) and isinstance(col[1], BaseColumn): elif isinstance(col, tuple) and len(col) == 2 and isinstance(col[0], BaseColumn) and isinstance(col[1], BaseColumn):
return self._inner_on_with_table(*col) return self._inner_on_with_table(*col)
else: else:
JoinException( raise JoinException(
"A join argument could be a column, or a tuple of columns corresponding to the input and join " "A join argument could be a column, or a tuple of two columns corresponding to the input and join "
f"tables column names. However, the join argument provided is {col} of type {type(col)}" f"tables column names. However, the join argument provided is {col} of type {type(col)}"
) )

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

@ -265,6 +265,24 @@ class TestQuery(TestBase):
Query(t).take(2), kind=JoinKind.INNER).render Query(t).take(2), kind=JoinKind.INNER).render
) )
def test_join_wrong_arguments_type(self):
col_name_str = "numField"
# noinspection PyTypeChecker
self.assertRaises(
JoinException(
"A join argument could be a column, or a tuple of two columns corresponding to the input and join "
f"tables column names. However, the join argument provided is {col_name_str} of type {type(col_name_str)}"
),
lambda: (
Query(t)
.where(t.numField > 4)
.take(5)
.join(Query(t).take(2), kind=JoinKind.INNER)
.on(col_name_str)
.render()
)
)
def test_extend(self): def test_extend(self):
self.assertEqual( self.assertEqual(
"mock_table | extend sumField = numField + numField2, foo = numField3 * 4 | take 5", "mock_table | extend sumField = numField + numField2, foo = numField3 * 4 | take 5",