Spaces:
Paused
Paused
Download tests/test_projects_browser.py from SEE7/AstheralPlus: direct link, hf CLI and curl.
- Browser
- Download file 2.94 kB
-
https://huggingface.co/spaces/SEE7/AstheralPlus/resolve/main/tests/test_projects_browser.py
- Command line
-
hf download hf://spaces/SEE7/AstheralPlus/tests/test_projects_browser.py
-
curl -L -o test_projects_browser.py https://huggingface.co/spaces/SEE7/AstheralPlus/resolve/main/tests/test_projects_browser.py
2.94 kB
| from pathlib import Path | |
| from playwright.sync_api import sync_playwright | |
| import json | |
| with sync_playwright() as p: | |
| browser=p.chromium.launch(args=['--no-sandbox']) | |
| page=browser.new_page(ignore_https_errors=True);errors=[];captured=[] | |
| page.on('pageerror',lambda e:errors.append(str(e))) | |
| def reply(route): | |
| captured.append(route.request.post_data_json) | |
| payload={'choices':[{'index':0,'delta':{'content':'A saved answer.'},'finish_reason':None}]} | |
| route.fulfill(status=200,content_type='text/event-stream',body='data: '+json.dumps(payload)+'\n\ndata: [DONE]\n\n') | |
| page.route('**/v1/chat/completions',reply) | |
| page.goto('https://see7-astheralplus.hf.space/',wait_until='networkidle',timeout=30000) | |
| page.get_by_role('button',name='Projects',exact=True).click() | |
| page.locator('#pp-new').click();page.locator('#pp-name').fill('Physics');page.locator('#pp-instructions').fill('Use SI units.');page.locator('#pp-save').click() | |
| page.locator('#pp-files').set_input_files({'name':'units.txt','mimeType':'text/plain','buffer':b'The metre is the SI unit of length.'}) | |
| page.wait_for_timeout(250);page.locator('#pp-close').click() | |
| page.locator('textarea').filter(visible=True).first.fill('Explain distance.') | |
| page.get_by_role('button',name='Send',exact=True).click();page.wait_for_timeout(1000) | |
| state=json.loads(page.evaluate("localStorage.getItem('astheralplus.projects.v1')")) | |
| a=state['projects'][0];assert len(a['files'])==1 and len(a['chats'])==1 | |
| assert a['chats'][0]['messages'][-1]['content']=='A saved answer.' | |
| assert 'Use SI units.' in captured[-1]['messages'][0]['content'] and 'units.txt' in captured[-1]['messages'][0]['content'] | |
| print('PROJECT_CHAT_PATH',a['chats'][0]['path'],flush=True) | |
| page.get_by_role('button',name='Projects · Physics',exact=True).click() | |
| with page.expect_download() as info:page.locator('#pp-export').click() | |
| assert info.value.suggested_filename=='Physics.json' | |
| page.locator('#pp-new').click();page.locator('#pp-name').fill('Writing');page.locator('#pp-save').click();page.locator('#pp-close').click() | |
| page.get_by_label('Response mode',exact=True).select_option('Thinking') | |
| page.locator('textarea').filter(visible=True).first.fill('Write a short sentence.') | |
| page.get_by_role('button',name='Send',exact=True).click();page.wait_for_timeout(800) | |
| data=captured[-1];assert data['model']=='SEE7/AstheralPlus' and data['chat_template_kwargs']['enable_thinking'] is True | |
| assert 'SI units' not in json.dumps(data['messages']) and 'Explain distance' not in json.dumps(data['messages']) | |
| page.reload(wait_until='networkidle');assert page.get_by_label('Response mode',exact=True).input_value()=='Thinking' | |
| assert page.get_by_role('button',name='Projects · Writing',exact=True).count()==1 | |
| print('PASS projects, reference files, instructions, saved chats, export, project isolation, mode toggle and reload persistence',flush=True) | |
| print('ERRORS',errors,flush=True);assert not errors | |
| browser.close() | |