from __future__ import annotations
import pytest
from tests.fixtures.spark_backend import BackendType, get_backend_type
from tests.fixtures.spark_imports import get_spark_imports
imports = get_spark_imports()
SparkSession = imports.SparkSession
try:
from sparkless import SparklessError
except ImportError:
SparklessError = RuntimeError
def test_createDataFrame_invalid_data_raises_pyspark_like_error(spark):
if get_backend_type() == BackendType.PYSPARK:
pytest.skip("Test for sparkless error shape; PySpark has its own message")
with pytest.raises((SparklessError, RuntimeError, TypeError)) as exc_info:
spark.createDataFrame("invalid_data", "id INT")
msg = str(exc_info.value)
if "CANNOT_ACCEPT_OBJECT" in msg or "can not accept object" in msg:
assert "StructType" in msg or "struct" in msg.lower()
assert "str" in msg
else:
assert "data must be a list" in msg or "list" in msg