Changeset View
Changeset View
Standalone View
Standalone View
swh/scanner/tests/conftest.py
Show All 32 Lines | |||||
async def aiosession(): | async def aiosession(): | ||||
"""Fixture that generate an aiohttp Client Session.""" | """Fixture that generate an aiohttp Client Session.""" | ||||
session = aiohttp.ClientSession() | session = aiohttp.ClientSession() | ||||
yield session | yield session | ||||
session.detach() | session.detach() | ||||
@pytest.fixture(scope='session') | @pytest.fixture(scope='session') | ||||
def temp_paths(tmp_path_factory): | def temp_folder(tmp_path_factory): | ||||
"""Fixture to generate temporary paths""" | """Fixture that generate a temporary folder with the following | ||||
douardda: generate**s** | |||||
subpath = tmp_path_factory.getbasetemp() | structure: | ||||
root: { | |||||
subdir: { | |||||
filesample.txt | |||||
} | |||||
subdir2 | |||||
subfile.txt | |||||
} | |||||
vlorentzUnsubmitted Not Done Inline ActionsUse a code block, or it will have formatting issues in our Sphinx-generated docs vlorentz: Use a [[ https://www.sphinx-doc.org/en/1.5/markup/code.html#directive-code-block | code block]]… | |||||
""" | |||||
root = tmp_path_factory.getbasetemp() | |||||
subdir = tmp_path_factory.mktemp('subdir') | subdir = tmp_path_factory.mktemp('subdir') | ||||
subdir2 = tmp_path_factory.mktemp('subdir2') | subdir2 = tmp_path_factory.mktemp('subdir2') | ||||
subfile = subpath.joinpath(PosixPath('./subfile.txt')) | subfile = root.joinpath(PosixPath('./subfile.txt')) | ||||
douarddaUnsubmitted Not Done Inline ActionsThe PosixPath is not needed here (and below): subfile = root.joinpath('subfile1.txt') or even: subfile = root / 'subfile1.txt' douardda: The PosixPath is not needed here (and below):
```subfile = root.joinpath('subfile1.txt')
```… | |||||
subfile.touch() | subfile.touch() | ||||
filesample = subdir.joinpath(PosixPath('./filesample.txt')) | |||||
filesample.touch() | |||||
avail_path = [subdir, subdir2, subfile] | avail_path = { | ||||
avail_pid = [pid_of_dir(bytes(subdir)), pid_of_dir(bytes(subdir2)), | subdir: pid_of_dir(bytes(subdir)), | ||||
pid_of_file(bytes(subfile))] | subdir2: pid_of_dir(bytes(subdir2)), | ||||
subfile: pid_of_file(bytes(subfile)), | |||||
return {'paths': avail_path, 'pids': avail_pid} | filesample: pid_of_file(bytes(filesample)) | ||||
} | |||||
return { | |||||
'root': root, | |||||
'paths': avail_path, | |||||
'filesample': filesample | |||||
} | |||||
@pytest.fixture(scope='session') | @pytest.fixture(scope='session') | ||||
def app(): | def app(): | ||||
"""Flask backend API (used by live_server).""" | """Flask backend API (used by live_server).""" | ||||
app = create_app() | app = create_app() | ||||
return app | return app | ||||
@pytest.fixture | @pytest.fixture | ||||
def test_folder(): | def test_folder(): | ||||
"""Location of the "data" folder """ | |||||
tests_path = PosixPath(os.path.abspath(__file__)).parent | tests_path = PosixPath(os.path.abspath(__file__)).parent | ||||
tests_data_folder = tests_path.joinpath('data') | tests_data_folder = tests_path.joinpath('data') | ||||
assert tests_data_folder.exists() | assert tests_data_folder.exists() | ||||
return tests_data_folder | return tests_data_folder |
generates