Skip to content

Commit 1f33435

Browse files
committed
chore: format code
1 parent e054f86 commit 1f33435

7 files changed

+48
-45
lines changed

http_server_extension.py

+13-10
Original file line numberDiff line numberDiff line change
@@ -29,44 +29,45 @@ async def handle_post_cmd(self, request):
2929
ten_env = self.ten_env
3030

3131
try:
32-
cmd_name = request.match_info.get('cmd_name')
32+
cmd_name = request.match_info.get("cmd_name")
3333

3434
req_json = await request.json()
3535
input_json = json.dumps(req_json, ensure_ascii=False)
3636

3737
ten_env.log_debug(
38-
f"process incoming request {request.method} {request.path} {input_json}")
38+
f"process incoming request {request.method} {request.path} {input_json}"
39+
)
3940

4041
cmd = Cmd.create(cmd_name)
4142
cmd.set_property_from_json("", input_json)
4243
[cmd_result, _] = await asyncio.wait_for(ten_env.send_cmd(cmd), 5.0)
4344

4445
# return response
4546
status = 200 if cmd_result.get_status_code() == StatusCode.OK else 502
46-
return web.json_response(
47-
cmd_result.get_property_to_json(""), status=status
48-
)
47+
return web.json_response(cmd_result.get_property_to_json(""), status=status)
4948
except json.JSONDecodeError:
5049
return web.Response(status=400)
5150
except asyncio.TimeoutError:
5251
return web.Response(status=504)
5352
except Exception as e:
5453
ten_env.log_warn(
55-
"failed to handle request with unknown exception, err {}".format(e))
54+
"failed to handle request with unknown exception, err {}".format(e)
55+
)
5656
return web.Response(status=500)
5757

5858
# POST /data/{data_name}
5959
async def handle_post_data(self, request):
6060
ten_env = self.ten_env
6161

6262
try:
63-
data_name = request.match_info.get('data_name')
63+
data_name = request.match_info.get("data_name")
6464

6565
req_json = await request.json()
6666
input_json = json.dumps(req_json, ensure_ascii=False)
6767

6868
ten_env.log_debug(
69-
f"process incoming request {request.method} {request.path} {input_json}")
69+
f"process incoming request {request.method} {request.path} {input_json}"
70+
)
7071

7172
data = Data.create(data_name)
7273
data.set_property_from_json("", input_json)
@@ -78,7 +79,8 @@ async def handle_post_data(self, request):
7879
return web.Response(status=400)
7980
except Exception as e:
8081
ten_env.log_warn(
81-
"failed to handle request with unknown exception, err {}".format(e))
82+
"failed to handle request with unknown exception, err {}".format(e)
83+
)
8284
return web.Response(status=500)
8385

8486
async def on_start(self, async_ten_env: AsyncTenEnv):
@@ -89,7 +91,8 @@ async def on_start(self, async_ten_env: AsyncTenEnv):
8991
self.ten_env = async_ten_env
9092

9193
async_ten_env.log_info(
92-
f"http server listening on {self.listen_addr}:{self.listen_port}")
94+
f"http server listening on {self.listen_addr}:{self.listen_port}"
95+
)
9396

9497
self.app.router.add_post("/cmd/{cmd_name}", self.handle_post_cmd)
9598
self.app.router.add_post("/data/{data_name}", self.handle_post_data)

tests/test_4xx.py

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def on_start(self, ten_env: TenEnvTester) -> None:
4444
if r.status_code == httpx.codes.BAD_REQUEST:
4545
ten_env.stop_test()
4646

47+
4748
class ExtensionTesterData400BadRequest(ExtensionTester):
4849
def on_start(self, ten_env: TenEnvTester) -> None:
4950
ten_env.on_start_done()
@@ -54,6 +55,7 @@ def on_start(self, ten_env: TenEnvTester) -> None:
5455
if r.status_code == httpx.codes.BAD_REQUEST:
5556
ten_env.stop_test()
5657

58+
5759
def test_4xx():
5860
tester_404_1 = ExtensionTester404NotFound1()
5961
tester_404_1.set_test_mode_single("http_server_python")

tests/test_5xx.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,14 @@ def on_cmd(self, ten_env: TenEnvTester, cmd: Cmd) -> None:
2828
ten_env.return_result(CmdResult.create(StatusCode.ERROR), cmd)
2929

3030
def on_start(self, ten_env: TenEnvTester) -> None:
31-
self.thread = threading.Thread(
32-
target=self._async_test, args=[ten_env])
31+
self.thread = threading.Thread(target=self._async_test, args=[ten_env])
3332
self.thread.start()
3433

3534
ten_env.on_start_done()
3635

3736
def _async_test(self, ten_env: TenEnvTester) -> None:
3837
property_json = {"num": 1, "str": "111"}
39-
r = httpx.post("http://127.0.0.1:8888/cmd/abc",
40-
json=property_json, timeout=5)
38+
r = httpx.post("http://127.0.0.1:8888/cmd/abc", json=property_json, timeout=5)
4139
ten_env.log_debug(f"{r}")
4240

4341
if r.status_code >= 500:

tests/test_cmd.py

+14-12
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,33 @@ def __init__(self):
2525
def on_cmd(self, ten_env: TenEnvTester, cmd: Cmd) -> None:
2626
ten_env.log_debug(f"on_cmd name {cmd.get_name()}")
2727

