Skip to content

Commit 4ddfefc

Browse files
committed
bumped some test requirements, runs with python 3.11.3
1 parent d140770 commit 4ddfefc

File tree

7 files changed

+79
-14
lines changed

7 files changed

+79
-14
lines changed

custom_components/pyscript/jupyter_kernel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ async def housekeep_run(self):
746746
await asyncio.sleep(10000)
747747
elif msg[0] == "shutdown":
748748
asyncio.create_task(self.session_shutdown())
749-
await asyncio.sleep(10000)
749+
return
750750
except asyncio.CancelledError:
751751
raise
752752
except Exception:

tests/requirements_test.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
coverage==7.1.0
1+
coverage==7.2.1
22
croniter==1.3.8
33
watchdog==2.1.9
44
mock-open==1.4.0
5-
mypy==1.1.1
5+
mypy==1.3.0
66
pre-commit==3.2.1
7-
pytest==7.2.1
7+
pytest==7.2.2
88
pytest-cov==3.0.0
9-
pytest-homeassistant-custom-component==0.13.10
10-
pylint==2.17.1
9+
pytest-homeassistant-custom-component==0.13.23
10+
pylint==2.17.4
1111
pylint-strict-informational==0.1

tests/test_function.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,17 +308,19 @@ def func4a_hold_false():
308308
309309
@service
310310
def func4b_hold_false():
311-
global seq_num
311+
global seq_num, func4b_hold_false_id
312312
313+
func4b_hold_false_id = task.current_task()
313314
while 1:
314315
seq_num += 1
315316
res = task.wait_until(state_trigger="int(pyscript.f4bvar2) >= 10", state_hold_false=0, __test_handshake__=["pyscript.done2", seq_num], state_check_now=False)
316317
pyscript.done = [seq_num, res["value"]]
317318
318319
@service
319320
def func4c_hold_false():
320-
global seq_num
321+
global seq_num, func4c_hold_false_id
321322
323+
func4c_hold_false_id = task.current_task()
322324
while 1:
323325
# this should never trigger
324326
seq_num += 1
@@ -411,6 +413,17 @@ def func9(var_name=None, value=None, old_value=None):
411413
seq_num += 1
412414
log.info(f"func9 var = {var_name}, value = {value}")
413415
pyscript.done = [seq_num, var_name, value, old_value]
416+
417+
@service
418+
def service_cleanup():
419+
global seq_num
420+
421+
seq_num += 1
422+
task.cancel(func4c_hold_false_id)
423+
task.cancel(func4b_hold_false_id)
424+
log.info(f"service_cleanup seq_num = {seq_num}")
425+
pyscript.done = [seq_num]
426+
414427
""",
415428
)
416429
# initialize the trigger and active variables
@@ -704,6 +717,10 @@ def func9(var_name=None, value=None, old_value=None):
704717
seq_num += 1
705718
assert literal_eval(await wait_until_done(notify_q2)) == seq_num
706719

720+
seq_num += 1
721+
await hass.services.async_call("pyscript", "service_cleanup", {})
722+
assert literal_eval(await wait_until_done(notify_q)) == [seq_num]
723+
707724

708725
@pytest.mark.asyncio
709726
async def test_state_trigger_time(hass, caplog):
@@ -1252,7 +1269,7 @@ async def test_service_call_blocking(hass, caplog):
12521269
12531270
@time_trigger("startup")
12541271
def func_startup():
1255-
global seq_num
1272+
global seq_num, long_sleep_id
12561273
12571274
seq_num += 1
12581275
pyscript.var1 = 1
@@ -1272,11 +1289,15 @@ def func_startup():
12721289
service.call("pyscript", "long_sleep", blocking=True, limit=1e-6)
12731290
pyscript.done = [seq_num, pyscript.var1]
12741291
1292+
task.cancel(long_sleep_id)
12751293
seq_num += 1
12761294
pyscript.done = [seq_num]
12771295
12781296
@service
12791297
def long_sleep():
1298+
global long_sleep_id
1299+
1300+
long_sleep_id = task.current_task()
12801301
task.sleep(10000)
12811302
12821303
@service

tests/test_jupyter.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
from custom_components.pyscript import trigger
1717
from custom_components.pyscript.const import DOMAIN, FOLDER
18+
from custom_components.pyscript.function import Function
1819
from custom_components.pyscript.jupyter_kernel import ZmqSocket
1920
from homeassistant.const import EVENT_HOMEASSISTANT_STARTED, EVENT_HOMEASSISTANT_STOP
2021
from homeassistant.setup import async_setup_component
@@ -565,3 +566,6 @@ async def test_jupyter_kernel_no_connection_timeout(hass, caplog, socket_enabled
565566
await asyncio.sleep(2e-3)
566567

567568
assert "No connections to session jupyter_" in caplog.text
569+
await Function.waiter_sync()
570+
await Function.waiter_stop()
571+
await Function.reaper_stop()

tests/test_unique.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,12 @@ async def test_task_unique(hass, caplog):
7979
8080
@time_trigger("startup")
8181
def funcStartupSync():
82-
global seq_num
82+
global seq_num, funcStartupSync_id
8383
8484
seq_num += 1
8585
log.info(f"funcStartupSync setting pyscript.done = {seq_num}")
8686
pyscript.done = seq_num
87+
funcStartupSync_id = task.current_task()
8788
#
8889
# stick around so the task.unique() still applies
8990
#
@@ -92,6 +93,15 @@ def funcStartupSync():
9293
assert task.current_task() == task.name2id()["func6"]
9394
task.sleep(10000)
9495
96+
@service
97+
def service_cleanup():
98+
global seq_num
99+
100+
seq_num += 1
101+
task.cancel(funcStartupSync_id)
102+
log.info(f"service_cleanup seq_num = {seq_num}")
103+
pyscript.done = [seq_num]
104+
95105
@state_trigger("pyscript.f0var1 == '1'")
96106
def func0(var_name=None, value=None):
97107
global seq_num
@@ -290,3 +300,7 @@ def func6():
290300
"context": context,
291301
},
292302
]
303+
304+
seq_num += 1
305+
await hass.services.async_call("pyscript", "service_cleanup", {})
306+
assert literal_eval(await wait_until_done(notify_q)) == [seq_num]

tests/test_unit_eval.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1372,7 +1372,9 @@ def func(arg):
13721372
13731373
id = task.create(func, 19)
13741374
done, pending = task.wait({id}, timeout=0)
1375-
[len(done), len(pending), id in pending, task.name2id("func") == id, task.name2id()["func"] == id]
1375+
res = [len(done), len(pending), id in pending, task.name2id("func") == id, task.name2id()["func"] == id]
1376+
task.cancel(id)
1377+
res
13761378
""",
13771379
[0, 1, True, True, True],
13781380
],
@@ -1404,6 +1406,9 @@ async def test_eval(hass):
14041406

