11import re
2+ from dataclasses import dataclass
23from tempfile import NamedTemporaryFile
4+ from typing import Dict
35from unittest .mock import MagicMock , patch
46
57import pytest
8+
9+ from suzieq .cli .sqcmds import context_commands
10+ from suzieq .shared .context import SqContext
611from suzieq .shared .utils import (get_sq_install_dir , load_sq_config ,
712 validate_sq_config )
813from 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
1417def 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
140143def 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