28-
num_val = cmd.get_property_int('num')
28+
num_val = cmd.get_property_int("num")
2929
assert num_val == 1
30-
str_val = cmd.get_property_string('str')
31-
assert str_val == '111'
32-
unicode_str_val = cmd.get_property_string('unicode_str')
33-
assert unicode_str_val == '你好!'
34-
num_float_val = cmd.get_property_float('num_float')
30+
str_val = cmd.get_property_string("str")
31+
assert str_val == "111"
32+
unicode_str_val = cmd.get_property_string("unicode_str")
33+
assert unicode_str_val == "你好!"
34+
num_float_val = cmd.get_property_float("num_float")
3535
assert math.isclose(num_float_val, -1.5)
3636

3737
ten_env.return_result(CmdResult.create(StatusCode.OK), cmd)
3838

3939
def on_start(self, ten_env: TenEnvTester) -> None:
4040

41-
self.thread = threading.Thread(
42-
target=self._async_test, args=[ten_env])
41+
self.thread = threading.Thread(target=self._async_test, args=[ten_env])
4342
self.thread.start()
4443

4544
ten_env.on_start_done()
4645

4746
def _async_test(self, ten_env: TenEnvTester) -> None:
48-
property_json = {"num": 1, "num_float": -
49-
1.5, "str": "111", "unicode_str": "你好!"}
47+
property_json = {
48+
"num": 1,
49+
"num_float": -1.5,
50+
"str": "111",
51+
"unicode_str": "你好!",
52+
}
5053

51-
r = httpx.post("http://127.0.0.1:8888/cmd/abc",
52-
json=property_json, timeout=5)
54+
r = httpx.post("http://127.0.0.1:8888/cmd/abc", json=property_json, timeout=5)
5355
ten_env.log_debug(f"{r}")
5456

5557
if r.status_code == httpx.codes.OK:

tests/test_data.py

+14-13
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,31 @@ def __init__(self):
2626
def on_data(self, ten_env: TenEnvTester, data: Data) -> None:
2727
ten_env.log_debug(f"on_data name {data.get_name()}")
2828

29-
num_val = data.get_property_int('num')
29+
num_val = data.get_property_int("num")
3030
assert num_val == 1
31-
str_val = data.get_property_string('str')
32-
assert str_val == '111'
33-
unicode_str_val = data.get_property_string('unicode_str')
34-
assert unicode_str_val == '你好!'
35-
num_float_val = data.get_property_float('num_float')
31+
str_val = data.get_property_string("str")
32+
assert str_val == "111"
33+
unicode_str_val = data.get_property_string("unicode_str")
34+
assert unicode_str_val == "你好!"
35+
num_float_val = data.get_property_float("num_float")
3636
assert math.isclose(num_float_val, -1.5)
3737

38-
3938
def on_start(self, ten_env: TenEnvTester) -> None:
4039

41-
self.thread = threading.Thread(
42-
target=self._async_test, args=[ten_env])
40+
self.thread = threading.Thread(target=self._async_test, args=[ten_env])
4341
self.thread.start()
4442

4543
ten_env.on_start_done()
4644

4745
def _async_test(self, ten_env: TenEnvTester) -> None:
48-
property_json = {"num": 1, "num_float": -
49-
1.5, "str": "111", "unicode_str": "你好!"}
46+
property_json = {
47+
"num": 1,
48+
"num_float": -1.5,
49+
"str": "111",
50+
"unicode_str": "你好!",
51+
}
5052

51-
r = httpx.post("http://127.0.0.1:8888/data/abc",
52-
json=property_json, timeout=5)
53+
r = httpx.post("http://127.0.0.1:8888/data/abc", json=property_json, timeout=5)
5354
ten_env.log_debug(f"{r}")
5455

5556
if r.status_code == httpx.codes.OK:

tests/test_set_property.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,14 @@ def on_cmd(self, ten_env: TenEnvTester, cmd: Cmd) -> None:
2727

2828
def on_start(self, ten_env: TenEnvTester) -> None:
2929

30-
self.thread = threading.Thread(
31-
target=self._async_test, args=[ten_env])
30+
self.thread = threading.Thread(target=self._async_test, args=[ten_env])
3231
self.thread.start()
3332

3433
ten_env.on_start_done()
3534

3635
def _async_test(self, ten_env: TenEnvTester) -> None:
3736
property_json = {"num": 1, "str": "111"}
38-
r = httpx.post("http://127.0.0.1:8899/cmd/abc",
39-
json=property_json, timeout=5)
37+
r = httpx.post("http://127.0.0.1:8899/cmd/abc", json=property_json, timeout=5)
4038
ten_env.log_debug(f"{r}")
4139

4240
if r.status_code == httpx.codes.OK:

tests/test_timeout.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ def on_start(self, ten_env: TenEnvTester) -> None:
2828
ten_env.on_start_done()
2929

3030
property_json = {"num": 1, "str": "111"}
31-
r = httpx.post("http://127.0.0.1:8888/cmd/abc",
32-
json=property_json, timeout=10)
31+
r = httpx.post("http://127.0.0.1:8888/cmd/abc", json=property_json, timeout=10)
3332
ten_env.log_debug(f"{r}")
3433
if r.status_code == httpx.codes.GATEWAY_TIMEOUT:
3534
ten_env.stop_test()

0 commit comments

Comments
 (0)