eugenegujing commented on code in PR #9042:
URL: https://github.com/apache/texera/pull/9042#discussion_r4572986988
##########
common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/visualization/volcanoPlot/VolcanoPlotOpDescSpec.scala:
##########
@@ -68,6 +81,124 @@ class VolcanoPlotOpDescSpec extends AnyFlatSpec with
Matchers {
decodeOccurrences should be >= 2
}
+ private def decodeSites(code: String): Int =
+ "decode_python_template".r.findAllIn(code).length
+
+ it should "keep the first column as the hover label when no hover column is
set" in {
+ val code = configured.generatePythonCode()
+ code should include("hover_name=table.columns[0],")
+ // An empty field adds no decode site of its own, and nothing to check for.
+ code should not include "hover_name=self.decode_python_template("
+ code should not include "Missing hover column"
+ }
+
+ it should "answer a set hover column that the table lacks with the
operator's error page" in {
+ // Like the two required columns, and unlike plotly's uncaught ValueError.
+ val op = configured
+ op.hoverName = "gene"
+ val code = op.generatePythonCode()
+ code should include(s"if ${decoded("gene")} not in table.columns:")
+ code should include("""self.render_error("Missing hover column in
table.")""")
+ }
+
+ it should "treat a whitespace-only hover column as empty" in {
+ Seq(" ", "\t", " \n ").foreach { blank =>
+ val op = configured
+ op.hoverName = blank
+ val code = op.generatePythonCode()
+ code should include("hover_name=table.columns[0],")
+ code should not include "Missing hover column"
+ code should not include decoded(blank)
+ }
+ }
+
+ it should "use the configured hover column instead of the first column" in {
+ val op = configured
+ op.hoverName = "gene"
+ val code = op.generatePythonCode()
+ code should include(s"hover_name=${decoded("gene")},")
+ code should not include "hover_name=table.columns[0]"
+ // Exactly two decode sites more than the default: the presence check and
the
+ // hover_name argument, both naming the hover column.
+ decodeSites(code) shouldBe decodeSites(configured.generatePythonCode()) + 2
+ }
+
+ it should "route a hover column with quotes and non-ASCII text through the
decoder" in {
+ val op = configured
+ op.hoverName = "HOVER_SENT \"gene\" 基因"
+ val code = op.generatePythonCode()
+ code should include(s"hover_name=${decoded(op.hoverName)},")
+ code should not include "HOVER_SENT"
+ }
+
+ it should "render a workflow saved before this change exactly as a
default-constructed operator" in {
+ val saved = objectMapper
+ .readValue(
+
"""{"operatorType":"VolcanoPlot","effectColumn":"log2fc","pvalueColumn":"pvalue"}""",
+ classOf[LogicalOp]
+ )
+ .asInstanceOf[VolcanoPlotOpDesc]
+ val code = saved.generatePythonCode()
+ code shouldBe configured.generatePythonCode()
+ code should include("hover_name=table.columns[0],")
+ code should not include "Missing hover column"
+ }
+
+ "VolcanoPlotOpDesc.generateStandaloneCode" should "keep the first column as
the hover label when no hover column is set" in {
+ val code = configured.generateStandaloneCode()
+ code should include("hover_name=table.columns[0],")
+ code should not include "Missing hover column"
+ }
+
+ it should "use the configured hover column as a literal and check that the
table has it" in {
+ val op = configured
+ op.hoverName = "gene"
+ val code = op.generateStandaloneCode()
+ code should include("""hover_name="gene",""")
+ code should not include "hover_name=table.columns[0]"
+ // One more branch of the script's column checks, before the row filter and
+ // right before the drawing branch, so a missing hover column gets the
error
+ // page and not plotly's ValueError.
+ code should include(
+ """ output.write(render_error("Missing required columns in
table."))
+ |elif "gene" not in in1df.columns:
+ | with open(outputHtml, "w", encoding="utf-8") as output:
+ | output.write(render_error("Missing hover column in table."))
+ |else:""".stripMargin
+ )
+ }
+
+ it should "escape a hover column with quotes or a backslash rather than
decode it" in {
+ // The export has no decoder, so the name itself is in the script: a quote
or a
+ // backslash must come out escaped, or the literal would end early.
+ val op = configured
+ op.hoverName = "HOVER_SENT \"gene\" 基因"
+ val code = op.generateStandaloneCode()
+ code should include("hover_name=\"HOVER_SENT \\\"gene\\\" 基因\",")
+ code should include("elif \"HOVER_SENT \\\"gene\\\" 基因\" not in
in1df.columns:")
+ code should not include "decode_python_template"
+ op.hoverName = "gene\\id"
+ op.generateStandaloneCode() should include("hover_name=\"gene\\\\id\",")
+ }
+
+ it should "treat a whitespace-only hover column as empty" in {
+ Seq(" ", "\t", " \n ").foreach { blank =>
+ val op = configured
+ op.hoverName = blank
+ op.generateStandaloneCode() shouldBe configured.generateStandaloneCode()
+ }
+ }
+
+ it should "render a workflow saved before this change exactly as a
default-constructed operator" in {
+ val saved = objectMapper
+ .readValue(
+
"""{"operatorType":"VolcanoPlot","effectColumn":"log2fc","pvalueColumn":"pvalue"}""",
+ classOf[LogicalOp]
+ )
+ .asInstanceOf[VolcanoPlotOpDesc]
+ saved.generateStandaloneCode() shouldBe configured.generateStandaloneCode()
+ }
Review Comment:
Fixed in bbc08a2561d72a5aa9f457ff5acba16d0e9c1fb3.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]