14051407
for test_data in evalTests:
14061408
await run_one_test(test_data)
1409+
await Function.waiter_sync()
1410+
await Function.waiter_stop()
1411+
await Function.reaper_stop()
14071412

14081413

14091414
evalTestsExceptions = [
@@ -1657,3 +1662,6 @@ async def test_eval_exceptions(hass):
16571662

16581663
for test_data in evalTestsExceptions:
16591664
await run_one_test_exception(test_data)
1665+
await Function.waiter_sync()
1666+
await Function.waiter_stop()
1667+
await Function.reaper_stop()

tests/test_unit_trigger.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ async def test_parse_date_time(hass, caplog):
9191
spec, date_offset, expect = test_data
9292
out = TrigTime.parse_date_time(spec, date_offset, now, now)
9393
assert out == expect
94+
await Function.waiter_sync()
95+
await Function.waiter_stop()
96+
await Function.reaper_stop()
9497

9598

9699
parseDateTimeTestsDayNames = [
@@ -127,6 +130,9 @@ async def test_parse_date_time_day_names(hass, caplog):
127130
spec, date_offset, expect = test_data
128131
out = TrigTime.parse_date_time(spec, date_offset, now, now)
129132
assert out == expect
133+
await Function.waiter_sync()
134+
await Function.waiter_stop()
135+
await Function.reaper_stop()
130136

131137

132138
@pytest.mark.parametrize(
@@ -188,7 +194,8 @@ async def test_parse_date_time_day_names(hass, caplog):
188194
],
189195
ids=lambda x: x if not isinstance(x, (dt, list)) else str(x),
190196
)
191-
def test_timer_active_check(hass, spec, now, expected):
197+
@pytest.mark.asyncio
198+
async def test_timer_active_check(hass, spec, now, expected):
192199
"""Run time active check tests."""
193200

194201
#
@@ -206,6 +213,9 @@ def test_timer_active_check(hass, spec, now, expected):
206213
print(f"calling timer_active_check({spec}, {now}, {startup_time})")
207214
out = TrigTime.timer_active_check(spec, now, startup_time)
208215
assert out == expected
216+
await Function.waiter_sync()
217+
await Function.waiter_stop()
218+
await Function.reaper_stop()
209219

210220

211221
timerTriggerNextTests = [
@@ -450,7 +460,8 @@ def test_timer_active_check(hass, spec, now, expected):
450460
]
451461

452462

453-
def test_timer_trigger_next(hass):
463+
@pytest.mark.asyncio
464+
async def test_timer_trigger_next(hass):
454465
"""Run trigger next tests."""
455466
#
456467
# Hardcode a location and timezone so we can check sunrise
@@ -474,6 +485,9 @@ def test_timer_trigger_next(hass):
474485
if t_next is None:
475486
break
476487
now = t_next + timedelta(microseconds=1)
488+
await Function.waiter_sync()
489+
await Function.waiter_stop()
490+
await Function.reaper_stop()
477491

478492

479493
timerTriggerNextTestsMonthRollover = [
@@ -571,7 +585,8 @@ def test_timer_trigger_next(hass):
571585
]
572586

573587

574-
def test_timer_trigger_next_month_rollover(hass):
588+
@pytest.mark.asyncio
589+
async def test_timer_trigger_next_month_rollover(hass):
575590
"""Run month rollover tests."""
576591

577592
Function.init(hass)
@@ -584,3 +599,6 @@ def test_timer_trigger_next_month_rollover(hass):
584599
t_next = TrigTime.timer_trigger_next(spec, now, startup_time)
585600
assert t_next == expect
586601
now = t_next
602+
await Function.waiter_sync()
603+
await Function.waiter_stop()
604+
await Function.reaper_stop()

0 commit comments

Comments
 (0)