-
Notifications
You must be signed in to change notification settings - Fork 708
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add two functions that assist in testing a TypedPipe #1478
Conversation
* a list and run it through a function that makes arbitrary | ||
* assertions on it. | ||
*/ | ||
def checkOutput[T](output: TypedPipe[T])(assertions: List[T] => Unit) = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth having a flavor like
def checkOutputTransform[T, U](input: List[T])(transform: TypedPipe[T] => TypedPipe[U])(assertions: List[T] => Unit) =
assertions(checkOutputInline(transform(TypedPipe.from(input))))
Or doing TypedPipe.from we should leave to the test writer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure that actually may be nice to have.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function added
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment here: make the return generic please.
* Takes a List and a transform function. | ||
* The resulting TypedPipe form the transform will be run through asserts | ||
*/ | ||
def checkOutputTransform[T, U](input: List[T])(transform: TypedPipe[T] => TypedPipe[U])(assertions: List[U] => Unit) = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we put a return type on all methods?
also, what about mre general:
def checkOutputTransform[T, U, R](input: List[T])(transform: TypedPipe[T] => TypedPipe[U])(assertions: List[U] => R): R =
then you could use methods that return other than unit.
/** | ||
* Execute a TypedPipe in memory and return the result as a List | ||
*/ | ||
def checkOutputInline[T](output: TypedPipe[T]): List[T] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason not to call this inMemoryToList
or something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this name for this function. I kind of like idea of keeping the names for the others though since it really is just a nice to have utility function for running some asserts on a typed pipe and the name indicates that it probably should only be used for unit testing.
If you think it could be used outside of tests though we can try to think of some better names.
ready to merge, just some name bikeshedding. |
Is there any need for the checkOutputTransform part?
|
Mostly just a simple utility function. Not strictly needed. You could imagine have a function that checks a TypedPipe that you may want reuse on different tests so it could be a little cleaner to use the checkOutput function. Sometimes just having the function where you are doing the testing can make the test a little more readable. I can see the transform being useful when you have some function of TypedPipe[T] -> TypedPipe[U] and you want to test this. This is common in many of my real world tests. |
Add two functions that assist in testing a TypedPipe
Many times when testing a scalding job you just want to test a function that takes a TypedPipe and returns another TypedPipe. This can be difficult using JobTest. TypedPipeChecker makes use of Executions to pull the given TypedPipe into memory so that can asserts can be run against the resulting List.