def test_multiple_strings_are_provided___result_is_join_by_join_str( join, elements): expected = join.join(elements) arg_elements = map(lambda o: f"'{o}'", elements) expr = f"join('{join}', {', '.join(arg_elements)})" assert run({}, expr) == expected
def test_multiple_objects_are_provided___result_is_join_by_join_str( join, elements): expected = join.join(map(str, elements)) arg_elements = map( lambda o: f"'{o}'" if isinstance(o, str) else str(o), elements, ) expr = f"join('{join}', {', '.join(arg_elements)})" assert run({}, expr) == expected
def test_lookup_function_with_escaped_quote_returns_row_column_value( name_lhs, name_rhs, value ): assert ( run( {f"{name_lhs}'{name_rhs}": value}, rf"lookup('{name_lhs}`'{name_rhs}')", ) == value )
def test_list_is_parsed_correctly(values): assert run({}, f"[{', '.join(map(str, values))}]") == values
def test_some_lhs_is_not_in_rhs___any_is_not_in_result_is_true(): assert run({}, "any [1, 2] is not in [0, 2, 4]") is True
def test_some_lhs_is_in_rhs___any_is_in_result_is_true(): assert run({}, "any [1, 2, 3] is in [0, 1, 4]") is True
def test_some_values_are_not_all_equal___any_is_result_is_true(): assert run({}, "any [1, 0.9, 0.8] is 0.9") is True
def test_some_values_are_gt_rhs___any_gte_result_is_true(): assert run({}, "any [1, 0.8] gte 0.9") is True
def test_some_values_are_gt_rhs___any_gt_result_is_true(): assert run({}, "any [0.8, 1.1] gt 0.9") is True
def test_some_values_are_eq_rhs___any_lte_result_is_true(): assert run({}, "any [1, 0.9] lte 1") is True
def test_string_addition(lhs, rhs): assert run({}, f"'{lhs}' + '{rhs}'") == lhs + rhs
def test_int_addition(lhs, rhs): assert run({}, f"{lhs} + {rhs}") == lhs + rhs
def test_no_args_are_provided___error_is_raised(): with pytest.raises(UnexpectedCharacters): run({}, "join()")
def test_no_strings_are_provided___result_is_empty(): assert run({}, "join(', ')") == ""
def test_regex_is_parsed_correctly(pattern): parsed = run({}, f"re'{pattern}'") assert isinstance(parsed, re.Pattern) assert parsed.pattern == pattern assert (parsed.flags & re.IGNORECASE) == 0
def test_some_values_are_lt___any_lt_result_is_true(): assert run({}, "any [1.1, 1, 0.9] lt 1") is True
def test_all_values_are_gte___any_lt_result_is_false(): assert run({}, "any [1.1, 1] lt 1") is False
def test_int_subtraction(lhs, rhs): assert run({}, f"{lhs} - {rhs}") == lhs - rhs
def test_all_values_are_gt_rhs___all_lte_result_is_false(): assert run({}, "any [1.1, 1.2] lte 1") is False
def test_int_multiplication(lhs, rhs): assert run({}, f"{lhs} * {rhs}") == lhs * rhs
def test_all_values_are_equal___any_gt_result_is_false(): assert run({}, "any [1, 1] gt 1") is False
def test_int_division(lhs, rhs): assert run({}, f"{lhs} / {rhs}") == lhs / rhs
def test_some_values_are_equal___any_gte_result_is_true(): assert run({}, "any [1, 0.9] gte 1") is True
def test_all_values_are_not_all_equal___any_is_result_is_false(): assert run({}, "any [1, 0.8] is 0.9") is False
def test_all_values_are_lt_rhs___any_gte_result_is_false(): assert run({}, "any [1, 0.9] gte 1.1") is False
def test_some_values_are_equal___any_is_not_result_is_true(): assert run({}, "any [1.1, 1, 0.9] is not 1") is True
def test_all_values_are_not_in_rhs___any_is_in_result_is_false(): assert run({}, "any [0, 1, 5, 6] is in [2, 3, 4]") is False
def test_all_values_are_lt_rhs___any_lt_result_is_true(): assert run({}, "any [0.9, 0.8] lt 1") is True
def test_all_values_are_in_rhs___any_is_not_in_result_is_false(): assert run({}, "any [2, 4] is not in [0, 1, 2, 3, 4]") is False
def test_values_are_all_equal___any_is_result_is_true(): assert run({}, "any [1, 1] is 1") is True