from __future__ import annotations
import pytest
from sparkless.testing import Mode, get_mode
from sparkless.testing import get_imports
imports = get_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_mode() == Mode.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