Download test/conftest.py from Asukaa02/tet: direct link, hf CLI and curl.
- Browser
- Download file 1.82 kB
-
https://huggingface.co/Asukaa02/tet/resolve/main/test/conftest.py
- Command line
-
hf download hf://Asukaa02/tet/test/conftest.py
-
curl -L -o conftest.py https://huggingface.co/Asukaa02/tet/resolve/main/test/conftest.py
1.82 kB
| import inspect | |
| import pathlib | |
| from contextlib import contextmanager | |
| import pytest | |
| from gradio_client import Client | |
| import gradio as gr | |
| def pytest_configure(config): | |
| config.addinivalue_line( | |
| "markers", "flaky: mark test as flaky. Failure will not cause te" | |
| ) | |
| def test_file_dir(): | |
| return pathlib.Path(pathlib.Path(__file__).parent, "test_files") | |
| def io_components(): | |
| classes_to_check = gr.components.IOComponent.__subclasses__() | |
| subclasses = [] | |
| while classes_to_check: | |
| subclass = classes_to_check.pop() | |
| children = subclass.__subclasses__() | |
| if children: | |
| classes_to_check.extend(children) | |
| if "value" in inspect.signature(subclass).parameters: | |
| subclasses.append(subclass) | |
| return subclasses | |
| def connect(): | |
| def _connect(demo: gr.Blocks, serialize=True): | |
| _, local_url, _ = demo.launch(prevent_thread_lock=True) | |
| try: | |
| yield Client(local_url, serialize=serialize) | |
| finally: | |
| # A more verbose version of .close() | |
| # because we should set a timeout | |
| # the tests that call .cancel() can get stuck | |
| # waiting for the thread to join | |
| if demo.enable_queue: | |
| demo._queue.close() | |
| demo.is_running = False | |
| demo.server.should_exit = True | |
| demo.server.thread.join(timeout=1) | |
| return _connect | |
| def gradio_temp_dir(monkeypatch, tmp_path): | |
| """tmp_path is unique to each test function. | |
| It will be cleared automatically according to pytest docs: https://docs.pytest.org/en/6.2.x/reference.html#tmp-path | |
| """ | |
| monkeypatch.setenv("GRADIO_TEMP_DIR", str(tmp_path)) | |
| return tmp_path | |