generated from godatadriven/python-devcontainer-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_sales_analysis.py
More file actions
26 lines (20 loc) · 793 Bytes
/
test_sales_analysis.py
File metadata and controls
26 lines (20 loc) · 793 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import pytest
from pyspark import Row
from pyspark.sql import DataFrame, SparkSession
from sales_analysis import calculate_sales_per_country
@pytest.fixture
def spark() -> SparkSession:
spark = SparkSession.builder.getOrCreate()
return spark
def test_calculate_sales_per_country(spark: SparkSession):
sales: DataFrame = spark.createDataFrame(
[
Row(country="The Netherlands", amount=30),
Row(country="The Netherlands", amount=50),
Row(country="The Netherlands", amount=20),
]
)
sales_per_country: DataFrame = calculate_sales_per_country(sales)
expected_sales: Row = Row(country="The Netherlands", total_sales=100)
actual_sales: Row = sales_per_country.collect()[0]
assert actual_sales == expected_sales