class_docstr: Database write tests that share common pytest/parametrize options.
class_docstr_tok: ["Database","write","tests","that","share","common","pytest\/parametrize","options","."]
docstr: Confirm that expected errors are raised.
docstr_tok: ["Confirm","that","expected","errors","are","raised","."]
code: def test_write_database_errors(
      self, engine: DbWriteEngine, tmp_path: Path
  ) -> None:
      """Confirm that expected errors are raised."""
      df = pl.DataFrame({"colx": [1, 2, 3]})
  
      with pytest.raises(
          ValueError,
          match="`table_name` appears to be invalid: 'w.x.y.z'",
      ):
          df.write_database(
              connection="sqlite:///:memory:",
              table_name="w.x.y.z",
              engine=engine,
          )
  
      with pytest.raises(
          ValueError,
          match="`if_table_exists` must be one of .* got 'do_something'",
      ):
          df.write_database(
              connection="sqlite:///:memory:",
              table_name="main.test_errs",
              if_table_exists="do_something",  # type: ignore[arg-type]
              engine=engine,
          )
  
file_path: polars/py-polars/tests/unit/io/test_database_write.py
imports: from __future__ import annotations
  import sys
  from typing import TYPE_CHECKING
  import pytest
  from sqlalchemy import create_engine
  import polars
  from polars.testing import assert_frame_equal
label_desc: Use image node_id 4 for calling the TestWriteDatabase obj's underlying member method code with example usage: obj.test_write_database_errors(engine, tmp_path) without return types