Beispiel #1
0
def test__templater_python_large_file_check():
    """Test large file skipping.

    The check is seperately called on each .process() method
    so it makes sense to test a few templaters.
    """
    # First check we can process the file normally without config.
    PythonTemplater().process(in_str="SELECT 1", fname="<string>")
    # Then check we raise a skip exception when config is set low.
    with pytest.raises(SQLFluffSkipFile) as excinfo:
        PythonTemplater().process(
            in_str="SELECT 1",
            fname="<string>",
            config=FluffConfig(overrides={
                "dialect": "ansi",
                "large_file_skip_char_limit": 2
            }, ),
        )

    assert "Length of file" in str(excinfo.value)
Beispiel #2
0
def test__templater_python_slice_file(raw_file, templated_file, unwrap_wrapped,
                                      result):
    """Test slice_file."""
    _, resp, _ = PythonTemplater().slice_file(
        raw_file,
        templated_file,
        config=FluffConfig(
            configs={"templater": {
                "unwrap_wrapped_queries": unwrap_wrapped
            }}),
    )
    # Check contigious
    prev_slice = None
    for templated_slice in resp:
        if prev_slice:
            assert templated_slice.source_slice.start == prev_slice[0].stop
            assert templated_slice.templated_slice.start == prev_slice[1].stop
        prev_slice = (templated_slice.source_slice,
                      templated_slice.templated_slice)
    # check result
    assert resp == result
Beispiel #3
0
def test__templater_python_error():
    """Test error handling in the python templater."""
    t = PythonTemplater(override_context=dict(noblah="foo"))
    instr = PYTHON_STRING
    with pytest.raises(SQLTemplaterError):
        t.process(in_str=instr)
Beispiel #4
0
def test__templater_python():
    """Test the python templater."""
    t = PythonTemplater(override_context=dict(blah="foo"))
    instr = PYTHON_STRING
    outstr, _ = t.process(in_str=instr)
    assert str(outstr) == "SELECT * FROM foo"