-
Notifications
You must be signed in to change notification settings - Fork 382
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
jarek/7481: repr of scala unit object as MIMEContainer.HIDDEN #7694
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
83 changes: 83 additions & 0 deletions
83
kernel/scala/src/test/java/com/twosigma/beakerx/scala/evaluator/ScalaReprTest.java
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,83 @@ | ||
/* | ||
* Copyright 2017 TWO SIGMA OPEN SOURCE, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.twosigma.beakerx.scala.evaluator; | ||
|
||
import com.twosigma.beakerx.TryResult; | ||
import com.twosigma.beakerx.jvm.object.SimpleEvaluationObject; | ||
import com.twosigma.beakerx.kernel.KernelManager; | ||
import com.twosigma.beakerx.mimetype.MIMEContainer; | ||
import com.twosigma.beakerx.scala.TestScalaEvaluator; | ||
import com.twosigma.beakerx.scala.kernel.ScalaKernelMock; | ||
import org.junit.After; | ||
import org.junit.AfterClass; | ||
import org.junit.Before; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
import static com.twosigma.beakerx.MessageFactorTest.commMsg; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class ScalaReprTest { | ||
|
||
private static ScalaEvaluator scalaEvaluator; | ||
|
||
@BeforeClass | ||
public static void setUpClass() throws Exception { | ||
scalaEvaluator = TestScalaEvaluator.evaluator(); | ||
} | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
ScalaKernelMock kernel = new ScalaKernelMock("id", scalaEvaluator); | ||
KernelManager.register(kernel); | ||
} | ||
|
||
@After | ||
public void tearDown() throws Exception { | ||
KernelManager.register(null); | ||
} | ||
|
||
@AfterClass | ||
public static void tearDownClass() throws Exception { | ||
scalaEvaluator.exit(); | ||
} | ||
|
||
@Test | ||
public void unitObjectShouldBeRepresentedAsHIDDEN() { | ||
//given | ||
String code = "()"; | ||
SimpleEvaluationObject seo = new SimpleEvaluationObject(code); | ||
seo.setJupyterMessage(commMsg()); | ||
//when | ||
TryResult evaluate = scalaEvaluator.evaluate(seo, code); | ||
//then | ||
assertThat(((MIMEContainer) evaluate.result())).isEqualTo(MIMEContainer.HIDDEN); | ||
} | ||
|
||
@Test | ||
public void emptyStringShouldBeRepresentedAsEmptyString() { | ||
//given | ||
String code = "\"\""; | ||
SimpleEvaluationObject seo = new SimpleEvaluationObject(code); | ||
seo.setJupyterMessage(commMsg()); | ||
//when | ||
TryResult evaluate = scalaEvaluator.evaluate(seo, code); | ||
//then | ||
assertThat(evaluate.result()).isEqualTo(""); | ||
} | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The method name
isUnitObject
doesn't match what it actually does. MaybeisPrintStringEmpty
? (and then useisEmpty
instead ofequals("")
). Or just compare the value to()
and ignore the interpreter's notion of how things should be printed.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.
by isUnitObject I want to express whether the interpreter returns Unit object or not.
I used
val print = interpreter.lastRequest.lineRep.call (" $ print "). toString.trim print.equals ("")
because I have not found a better way to do this.The question is whether my solution meets the requirements and doesn't provide errors.
There is a test that checks if Unit object is represented by MIMEContainer.HIDDEN https://github.com/twosigma/beakerx/pull/7694/files#diff-7a177fbeb8a50f57cde772923fc6e1ccR60
if you know use cases which we should handle or you see problems with this solution, please let us know, your input is welcome.
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 just did some exploration and the behavior of the interpreter is surprising. Calling
$result
when the input is"()"
returnsnull
instead of a boxedUnit
, so looking at the result value alone is not a solution. I am persuaded that it makes sense to use$print
to decide whether to hide the result. That said, I still think the nameisUnitObject
is misleading, and would suggest changing it toshouldHideResult
. For a specific example, the input"(): Any"
gives a result that is a unit object (with a wider type), but the interpreter does not suppress the output in that case.