1
0
mirror of https://github.com/venthur/blag.git synced 2025-11-25 20:52:43 +00:00

fixed devserver

so it does crash on build failure anymore. also made tests a bit faster
by adding a wait parameter to the autoreload method.
This commit is contained in:
Bastian Venthur
2024-04-24 21:47:59 +02:00
parent 4d4630867d
commit 0236dbf782
3 changed files with 53 additions and 18 deletions

View File

@@ -8,10 +8,10 @@ import threading
import time
from argparse import Namespace
import pytest
from blag import devserver
WAITTIME = 0.1
def test_get_last_modified(cleandir: str) -> None:
"""Test get_last_modified."""
@@ -19,13 +19,13 @@ def test_get_last_modified(cleandir: str) -> None:
t1 = devserver.get_last_modified(["content"])
# wait a bit, create a file and measure again
time.sleep(0.1)
time.sleep(WAITTIME)
with open("content/test", "w") as fh:
fh.write("boo")
t2 = devserver.get_last_modified(["content"])
# wait a bit and take time again
time.sleep(0.1)
time.sleep(WAITTIME)
t3 = devserver.get_last_modified(["content"])
assert t2 > t1
@@ -40,14 +40,14 @@ def test_autoreload_builds_immediately(args: Namespace) -> None:
t = threading.Thread(
target=devserver.autoreload,
args=(args,),
args=(args, WAITTIME),
daemon=True,
)
t0 = devserver.get_last_modified(["build"])
t.start()
# try for 5 seconds...
for i in range(5):
time.sleep(1)
time.sleep(WAITTIME)
t1 = devserver.get_last_modified(["build"])
print(t1)
if t1 > t0:
@@ -55,14 +55,11 @@ def test_autoreload_builds_immediately(args: Namespace) -> None:
assert t1 > t0
@pytest.mark.filterwarnings(
"ignore::pytest.PytestUnhandledThreadExceptionWarning"
)
def test_autoreload(args: Namespace) -> None:
"""Test autoreload."""
t = threading.Thread(
target=devserver.autoreload,
args=(args,),
args=(args, WAITTIME),
daemon=True,
)
t.start()
@@ -75,8 +72,32 @@ def test_autoreload(args: Namespace) -> None:
# try for 5 seconds to see if we rebuild once...
for i in range(5):
time.sleep(1)
time.sleep(WAITTIME)
t1 = devserver.get_last_modified(["build"])
if t1 > t0:
break
assert t1 > t0
def test_autoreload_does_not_crash(args: Namespace) -> None:
"""Test autoreload does not crash if build fails."""
t = threading.Thread(
target=devserver.autoreload,
args=(args, WAITTIME),
daemon=True,
)
t.start()
t0 = devserver.get_last_modified(["build"])
# create a file that causes build to crash
with open("content/test.md", "w") as fh:
fh.write("date: ")
# try for 5 seconds to see if we rebuild once...
for i in range(5):
time.sleep(WAITTIME)
t1 = devserver.get_last_modified(["build"])
if t1 > t0:
break
assert t.is_alive()