From 56bdbd79260b258d6d5f443aec0db4f4ebaa4016 Mon Sep 17 00:00:00 2001 From: manatlan Date: Tue, 4 Jun 2024 15:49:03 +0000 Subject: [PATCH] seems iso ;-) --- htagweb/hrclient.py | 19 +++---------------- htagweb/hrprocess.py | 6 ++---- htagweb/runners.py | 3 ++- test_runner.py | 23 +++++++++++++++++++++-- 4 files changed, 28 insertions(+), 23 deletions(-) diff --git a/htagweb/hrclient.py b/htagweb/hrclient.py index 7bad7f3..10ac08a 100644 --- a/htagweb/hrclient.py +++ b/htagweb/hrclient.py @@ -40,12 +40,10 @@ async def updater(self): def log(self,*a): msg = " ".join([str(i) for i in ["hrclient",self._fifo,":"] + list(a)]) # logging.warning( msg ) - RED='\033[0;32m' - NC='\033[0m' # No Color - print(RED,msg,NC,flush=True) + print(msg,flush=True) - async def create(self, js:str, init=None) -> str: + async def create(self, js:str, init=None, fullerror=False) -> str: # Assurez-vous que les pipes existent if self._fifo.exists(): self.log("reuse fifo process") @@ -55,7 +53,7 @@ async def create(self, js:str, init=None) -> str: if err: raise Exception(err) - self._html = await self._fifo.com("create",init=init, js=js,fullerror=False) + self._html = await self._fifo.com("create",init=init, js=js,fullerror=fullerror) return self._html def __str__(self) -> str: @@ -69,17 +67,6 @@ async def interact(self,id:int,method:str,args:list,kargs:dict,event=None) -> di else: raise Exception( f"App {self._fifo} is NOT RUNNING ! (can't interact)") - # async def exit(self): - # if self._fifo.exists(): - # # kill softly - # # assert await self._fifo.com("exit") - # self.log(f"kill via fifo") - # self._process.kill() - # self._process.join() - # self._fifo.removePipes() - # else: - # raise Exception( f"App {self._fifo} is NOT RUNNING ! (can't exit)") - @classmethod async def clean(cls): print(f"Clean clients",flush=True) diff --git a/htagweb/hrprocess.py b/htagweb/hrprocess.py index 6df8595..629b0a0 100644 --- a/htagweb/hrprocess.py +++ b/htagweb/hrprocess.py @@ -42,9 +42,7 @@ def process_exit(): def log(*a): msg = " ".join([str(i) for i in ["hrprocess",f,":"] + list(a)]) # logging.warning( msg ) - RED='\033[0;33m' - NC='\033[0m' # No Color - print(RED,msg,NC,flush=True,file=sys.stderr) + print(msg,flush=True,file=sys.stderr) async def sendactions(actions:dict) -> bool: # create the fifo on the first tag.update ! @@ -140,8 +138,8 @@ def destroy(): try: c["response"]=await cmd(**c) except Exception as e: + # HRenderer.interact has its own system, but needed for create ;-( if hasattr( sys, "hr") and sys.hr and sys.hr.fullerror: - #TODO: as is (see runner), fullerror is always false err=traceback.format_exc() else: err=str(e) diff --git a/htagweb/runners.py b/htagweb/runners.py index 654499f..ace1a93 100644 --- a/htagweb/runners.py +++ b/htagweb/runners.py @@ -206,6 +206,7 @@ def __init__(self, self.http_only = http_only self.timeout_interaction = timeout_interaction self.timeout_inactivity = timeout_inactivity + self.fullerror = debug ################################################################### @@ -321,7 +322,7 @@ async def handle(self, request, """ % locals() hr = HrClient(uid,fqn, the_timeout_interaction, the_timeout_inactivity) - hr=await hr.create(js=js,init=init) + hr=await hr.create(js=js,init=init,fullerror=self.fullerror) html=str(hr) return HTMLResponse(html) diff --git a/test_runner.py b/test_runner.py index ef8632b..93dc284 100644 --- a/test_runner.py +++ b/test_runner.py @@ -16,8 +16,7 @@ def do_tests(client): assert "" in response.text - soup=bs4.BeautifulSoup(response.text,"html.parser") - id=soup.select("button")[-1].get("id") + id=bs4.BeautifulSoup(response.text,"html.parser").select("button")[-1].get("id") datas={"id":int(id),"method":"__on__","args":["onclick-"+str(id)],"kargs":{},"event":{}} with client.websocket_connect('/_/examples.simple.App') as websocket: @@ -32,3 +31,23 @@ def do_tests(client): with TestClient(app) as client: do_tests(client) + +def test_runner_http_mode(): + + def do_tests(client): + response = client.get('/') + + # assert that get bootstrap page + assert response.status_code == 200 + assert "" in response.text + + id=bs4.BeautifulSoup(response.text,"html.parser").select("button")[-1].get("id") + datas={"id":int(id),"method":"__on__","args":["onclick-"+str(id)],"kargs":{},"event":{}} + + response = client.post('/_/examples.simple.App',content=json.dumps(datas)) + dico = json.loads(response.text) + assert "update" in dico + + app=Runner("examples.simple.App",http_only=True) + with TestClient(app) as client: + do_tests(client)