Skip to content

Commit

Permalink
add KyuubiCommands parse python snippets unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
cfmcgrady committed Mar 22, 2023
1 parent 06f3884 commit 9bffa03
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
6 changes: 6 additions & 0 deletions kyuubi-hive-beeline/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@
<artifactId>commons-io</artifactId>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import static org.apache.kyuubi.jdbc.hive.JdbcConnectionParams.*;

import com.google.common.annotations.VisibleForTesting;
import java.io.*;
import java.sql.*;
import java.util.*;
Expand Down Expand Up @@ -277,7 +278,8 @@ private boolean execute(String line, boolean call, boolean entireLineAsCommand)
* quotations. It iterates through each character in the line and checks to see if it is a ;, ',
* or "
*/
private List<String> getCmdList(String line, boolean entireLineAsCommand) {
@VisibleForTesting
public List<String> getCmdList(String line, boolean entireLineAsCommand) {
List<String> cmdList = new ArrayList<String>();
if (entireLineAsCommand) {
cmdList.add(line);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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.hive.beeline;

import static org.junit.Assert.assertEquals;

import java.io.IOException;
import java.util.List;
import jline.console.ConsoleReader;
import org.junit.Test;
import org.mockito.Mockito;

public class KyuubiCommandsTest {
@Test
public void testParsePythonSnippets() throws IOException {
ConsoleReader reader = Mockito.mock(ConsoleReader.class);
String pythonSnippets = "for i in [1, 2, 3]:\n" + " print(i)\n";
Mockito.when(reader.readLine()).thenReturn(pythonSnippets);

KyuubiBeeLine beeline = new KyuubiBeeLine();
beeline.setConsoleReader(reader);
KyuubiCommands commands = new KyuubiCommands(beeline);
String line = commands.handleMultiLineCmd(pythonSnippets);

List<String> cmdList = commands.getCmdList(line, false);
assertEquals(cmdList.size(), 1);
assertEquals(cmdList.get(0), pythonSnippets);
}
}
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@
<ldapsdk.version>6.0.5</ldapsdk.version>
<log4j.version>2.20.0</log4j.version>
<mysql.jdbc.version>8.0.32</mysql.jdbc.version>
<mockito.version>4.6.1</mockito.version>
<netty.version>4.1.89.Final</netty.version>
<openai.java.version>0.11.1</openai.java.version>
<parquet.version>1.10.1</parquet.version>
Expand Down Expand Up @@ -1109,6 +1110,13 @@
<version>${scalatestplus.version}</version>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down

0 comments on commit 9bffa03

Please sign in to comment.