Last active
February 1, 2019 09:44
-
-
Save afranzi/55ceb66bac95c8dbd66b47cb47e1d0bb 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 | |
import pytest | |
from pyspark.sql.types import StringType | |
@pytest.fixture(scope='function', autouse=True) | |
def mock_udf_annotation(monkeypatch): | |
def dummy_udf(f): | |
return f | |
def mock_udf(f=None, returnType=StringType()): | |
return f if f else dummy_udf | |
monkeypatch.setattr('pyspark.sql.functions.udf', mock_udf) | |
class TestUDFs(TestCase): | |
def test_upper(self): | |
""" | |
@udf(returnType=ArrayType(StringType())) | |
def to_upper_list(s): | |
return [i.upper() for i in s] | |
""" | |
from our_package.spark import udfs as UDF | |
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