-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
64c3b7b
commit 98708f8
Showing
1 changed file
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,55 @@ | ||
from __future__ import annotations | ||
|
||
|
||
def test_print_schema(spark_session, capsys) -> None: | ||
def test_print_schema_range(spark_session, capsys) -> None: | ||
df = spark_session.range(10) | ||
df.printSchema() | ||
|
||
captured = capsys.readouterr() | ||
expected = "root\n" " |-- id: integer (nullable = true)\n\n" | ||
assert captured.out == expected | ||
|
||
|
||
def test_print_schema_simple_df(spark_session, capsys) -> None: | ||
data = [(1,), (2,), (3,)] | ||
df = spark_session.createDataFrame(data, ["value"]) | ||
df.printSchema() | ||
|
||
captured = capsys.readouterr() | ||
expected = "root\n" " |-- value: integer (nullable = true)\n\n" | ||
assert captured.out == expected | ||
|
||
|
||
def test_print_schema_multiple_columns(spark_session, capsys) -> None: | ||
data = [(1, "a", True), (2, "b", False)] | ||
df = spark_session.createDataFrame(data, ["id", "name", "flag"]) | ||
df.printSchema() | ||
|
||
captured = capsys.readouterr() | ||
expected = ( | ||
"root\n" | ||
" |-- id: integer (nullable = true)\n" | ||
" |-- name: string (nullable = true)\n" | ||
" |-- flag: boolean (nullable = true)\n\n" | ||
) | ||
assert captured.out == expected | ||
|
||
|
||
def test_print_schema_decimal(spark_session, capsys) -> None: | ||
data = [(1.23,), (4.56,)] | ||
df = spark_session.createDataFrame(data, ["amount"]) | ||
df.printSchema() | ||
|
||
captured = capsys.readouterr() | ||
expected = "root\n" " |-- amount: double (nullable = true)\n\n" | ||
assert captured.out == expected | ||
|
||
|
||
def test_print_schema_with_nulls(spark_session, capsys) -> None: | ||
data = [(1, None), (None, "test")] | ||
df = spark_session.createDataFrame(data, ["id", "value"]) | ||
df.printSchema() | ||
|
||
captured = capsys.readouterr() | ||
expected = "root\n" " |-- id: integer (nullable = true)\n" " |-- value: string (nullable = true)\n\n" | ||
assert captured.out == expected |