-
Notifications
You must be signed in to change notification settings - Fork 701
Add two functions that assist in testing a TypedPipe #1478
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package com.twitter.scalding | ||
|
|
||
| /** | ||
| * This class is used to assist with testing a TypedPipe | ||
| */ | ||
| object TypedPipeChecker { | ||
|
|
||
| /* | ||
| * Takes a List and a transform function. | ||
| * The resulting TypedPipe form the transform will be run through asserts | ||
| */ | ||
| def checkOutputTransform[T, U, R](input: List[T])(transform: TypedPipe[T] => TypedPipe[U])(assertions: List[U] => R): R = | ||
| assertions(inMemoryToList(transform(TypedPipe.from(input)))) | ||
|
|
||
| /* | ||
| * Execute a TypedPipe in memory, convert the resulting Iterator to | ||
| * a list and run it through a function that makes arbitrary | ||
| * assertions on it. | ||
| */ | ||
| def checkOutput[T, R](output: TypedPipe[T])(assertions: List[T] => R): R = | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mentioned above, I don't mind this name too much since it indicates that it should probably only be used for tests. With mapAll we should also warn that it pulls everything into memory. mapAllAsList? If we can imagine people using this function in normal jobs it may be worthwhile to think about other names. |
||
| assertions(inMemoryToList(output)) | ||
|
|
||
| /** | ||
| * Execute a TypedPipe in memory and return the result as a List | ||
| */ | ||
| def inMemoryToList[T](output: TypedPipe[T]): List[T] = | ||
| output | ||
| .toIterableExecution | ||
| .waitFor(Config.unitTestDefault, Local(strictSources = true)) | ||
| .get | ||
| .toList | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package com.twitter.scalding | ||
|
|
||
| import org.scalatest.{ Matchers, WordSpec } | ||
|
|
||
| class TypedPipeCheckerTest extends WordSpec with Matchers { | ||
| import TypedPipeChecker._ | ||
|
|
||
| "TypedPipeChecker" should { | ||
| "run asserts on pipe" in { | ||
| checkOutput(TypedPipe.from(List(1, 2, 3, 4))){ rows => | ||
| assert(rows.size == 4) | ||
| assert(rows == List(1, 2, 3, 4)) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| it should { | ||
| "give back a list" in { | ||
| val list = inMemoryToList(TypedPipe.from(List(1, 2, 3, 4))) | ||
| assert(list == List(1, 2, 3, 4)) | ||
| } | ||
| } | ||
|
|
||
| it should { | ||
| "allow for a list of input to be run through a transform function" in { | ||
| def transform(pipe: TypedPipe[Int]) = pipe.map(identity) | ||
|
|
||
| checkOutputTransform(List(1, 2, 3))(transform){ rows => | ||
| assert(rows == List(1, 2, 3)) | ||
| } | ||
| } | ||
| } | ||
| } |
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.
def transformMapAll? as a name hereThere 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 point as checkOutput.