def test_invalid_scalars() -> None: translator = Translation() with pytest.raises( InvalidExpressionError, match=re.escape("tuple/array must contain only scalar values"), ): translator._stringify_scalar(({"a": 1}, {1, 2, 3})) # type: ignore with pytest.raises( InvalidExpressionError, match=re.escape("tuple/array must contain only scalar values"), ): translator._stringify_scalar([{"a": 1}, {1, 2, 3}]) # type: ignore
def test_scalars(scalar: ScalarType, expected: str) -> None: translator = Translation() assert translator._stringify_scalar(scalar) == expected, scalar
def __init__(self, pretty: bool = False, is_inner: bool = False) -> None: self.translator = Translation() self.pretty = pretty self.is_inner = is_inner
), id="alias must be string", ), pytest.param( Column("stuff"), "what???||things!!", None, InvalidExpressionError( "alias 'what???||things!!' of expression contains invalid characters" ), id="alias has invalid characters", ), ] TRANSLATOR = Translation(use_entity_aliases=True) @pytest.mark.parametrize("exp, alias, translated, exception", tests) def test_aliased_expression( exp: Column, alias: Optional[str], translated: str, exception: Optional[Exception], ) -> None: if exception is not None: with pytest.raises(type(exception), match=re.escape(str(exception))): AliasedExpression(exp, alias) else: aliased = AliasedExpression(exp, alias) assert TRANSLATOR.visit(aliased) == translated
), id="op invalid type", ), pytest.param( cond(Column("foo"), Op.EQ, Op.EQ), None, "", InvalidConditionError( "invalid condition: RHS of a condition must be a Column, CurriedFunction, Function or Scalar not <enum 'Op'>" ), id="rhs invalid type", ), ] TRANSLATOR = Translation() @pytest.mark.parametrize("cond_wrapper, valid, translated, exception", tests) def test_conditions( cond_wrapper: Callable[[], Any], valid: Optional[Condition], translated: Optional[str], exception: Optional[Exception], ) -> None: def verify() -> None: exp = cond_wrapper() assert exp == valid assert TRANSLATOR.visit(exp) == translated if exception is not None: