Skip to content

Commit

Permalink
chore: fix test
Browse files Browse the repository at this point in the history
Signed-off-by: ThibaultFy <[email protected]>
  • Loading branch information
ThibaultFy committed Oct 2, 2024
1 parent 8f140ba commit 9299c8d
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 96 deletions.
78 changes: 77 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import json
import os
import sys
from pathlib import Path
from uuid import uuid4

import pytest

import substra
Expand All @@ -7,6 +13,10 @@
from .fl_interface import FLFunctionInputs
from .fl_interface import FLFunctionOutputs
from .fl_interface import FunctionCategory
from substra.tools.task_resources import TaskResources
from substra.tools.utils import import_module
from substra.tools.workspace import FunctionWorkspace
from tests.tools.utils import OutputIdentifiers


def pytest_configure(config):
Expand All @@ -24,7 +34,7 @@ def client(tmpdir):

@pytest.fixture
def workdir(tmp_path):
d = tmp_path / "substra-cli"
d = tmp_path / "substra-workspace"
d.mkdir()
return d

Expand Down Expand Up @@ -131,3 +141,69 @@ def asset_factory():
@pytest.fixture()
def data_sample(asset_factory):
return asset_factory.create_data_sample()


@pytest.fixture(autouse=True)
def patch_cwd(monkeypatch, workdir):
# this is needed to ensure the workspace is located in a tmpdir
def getcwd():
return str(workdir)

monkeypatch.setattr(os, "getcwd", getcwd)


@pytest.fixture()
def valid_opener_code():
return """
import json
from substratools import Opener
class FakeOpener(Opener):
def get_data(self, folder):
return 'X', list(range(0, 3))
def fake_data(self, n_samples):
return ['Xfake'] * n_samples, [0] * n_samples
"""


@pytest.fixture()
def valid_opener(valid_opener_code):
import_module("opener", valid_opener_code)
yield
del sys.modules["opener"]


@pytest.fixture()
def valid_opener_script(workdir, valid_opener_code):
opener_path = workdir / "my_opener.py"
opener_path.write_text(valid_opener_code)

return str(opener_path)


@pytest.fixture(autouse=True)
def output_model_path(workdir: Path) -> str:
path = workdir / str(uuid4())
yield path
if path.exists():
os.remove(path)


@pytest.fixture(autouse=True)
def output_model_path_2(workdir: Path) -> str:
path = workdir / str(uuid4())
yield path
if path.exists():
os.remove(path)


@pytest.fixture()
def valid_function_workspace(output_model_path: str) -> FunctionWorkspace:
workspace_outputs = TaskResources(
json.dumps([{"id": OutputIdentifiers.shared, "value": str(output_model_path), "multiple": False}])
)

workspace = FunctionWorkspace(outputs=workspace_outputs)

return workspace
4 changes: 2 additions & 2 deletions tests/tools/test_aggregatealgo.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from substratools.task_resources import TaskResources
from substratools.workspace import FunctionWorkspace
from tests.tools import utils
from tests.utils import InputIdentifiers
from tests.utils import OutputIdentifiers
from tests.tools.utils import InputIdentifiers
from tests.tools.utils import OutputIdentifiers


@pytest.fixture(autouse=True)
Expand Down
4 changes: 2 additions & 2 deletions tests/tools/test_compositealgo.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
from substratools.task_resources import TaskResources
from substratools.workspace import FunctionWorkspace
from tests.tools import utils
from tests.utils import InputIdentifiers
from tests.utils import OutputIdentifiers
from tests.tools.utils import InputIdentifiers
from tests.tools.utils import OutputIdentifiers


@pytest.fixture(autouse=True)
Expand Down
4 changes: 2 additions & 2 deletions tests/tools/test_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
from substratools.task_resources import TaskResources
from substratools.workspace import FunctionWorkspace
from tests.tools import utils
from tests.utils import InputIdentifiers
from tests.utils import OutputIdentifiers
from tests.tools.utils import InputIdentifiers
from tests.tools.utils import OutputIdentifiers


@pytest.fixture(autouse=True)
Expand Down
4 changes: 2 additions & 2 deletions tests/tools/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
from substratools.task_resources import TaskResources
from substratools.workspace import FunctionWorkspace
from tests.tools import utils
from tests.utils import InputIdentifiers
from tests.utils import OutputIdentifiers
from tests.tools.utils import InputIdentifiers
from tests.tools.utils import OutputIdentifiers


@pytest.fixture()
Expand Down
4 changes: 2 additions & 2 deletions tests/tools/test_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
from substratools.utils import import_module
from substratools.workspace import FunctionWorkspace
from tests.tools import utils
from tests.utils import InputIdentifiers
from tests.utils import OutputIdentifiers
from tests.tools.utils import InputIdentifiers
from tests.tools.utils import OutputIdentifiers


@pytest.fixture
Expand Down
85 changes: 0 additions & 85 deletions tests/tools/tools_conftest.py

This file was deleted.

0 comments on commit 9299c8d

Please sign in to comment.