Example #1
0
    def test_api_level_missing(self) -> None:
        with pytest.raises(ParseError, match="missing header: api-level"):
            parse_sql_stream(
                StringIO("""-- Schema: my-schema
-- Dialect: sqlite
-- Version: 3
            """),
                "",
            )
Example #2
0
    def test_schema_missing(self) -> None:
        with pytest.raises(ParseError, match="missing header: schema"):
            parse_sql_stream(
                StringIO("""-- Dialect: sqlite
-- Version: 13
-- API-Level: 3
            """),
                "",
            )
Example #3
0
    def test_version_missing(self) -> None:
        with pytest.raises(ParseError, match="missing header: version"):
            parse_sql_stream(
                StringIO("""-- Schema: my-schema
-- Dialect: sqlite
-- API-Level: 3
            """),
                "",
            )
Example #4
0
    def test_dialect_missing(self) -> None:
        with pytest.raises(ParseError, match="missing header: dialect"):
            parse_sql_stream(
                StringIO("""-- Schema: my-schema
-- Version: 13
-- API-Level: 3
            """),
                "",
            )
Example #5
0
    def test_ignore_headers_after_break(self) -> None:
        with pytest.raises(ParseError, match="missing header: api-level"):
            parse_sql_stream(
                StringIO("""-- Schema: my-schema
-- Dialect: sqlite
-- Version: 13

-- API-Level: 3
        """),
                "",
            )
Example #6
0
    def test_api_level_is_not_an_int(self) -> None:
        with pytest.raises(ParseError,
                           match="header is not an integer: api-level"):
            parse_sql_stream(
                StringIO("""-- Schema: my-schema
-- Dialect: sqlite
-- Version: 24
-- API-Level: INVALID
            """),
                "",
            )
Example #7
0
    def test_transaction_invalid(self) -> None:
        with pytest.raises(ParseError,
                           match="header must be 'yes' or 'no': transaction"):
            parse_sql_stream(
                StringIO("""-- Schema: my-schema
-- Dialect: sqlite
-- Version: 25
-- API-Level: 3
-- Transaction: INVALID
            """),
                "",
            )
Example #8
0
    def test_transaction_no(self) -> None:
        info = parse_sql_stream(
            StringIO("""-- Schema: my-schema
-- Dialect: sqlite
-- Version: 25
-- API-Level: 3
-- Transaction: no
            """),
            "",
        )
        assert not info.transaction
Example #9
0
    def test_required_headers(self) -> None:
        info = parse_sql_stream(
            StringIO("""-- Schema: my-schema
-- Dialect: sqlite
-- Version: 13
-- API-Level: 3

UPDATE foo SET bar = 99;
        """),
            "/foo/bar",
        )
        assert info.filename == "/foo/bar"
        assert info.schema == "my-schema"
        assert info.dialect == "sqlite"
        assert info.version == 13
        assert info.api_level == 3
        assert info.transaction