Skip to content

Commit

Permalink
reformat code
Browse files Browse the repository at this point in the history
Signed-off-by: Zhongnan Su <[email protected]>
  • Loading branch information
zhongnansu committed Nov 30, 2021
1 parent e5ec334 commit 24fe254
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 24 deletions.
10 changes: 4 additions & 6 deletions sql-cli/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
_version_re = re.compile(r"__version__\s+=\s+(.*)")

with open("src/opensearch_sql_cli/__init__.py", "rb") as f:
version = str(
ast.literal_eval(_version_re.search(f.read().decode("utf-8")).group(1))
)
version = str(ast.literal_eval(_version_re.search(f.read().decode("utf-8")).group(1)))

description = "OpenSearch SQL CLI with auto-completion and syntax highlighting"

Expand All @@ -38,8 +36,8 @@
version=version,
license="Apache 2.0",
url="https://docs-beta.opensearch.org/search-plugins/sql/cli/",
packages=find_packages('src'),
package_dir={'': 'src'},
packages=find_packages("src"),
package_dir={"": "src"},
package_data={"opensearch_sql_cli": ["conf/clirc", "opensearch_literals/opensearch_literals.json"]},
description=description,
long_description=long_description,
Expand All @@ -64,5 +62,5 @@
"Topic :: Software Development",
"Topic :: Software Development :: Libraries :: Python Modules",
],
python_requires='>=3.0'
python_requires=">=3.0",
)
16 changes: 4 additions & 12 deletions sql-cli/src/opensearch_sql_cli/opensearch_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ def get_aes_client(self):
region = session.region_name

if credentials is not None:
self.aws_auth = AWS4Auth(
credentials.access_key, credentials.secret_key, region, service
)
self.aws_auth = AWS4Auth(credentials.access_key, credentials.secret_key, region, service)
else:
click.secho(
message="Can not retrieve your AWS credentials, check your AWS config",
Expand Down Expand Up @@ -93,9 +91,7 @@ def get_opensearch_client(self):
return opensearch_client

def is_sql_plugin_installed(self, opensearch_client):
self.plugins = opensearch_client.cat.plugins(
params={"s": "component", "v": "true"}
)
self.plugins = opensearch_client.cat.plugins(params={"s": "component", "v": "true"})
sql_plugin_name_list = ["opensearch-sql"]
return any(x in self.plugins for x in sql_plugin_name_list)

Expand Down Expand Up @@ -133,9 +129,7 @@ def set_connection(self, is_reconnect=False):
# re-throw error
raise error
else:
click.secho(
message="Can not connect to endpoint %s" % self.endpoint, fg="red"
)
click.secho(message="Can not connect to endpoint %s" % self.endpoint, fg="red")
click.echo(repr(error))
sys.exit(0)

Expand All @@ -152,9 +146,7 @@ def handle_server_close_connection(self):
)
click.secho(repr(reconnection_err), err=True, fg="red")

def execute_query(
self, query, output_format="jdbc", explain=False, use_console=True
):
def execute_query(self, query, output_format="jdbc", explain=False, use_console=True):
"""
Handle user input, send SQL query and get response.
Expand Down
4 changes: 3 additions & 1 deletion sql-cli/src/opensearch_sql_cli/opensearchsql_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ def echo_via_pager(self, text, color=None):
click.echo(text, color=color)

def connect(self, endpoint, http_auth=None):
self.opensearch_executor = OpenSearchConnection(endpoint, http_auth, self.use_aws_authentication, self.query_language)
self.opensearch_executor = OpenSearchConnection(
endpoint, http_auth, self.use_aws_authentication, self.query_language
)
self.opensearch_executor.set_connection()

def _get_literals(self):
Expand Down
4 changes: 3 additions & 1 deletion sql-cli/tests/test_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ def test_format_output_vertical(self):
"age | 24",
]

with mock.patch("src.opensearch_sql_cli.main.click.secho") as mock_secho, mock.patch("src.opensearch_sql_cli.main.click.confirm") as mock_confirm:
with mock.patch("src.opensearch_sql_cli.main.click.secho") as mock_secho, mock.patch(
"src.opensearch_sql_cli.main.click.confirm"
) as mock_confirm:
expanded_results = formatter.format_output(data)

mock_secho.assert_called_with(message="Output longer than terminal width", fg="red")
Expand Down
11 changes: 8 additions & 3 deletions sql-cli/tests/test_opensearch_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ def test_connection_fail(self):
test_executor = OpenSearchConnection(endpoint=INVALID_ENDPOINT)
err_message = "Can not connect to endpoint %s" % INVALID_ENDPOINT

with mock.patch("sys.exit") as mock_sys_exit, mock.patch("src.opensearch_sql_cli.opensearch_connection.click.secho") as mock_secho:
with mock.patch("sys.exit") as mock_sys_exit, mock.patch(
"src.opensearch_sql_cli.opensearch_connection.click.secho"
) as mock_secho:
test_executor.set_connection()

mock_sys_exit.assert_called()
Expand Down Expand Up @@ -121,8 +123,11 @@ def test_get_od_client(self):
od_test_executor.get_opensearch_client()

mock_es.assert_called_with(
[OPENSEARCH_ENDPOINT], http_auth=AUTH, verify_certs=False, ssl_context=od_test_executor.ssl_context,
connection_class=RequestsHttpConnection
[OPENSEARCH_ENDPOINT],
http_auth=AUTH,
verify_certs=False,
ssl_context=od_test_executor.ssl_context,
connection_class=RequestsHttpConnection,
)

def test_get_aes_client(self):
Expand Down
4 changes: 3 additions & 1 deletion sql-cli/tests/test_opensearchsql_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ def cli(default_config_location):

class TestOpenSearchSqlCli:
def test_connect(self, cli):
with mock.patch.object(OpenSearchConnection, "__init__", return_value=None) as mock_OpenSearchConnection, mock.patch.object(
with mock.patch.object(
OpenSearchConnection, "__init__", return_value=None
) as mock_OpenSearchConnection, mock.patch.object(
OpenSearchConnection, "set_connection"
) as mock_set_connectiuon:
cli.connect(endpoint=ENDPOINT)
Expand Down

0 comments on commit 24fe254

Please sign in to comment.