forked from FRosner/drunken-data-quality
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request FRosner#131 from Gerrrr/issue/111
Check if the ddq jar is available in pyddq
- Loading branch information
Showing
5 changed files
with
72 additions
and
26 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class JavaClassNotFoundException(Exception): | ||
""" | ||
Raise if required Java class is not found by py4j | ||
""" | ||
|
||
def __init__(self, java_class): | ||
Exception.__init__(self) | ||
self.java_class = java_class | ||
|
||
def __str__(self): | ||
return "%s. Did you forget to add the jar to the class path?" % ( | ||
self.java_class | ||
) | ||
|
||
def __repr__(self): | ||
return "%s: %s" % (self.__class__.__name__, self.java_class) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,52 @@ | ||
import unittest | ||
from mock import Mock | ||
from mock import Mock, call | ||
from pyddq.core import Check | ||
|
||
from pyddq.exceptions import JavaClassNotFoundException | ||
from utils import get_df | ||
|
||
class ConstructorTest(unittest.TestCase): | ||
def setUp(self): | ||
self.df = get_df() | ||
|
||
def test_default_args(self): | ||
df = Mock() | ||
check = Check(df) | ||
ddq_check = check._jvm.de.frosner.ddq.core.Check | ||
ddq_check.assert_called_with( | ||
df._jdf, | ||
getattr(ddq_check, "apply$default$2")(), | ||
getattr(ddq_check, "apply$default$3")(), | ||
getattr(ddq_check, "apply$default$4")(), | ||
getattr(ddq_check, "apply$default$5")(), | ||
) | ||
check = Check(self.df) | ||
ddq_core = check._jvm.de.frosner.ddq.core | ||
ddq_check = ddq_core.Check | ||
|
||
ddq_core.assert_has_calls([ | ||
call.Check( | ||
self.df._jdf, | ||
getattr(ddq_check, "apply$default$2")(), | ||
getattr(ddq_check, "apply$default$3")(), | ||
getattr(ddq_check, "apply$default$4")(), | ||
getattr(ddq_check, "apply$default$5")() | ||
) | ||
]) | ||
|
||
def test_passed_args(self): | ||
df = Mock() | ||
display_name = Mock() | ||
cache_method = Mock() | ||
id = Mock() | ||
|
||
df._sc._jvm.scala.Some.apply = Mock( | ||
self.df._sc._jvm.scala.Some.apply = Mock( | ||
side_effect=["Some(displayName)", "Some(cacheMethod)"] | ||
) | ||
check = Check(df, display_name, cache_method, id) | ||
check = Check(self.df, display_name, cache_method, id) | ||
ddq_core = check._jvm.de.frosner.ddq.core | ||
ddq_check = check._jvm.de.frosner.ddq.core.Check | ||
|
||
ddq_check.assert_called_with( | ||
df._jdf, | ||
"Some(displayName)", | ||
"Some(cacheMethod)", | ||
getattr(ddq_check, "apply$default$4")(), | ||
id | ||
) | ||
ddq_core.assert_has_calls([ | ||
call.Check( | ||
self.df._jdf, | ||
"Some(displayName)", | ||
"Some(cacheMethod)", | ||
getattr(ddq_check, "apply$default$4")(), | ||
id | ||
) | ||
]) | ||
|
||
def test_ddq_jar(self): | ||
self.assertRaises(JavaClassNotFoundException, Check, Mock()) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from mock import Mock | ||
from py4j.java_gateway import JavaClass | ||
|
||
def get_df(): | ||
df = Mock() | ||
df._sc._jvm.de.frosner.ddq.core.Check = Mock(spec=JavaClass) | ||
setattr(df._sc._jvm.de.frosner.ddq.core.Check, "apply$default$2", Mock()) | ||
setattr(df._sc._jvm.de.frosner.ddq.core.Check, "apply$default$3", Mock()) | ||
setattr(df._sc._jvm.de.frosner.ddq.core.Check, "apply$default$4", Mock()) | ||
setattr(df._sc._jvm.de.frosner.ddq.core.Check, "apply$default$5", Mock()) | ||
return df |