aglinxinyuan commented on code in PR #5952: URL: https://github.com/apache/texera/pull/5952#discussion_r3480256170
########## 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: Good observation — added two cases: one sets `groundTruthAttribute` to an INTEGER input column and asserts the result column inherits that type (not STRING), and one asserts the unguarded `.get` throws `NoSuchElementException` when the ground-truth attribute is absent from the input schema. Mirrors the both-branch coverage in SklearnTestingOpDescSpec. -- 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]
