Skip to content

Commit df3efa5

Browse files
fixing mypy errors
Signed-off-by: Emanuele Lanuti <[email protected]>
1 parent e7ee843 commit df3efa5

File tree

4 files changed

+49
-45
lines changed

4 files changed

+49
-45
lines changed

suzieq/cli/sqcmds/context_commands.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import typing
21
import os
2+
import typing
3+
34
from nubia import command, context
4-
from nubia.internal.commands.help import HelpCommand
55
from nubia.internal.cmdbase import Command
6+
from nubia.internal.commands.help import HelpCommand
67
from prompt_toolkit.completion import Completion
7-
from termcolor import cprint, colored
8+
from termcolor import colored, cprint
89

910
from suzieq.cli.nubia_patch import argument
10-
from suzieq.shared.utils import SUPPORTED_ENGINES,\
11-
print_version,\
12-
set_rest_engine
11+
from suzieq.shared.utils import (SUPPORTED_ENGINES, print_version,
12+
set_rest_engine)
1313

1414

1515
@command("set")
@@ -90,10 +90,10 @@ def set_ctxt(
9090
if engine:
9191
if ctxt.engine != engine:
9292
if engine == 'rest':
93-
ctxt.rest_server_ip,\
94-
ctxt.rest_server_port,\
95-
ctxt.rest_transport,\
96-
ctxt.rest_api_key = set_rest_engine(ctxt.cfg)
93+
ctxt.rest_server_ip, \
94+
ctxt.rest_server_port, \
95+
ctxt.rest_transport, \
96+
ctxt.rest_api_key = set_rest_engine(ctxt.cfg)
9797
plugin_ctx.change_engine(engine)
9898

9999
if debug:

suzieq/shared/context.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ def __post_init__(self):
3434
if not self.engine:
3535
self.engine = self.cfg.get('ux', {}).get('engine', 'pandas')
3636
if self.engine == 'rest':
37-
self.rest_server_ip,\
38-
self.rest_server_port,\
39-
self.rest_transport,\
40-
self.rest_api_key = set_rest_engine(self.cfg)
37+
self.rest_server_ip, \
38+
self.rest_server_port, \
39+
self.rest_transport, \
40+
self.rest_api_key = set_rest_engine(self.cfg)
4141

4242
if self.engine not in SUPPORTED_ENGINES:
4343
raise ValueError(f'Engine {self.engine} not supported')

suzieq/shared/utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,8 @@ def log_suzieq_info(name: str, c_logger: logging.Logger = None,
12301230
if prev_level > logging.INFO:
12311231
c_logger.setLevel(prev_level)
12321232

1233-
def set_rest_engine(cfg:Dict[str, Any]) -> Tuple:
1233+
1234+
def set_rest_engine(cfg: Dict[str, Any]) -> Tuple:
12341235
"""Unpack the rest configuration from the cfg object. It is used to switch
12351236
to rest engine with the right config params
12361237
@@ -1242,7 +1243,7 @@ def set_rest_engine(cfg:Dict[str, Any]) -> Tuple:
12421243
rest_server_ip
12431244
rest_server_port
12441245
rest_transport
1245-
rest_api_key
1246+
rest_api_key
12461247
"""
12471248
restcfg = cfg.get('rest', {})
12481249
rest_server_ip = restcfg.get('address', '127.0.0.1')

tests/unit/test_sqconfig_load.py

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import re
2+
from dataclasses import dataclass
23
from tempfile import NamedTemporaryFile
4+
from typing import Dict
35
from unittest.mock import MagicMock, patch
46

57
import pytest
8+
9+
from suzieq.cli.sqcmds import context_commands
10+
from suzieq.shared.context import SqContext
611
from suzieq.shared.utils import (get_sq_install_dir, load_sq_config,
712
validate_sq_config)
813
from tests.conftest import create_dummy_config_file
9-
from suzieq.shared.context import SqContext
10-
from suzieq.cli.sqcmds import context_commands
11-
from dataclasses import dataclass
14+
1215

1316
@pytest.mark.sq_config
1417
def test_valid_sq_config():
@@ -94,14 +97,17 @@ def test_config_validation(monkeypatch):
9497
assert error is None, error
9598

9699

97-
@ pytest.mark.sq_config
98-
@ pytest.mark.rest
99-
def test_config_rest():
100-
#with pandas engine
101-
cfg = {'rest': {}}
100+
@pytest.mark.sq_config
101+
@pytest.mark.rest
102+
def test_config_rest() -> None:
103+
"""
104+
Test config file
105+
"""
106+
# with pandas engine
107+
cfg: Dict = {'rest': {}}
102108

103109
ctxt = SqContext(cfg=cfg)
104-
#check that the default value are the same
110+
# check that the default value are the same
105111
assert ctxt.rest_transport == 'https'
106112
assert ctxt.rest_server_ip == '127.0.0.1'
107113
assert ctxt.rest_server_port == 8000
@@ -113,7 +119,7 @@ def test_config_rest():
113119
cfg['rest']['address'] = '0.0.0.0'
114120
cfg['rest']['port'] = 8000
115121
cfg['rest']['no-https'] = True
116-
cfg['ux']= {'engine': 'rest'}
122+
cfg['ux'] = {'engine': 'rest'}
117123

118124
ctxt = SqContext(cfg=cfg)
119125
assert ctxt.rest_transport == 'http'
@@ -122,7 +128,7 @@ def test_config_rest():
122128
assert ctxt.rest_api_key == '496157e6e869ef7f3d6ecb24a6f6d847b224ee4f'
123129
assert ctxt.engine == 'rest'
124130

125-
#https with rest engine
131+
# https with rest engine
126132
cfg['rest']['no-https'] = False
127133
ctxt = SqContext(cfg=cfg)
128134
assert ctxt.rest_transport == 'https'
@@ -132,12 +138,12 @@ def test_config_rest():
132138
assert ctxt.engine == 'rest'
133139

134140

135-
136-
137-
138-
@ pytest.mark.sq_config
139-
@ pytest.mark.rest
141+
@pytest.mark.sq_config
142+
@pytest.mark.rest
140143
def test_context_commands_context(monkeypatch):
144+
"""
145+
test context
146+
"""
141147
CTXT_REST_ATTRS = {
142148
'rest_server_ip': 'address',
143149
'rest_server_port': 'port',
@@ -147,7 +153,7 @@ def test_context_commands_context(monkeypatch):
147153
@dataclass
148154
class fake_ctxt_class():
149155
engine = 'rest'
150-
cfg = {'rest':
156+
cfg = {'rest':
151157
{
152158
'address': '0.0.0.0',
153159
'port': '8000',
@@ -169,8 +175,7 @@ def change_engine(self, engine):
169175
def fake_get_context():
170176
return fake_context_class()
171177

172-
173-
#sending set engine: rest when is already selected, nothing should change
178+
# sending set engine: rest when is already selected, nothing should change
174179
monkeypatch.setattr(context_commands.context,
175180
'get_context',
176181
fake_get_context)
@@ -185,27 +190,25 @@ def fake_get_context():
185190
assert getattr(context_commands.context.get_context().ctxt,
186191
'rest_transport') == 'test_rest_transport'
187192

188-
189-
#sending set engine: rest when is selected engine: pandas with http
193+
# sending set engine: rest when is selected engine: pandas with http
190194
fake_context_class.ctxt.engine = 'pandas'
191195
monkeypatch.setattr(context_commands.context,
192196
'get_context',
193197
fake_get_context)
194198
context_commands.set_ctxt(engine='rest')
195199
assert context_commands.context.get_context().ctxt.engine == 'rest'
196200
for attr in CTXT_REST_ATTRS:
197-
#get the expexted value of the rest param
201+
# get the expexted value of the rest param
198202
expected_value = fake_ctxt_class.cfg['rest'][CTXT_REST_ATTRS[attr]]
199203
if CTXT_REST_ATTRS[attr] == 'no-https':
200-
expected_value = 'http' if expected_value == True else 'https'
201-
#check if all the rest attr match
204+
expected_value = 'http' if expected_value is True else 'https'
205+
# check if all the rest attr match
202206
assert getattr(
203207
context_commands.context.get_context().ctxt,
204208
attr) == expected_value, f'{attr} value shold be {expected_value},\
205209
not {getattr(context_commands.context.get_context().ctxt, attr)}'
206210

207-
208-
#sending set engine: rest when is selected engine: pandas with https
211+
# sending set engine: rest when is selected engine: pandas with https
209212
fake_context_class.ctxt.engine = 'pandas'
210213
fake_ctxt_class.cfg['rest']['no-https'] = False
211214
monkeypatch.setattr(context_commands.context,
@@ -214,11 +217,11 @@ def fake_get_context():
214217
context_commands.set_ctxt(engine='rest')
215218
assert context_commands.context.get_context().ctxt.engine == 'rest'
216219
for attr in CTXT_REST_ATTRS:
217-
#get the expexted value of the rest param
220+
# get the expexted value of the rest param
218221
expected_value = fake_ctxt_class.cfg['rest'][CTXT_REST_ATTRS[attr]]
219222
if CTXT_REST_ATTRS[attr] == 'no-https':
220-
expected_value = 'http' if expected_value == True else 'https'
221-
#check if all the rest attr match
223+
expected_value = 'http' if expected_value is True else 'https'
224+
# check if all the rest attr match
222225
assert getattr(
223226
context_commands.context.get_context().ctxt,
224227
attr) == expected_value, f'{attr} value shold be {expected_value},\

0 commit comments

Comments
 (0)