| 1 |
# Copyright 2019-2026 Facundo Batista, Nicolás Demarchi |
| 2 |
# |
| 3 |
# This program is free software: you can redistribute it and/or modify it |
| 4 |
# under the terms of the GNU General Public License version 3, as published |
| 5 |
# by the Free Software Foundation. |
| 6 |
# |
| 7 |
# This program is distributed in the hope that it will be useful, but |
| 8 |
# WITHOUT ANY WARRANTY; without even the implied warranties of |
| 9 |
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
| 10 |
# PURPOSE. See the GNU General Public License for more details. |
| 11 |
# |
| 12 |
# You should have received a copy of the GNU General Public License along |
| 13 |
# with this program. If not, see <http://www.gnu.org/licenses/>. |
| 14 |
# |
| 15 |
# For further info, check https://github.com/PyAr/fades |
| 16 |
|
| 17 |
import json |
| 18 |
import uuid |
| 19 |
|
| 20 |
from pytest import fixture |
| 21 |
|
| 22 |
|
| 23 |
@fixture(scope="function") |
| 24 |
def tmp_file(tmp_path): |
| 25 |
"""Fixture for a unique tmpfile for each test.""" |
| 26 |
yield tmp_path / "testfile" |
| 27 |
|
| 28 |
|
| 29 |
@fixture(scope="function") |
| 30 |
def create_tmpfile(tmp_path): |
| 31 |
|
| 32 |
def add_content(lines): |
| 33 |
"""Fixture for a unique tmpfile for each test.""" |
| 34 |
namefile = tmp_path / f"testfile_{uuid.uuid4()}" |
| 35 |
with open(namefile, "w", encoding="utf-8") as f: |
| 36 |
for line in lines: |
| 37 |
f.write(line + "\n") |
| 38 |
|
| 39 |
return namefile |
| 40 |
|
| 41 |
yield add_content |
| 42 |
|
| 43 |
|
| 44 |
def pytest_addoption(parser): |
| 45 |
"""Define new pytest command line argument to be used by integration tests.""" |
| 46 |
parser.addoption("--integtest-pyversion", action="store") |
| 47 |
|
| 48 |
|
| 49 |
@fixture |
| 50 |
def fake_venv(): |
| 51 |
"""Provides a fake venv data.""" |
| 52 |
|
| 53 |
def gen(extra="extra metadata", **kwargs): |
| 54 |
base = { |
| 55 |
"metadata": {"env_path": "foo", "env_bin_path": "bar", "extra": extra}, |
| 56 |
"installed": {}, |
| 57 |
"interpreter": "pythonX.Y", |
| 58 |
"options": {"foo": "bar"}, |
| 59 |
} |
| 60 |
base.update(kwargs) |
| 61 |
return json.dumps(base) |
| 62 |
|
| 63 |
return gen |