forked from LearningJournal/Spark-Programming-In-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRowDemo_Test.py
More file actions
35 lines (26 loc) · 1.11 KB
/
RowDemo_Test.py
File metadata and controls
35 lines (26 loc) · 1.11 KB
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
35
from datetime import date
from unittest import TestCase
from pyspark.sql import *
from pyspark.sql.types import *
from RowDemo import to_date_df
class RowDemoTestCase(TestCase):
@classmethod
def setUpClass(cls) -> None:
cls.spark = SparkSession.builder \
.master("local[3]") \
.appName("RowDemoTest") \
.getOrCreate()
my_schema = StructType([
StructField("ID", StringType()),
StructField("EventDate", StringType())])
my_rows = [Row("123", "04/05/2020"), Row("124", "4/5/2020"), Row("125", "04/5/2020"), Row("126", "4/05/2020")]
my_rdd = cls.spark.sparkContext.parallelize(my_rows, 2)
cls.my_df = cls.spark.createDataFrame(my_rdd, my_schema)
def test_data_type(self):
rows = to_date_df(self.my_df, "M/d/y", "EventDate").collect()
for row in rows:
self.assertIsInstance(row["EventDate"], date)
def test_date_value(self):
rows = to_date_df(self.my_df, "M/d/y", "EventDate").collect()
for row in rows:
self.assertEqual(row["EventDate"], date(2020, 4, 5))