-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_pyspark_task.py
More file actions
34 lines (26 loc) · 975 Bytes
/
test_pyspark_task.py
File metadata and controls
34 lines (26 loc) · 975 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
27
28
29
30
31
32
33
34
from pyspark_task import get_product_category_pairs
def test_get_product_category_pairs(spark):
products_df = spark.createDataFrame([
{"id": 1, "name": "Laptop"},
{"id": 2, "name": "Phone"},
{"id": 3, "name": "Mouse"},
])
categories_df = spark.createDataFrame([
{"id": 10, "name": "Electronics"},
{"id": 20, "name": "Accessories"},
])
product_category_df = spark.createDataFrame([
{"product_id": 1, "category_id": 10},
{"product_id": 3, "category_id": 20},
])
result_df = get_product_category_pairs(
products_df, categories_df, product_category_df
)
result = {(row["product_name"], row["category_name"]) for row in result_df.collect()}
expected = {
("Laptop", "Electronics"),
("Phone", None),
("Mouse", "Accessories"),
}
assert result == expected
# Для теста в терминале ввести: pytest test_pyspark_task.py