Esempio n. 1
0
def test_render_datetime_roundtrip():
    dt1 = datetime.datetime(2020, 6, 17, 18, 38, 1)
    dt2 = datetime.datetime(2020, 6, 17, 18, 41, 1)
    df = DataFrame({"dt": [dt1, dt2]})
    result = render(df, {"sql": "SELECT dt FROM input"})
    expected = (DataFrame({"dt": [dt1, dt2]}), "")

    assert result[1] == []
    assert_frame_equal(result[0], expected[0])
Esempio n. 2
0
def test_render_duplicate_column_name():
    df = DataFrame({"A": [1, 2, 3]})
    result = render(df, {"sql": "SELECT A, A FROM input"})
    assert result == (
        None,
        [
            i18n_message("badValue.sql.duplicateColumnName", {"colname": "A"}),
        ],
    )
Esempio n. 3
0
def test_render_hint_invalid_table_name():
    df = DataFrame({"foo": [1, 2, 3]})
    result = render(df, {"sql": "SELECT * FROM input2"})
    assert result == (
        None,
        [
            i18n_message("badValue.sql.invalidTableName",
                         {"table_name": "input"})
        ],
    )
Esempio n. 4
0
def test_two_statements_in_one():
    df = DataFrame({"A": [1, 2, 3]})
    result = render(df, {"sql": "SELECT A FROM input; SELECT A FROM input"})
    assert result == (None, [i18n_message("badValue.sql.tooManyCommands")])
Esempio n. 5
0
def test_render_empty_input():
    df = DataFrame()
    result = render(df, {"sql": "SELECT * FROM input"})
    assert result[1] == []
    assert_frame_equal(result[0], DataFrame())
Esempio n. 6
0
def test_render_invalid_sql_syntax():
    df = DataFrame({"foo": [1, 2, 3]})
    result = render(df, {"sql": "This is not SQL"})
    assert result == (None, ['SQL error near "This": syntax error'])
Esempio n. 7
0
def test_render_commented_sql():
    df = DataFrame({"foo": [1, 2, 3]})
    result = render(df, {"sql": "-- SELECT * FROM input"})
    assert result == (None, [i18n_message("badValue.sql.commentedQuery")])
Esempio n. 8
0
def test_render_empty_sql():
    df = DataFrame({"foo": [1, 2, 3]})
    result = render(df, {"sql": ""})
    assert result == (None, [i18n_message("badParam.sql.missing")])
Esempio n. 9
0
def test_render_str_roundtrip():
    df = DataFrame({"A": ["b", "c", "dé"]})
    result = render(df, {"sql": "SELECT * FROM input"})
    assert result[1] == []
    assert_frame_equal(result[0], df)
Esempio n. 10
0
def test_render_happy_path():
    df = DataFrame({"foo": [1, 2, 3], "bar": [2, 3, 4]})
    result = render(df, {"sql": "SELECT foo + bar AS baz FROM input"})
    assert result[1] == []
    assert_frame_equal(result[0], DataFrame({"baz": [3, 5, 7]}), [])