Created
February 1, 2019 09:53
-
-
Save afranzi/6149ff5943dc8f876031ceaf005c6252 to your computer and use it in GitHub Desktop.
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
from unittest import TestCase | |
def dummy_udf(f): | |
return f | |
def mock_udf(f=None, returnType=None): | |
return f if f else dummy_udf | |
from mock import patch | |
patch('pyspark.sql.functions.udf', mock_udf).start() | |
from our_package.spark import udfs as UDF | |
class TestUDFs(TestCase): | |
def test_upper(self): | |
""" | |
@udf(returnType=ArrayType(StringType())) | |
def to_upper_list(s): | |
return [i.upper() for i in s] | |
""" | |
self.assertEqual(UDF.to_upper_list(['potato', 'carrot', 'tomato']), ['POTATO', 'CARROT', 'TOMATO']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment