import pytest
class TestFunctionAPIs:
def test_current_date_is_function_not_method(self, spark):
from tests.fixtures.spark_imports import get_spark_imports
imports = get_spark_imports()
F = imports.F
df = spark.createDataFrame([{"id": 1}], ["id"])
result = df.withColumn("today", F.current_date())
assert result is not None
with pytest.raises(AttributeError):
df.current_date()
def test_current_timestamp_is_function_not_method(self, spark):
from tests.fixtures.spark_imports import get_spark_imports
imports = get_spark_imports()
F = imports.F
df = spark.createDataFrame([{"id": 1}], ["id"])
result = df.withColumn("now", F.current_timestamp())
assert result is not None
with pytest.raises(AttributeError):
df.current_timestamp()
def test_functions_are_static_methods(self, spark):
from tests.fixtures.spark_imports import get_spark_imports
imports = get_spark_imports()
F = imports.F
col_expr = F.col("id")
assert col_expr is not None
lit_expr = F.lit(42)
assert lit_expr is not None
count_func = F.count("id")
assert count_func is not None
row_num = F.row_number()
assert row_num is not None
def test_function_signatures_match_pyspark(self, spark):
from tests.fixtures.spark_imports import get_spark_imports
imports = get_spark_imports()
F = imports.F
df = spark.createDataFrame([{"id": 1, "value": 10}], ["id", "value"])
result = df.groupBy().agg(
F.count("id").alias("count"),
F.sum("value").alias("sum"),
F.current_date().alias("today"),
F.current_timestamp().alias("now"),
)
rows = result.collect()
assert len(rows) == 1