[KYUUBI #4581] [TEST] Add KyuubiCommands parse python snippets unit test
### _Why are the changes needed?_ to resolve https://github.com/apache/kyuubi/pull/4333#issuecomment-1442793799 ### _How was this patch tested?_ - [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible - [ ] Add screenshots for manual tests if appropriate - [x] [Run test](https://kyuubi.readthedocs.io/en/master/develop_tools/testing.html#running-tests) locally before make a pull request Closes #4581 from cfmcgrady/beeline-parser-python-ut. Closes #4581 9bffa033b [Fu Chen] add KyuubiCommands parse python snippets unit test Authored-by: Fu Chen <cfmcgrady@gmail.com> Signed-off-by: Fu Chen <cfmcgrady@gmail.com>
This commit is contained in:
parent
06f3884627
commit
acdfa6ce1d
@ -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>
|
||||
|
||||
@ -19,6 +19,7 @@ package org.apache.hive.beeline;
|
||||
|
||||
import static org.apache.kyuubi.jdbc.hive.JdbcConnectionParams.*;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import java.io.*;
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
@ -277,7 +278,8 @@ public class KyuubiCommands extends Commands {
|
||||
* 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);
|
||||
|
||||
@ -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
pom.xml
8
pom.xml
@ -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>
|
||||
@ -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>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user