mengw15 commented on code in PR #5952:
URL: https://github.com/apache/texera/pull/5952#discussion_r3480203751


##########
common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/sklearn/SklearnPredictionOpDescSpec.scala:
##########
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.texera.amber.operator.sklearn
+
+import org.apache.texera.amber.core.tuple.{AttributeType, Schema}
+import org.apache.texera.amber.core.workflow.PortIdentity
+import org.apache.texera.amber.operator.LogicalOp
+import org.apache.texera.amber.operator.metadata.OperatorGroupConstants
+import org.apache.texera.amber.util.JSONUtils.objectMapper
+import org.scalatest.flatspec.AnyFlatSpec
+import org.scalatest.matchers.should.Matchers
+
+class SklearnPredictionOpDescSpec extends AnyFlatSpec with Matchers {
+
+  "SklearnPredictionOpDesc.operatorInfo" should
+    "advertise the name, Sklearn group, and a model/data 2-in 1-out shape" in {
+    val info = (new SklearnPredictionOpDesc).operatorInfo
+    info.userFriendlyName shouldBe "Sklearn Prediction"
+    info.operatorDescription shouldBe "Sklearn Prediction Operator"
+    info.operatorGroupName shouldBe OperatorGroupConstants.SKLEARN_GROUP
+    info.inputPorts should have length 2
+    info.inputPorts.head.displayName shouldBe "model"
+    info.outputPorts should have length 1
+  }
+
+  "SklearnPredictionOpDesc" should "default its attribute fields" in {
+    val d = new SklearnPredictionOpDesc
+    d.model shouldBe null
+    d.resultAttribute shouldBe null
+    d.groundTruthAttribute shouldBe ""
+  }
+
+  "SklearnPredictionOpDesc.getOutputSchemas" should
+    "append the result attribute to the data (port 1) schema" in {
+    val d = new SklearnPredictionOpDesc
+    d.resultAttribute = "prediction"
+    val data = Schema().add("feature", AttributeType.STRING)
+    val out = d.getOutputSchemas(Map(PortIdentity(1) -> data))
+    val schema = out(d.operatorInfo.outputPorts.head.id)
+    schema.getAttribute("feature").getType shouldBe AttributeType.STRING
+    schema.getAttribute("prediction").getType shouldBe AttributeType.STRING
+  }
+
+  "SklearnPredictionOpDesc.generatePythonCode" should "emit the model-applying 
tuple operator" in {
+    val d = new SklearnPredictionOpDesc
+    d.model = "model"
+    d.resultAttribute = "prediction"
+    val code = d.generatePythonCode()

Review Comment:
   Branch coverage gap: this test pins `getOutputSchemas` for the **default** 
`groundTruthAttribute == ""` branch (result column type forced to STRING). The 
other branch in the source —
   
   ```scala
   if (groundTruthAttribute != "") {
     resultType = inputSchema.attributes.find(attr => attr.getName == 
groundTruthAttribute).get.getType
   }
   ```
   
   — is the more interesting one: result column type is derived from the input 
schema's `groundTruthAttribute` column type (so could be INTEGER, DOUBLE, 
BOOLEAN, etc., not just STRING). Worth a second case that sets 
`groundTruthAttribute` and asserts the result column inherits the right type.
   
   Also notice the unguarded `.get` on `attributes.find(...)` — if 
`groundTruthAttribute` is set to a name that doesn't exist in the input schema, 
that throws `NoSuchElementException`. The `SklearnTestingOpDescSpec` in this 
same PR covers both its classification/regression branches; pulling the same 
care over here would round it out.



-- 
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]

Reply via email to