Skip to content

Commit

Permalink
seems iso ;-)
Browse files Browse the repository at this point in the history
  • Loading branch information
manatlan committed Jun 4, 2024
1 parent 7875597 commit 56bdbd7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 23 deletions.
19 changes: 3 additions & 16 deletions htagweb/hrclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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:
Expand All @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions htagweb/hrprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 !
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion htagweb/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

###################################################################

Expand Down Expand Up @@ -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)

Expand Down
23 changes: 21 additions & 2 deletions test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ def do_tests(client):
assert "<!DOCTYPE html>" 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:
Expand All @@ -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 "<!DOCTYPE html>" 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)

0 comments on commit 56bdbd7

Please sign in to comment.