Skip to content

Commit

Permalink
Add a fixture to get the path to test files (#672)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillemBarroso authored Dec 9, 2022
1 parent 86b22b6 commit 1d20003
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 38 deletions.
4 changes: 4 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ def resolve_test_file(basename, additional_path="", is_in_examples=None):
)
return examples.find_files(filename)

@pytest.fixture()
def testfiles_dir():
"""Return the path of the testfiles directory."""
return _get_test_files_directory()

@pytest.fixture()
def allkindofcomplexity():
Expand Down
72 changes: 34 additions & 38 deletions tests/test_python_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,29 @@


@pytest.fixture(scope="module")
def load_all_types_plugin():
current_dir = os.getcwd()
def load_all_types_plugin(testfiles_dir):
return dpf.load_library(
dpf.path_utilities.to_server_os(
os.path.join(current_dir, "testfiles", "pythonPlugins", "all_types")
os.path.join(testfiles_dir, "pythonPlugins", "all_types")
),
"py_test_types",
"load_operators",
)


def load_all_types_plugin_with_serv(my_server):
current_dir = os.getcwd()
def load_all_types_plugin_with_serv(my_server, testfiles_dir):
return dpf.load_library(
dpf.path_utilities.to_server_os(
os.path.join(current_dir, "testfiles", "pythonPlugins", "all_types"), my_server
os.path.join(testfiles_dir, "pythonPlugins", "all_types"), my_server
),
"py_test_types",
"load_operators",
server=my_server,
)


def test_integral_types(server_type_remote_process):
load_all_types_plugin_with_serv(server_type_remote_process)
def test_integral_types(server_type_remote_process, testfiles_dir):
load_all_types_plugin_with_serv(server_type_remote_process, testfiles_dir)
op = dpf.Operator("custom_forward_int", server=server_type_remote_process)
op.connect(0, 1)
assert op.get_output(0, dpf.types.int) == 1
Expand All @@ -74,8 +72,8 @@ def test_integral_types(server_type_remote_process):
assert op.get_output(0, dpf.types.string) == "hello"


def test_lists(server_type_remote_process):
load_all_types_plugin_with_serv(server_type_remote_process)
def test_lists(server_type_remote_process, testfiles_dir):
load_all_types_plugin_with_serv(server_type_remote_process, testfiles_dir)
op = dpf.Operator(
"custom_forward_vec_int", server=server_type_remote_process
)
Expand All @@ -97,8 +95,8 @@ def test_lists(server_type_remote_process):
assert np.allclose(op.get_output(0, dpf.types.vec_double), np.ones((200)))


def test_field(server_type_remote_process):
load_all_types_plugin_with_serv(server_type_remote_process)
def test_field(server_type_remote_process, testfiles_dir):
load_all_types_plugin_with_serv(server_type_remote_process, testfiles_dir)
f = dpf.fields_factory.create_3d_vector_field(
3, "Elemental", server=server_type_remote_process
)
Expand All @@ -113,8 +111,8 @@ def test_field(server_type_remote_process):
assert op.get_output(0, dpf.types.field).location == "Elemental"


def test_property_field(server_type_remote_process):
load_all_types_plugin_with_serv(server_type_remote_process)
def test_property_field(server_type_remote_process, testfiles_dir):
load_all_types_plugin_with_serv(server_type_remote_process, testfiles_dir)
f = dpf.PropertyField(server=server_type_remote_process)
f.data = np.ones((9), dtype=np.int32)
op = dpf.Operator(
Expand All @@ -128,8 +126,8 @@ def test_property_field(server_type_remote_process):


@conftest.raises_for_servers_version_under("5.0")
def test_string_field(server_type_remote_process):
load_all_types_plugin_with_serv(server_type_remote_process)
def test_string_field(server_type_remote_process, testfiles_dir):
load_all_types_plugin_with_serv(server_type_remote_process, testfiles_dir)
f = dpf.StringField(server=server_type_remote_process)
f.data = ["hello", "good"]
op = dpf.Operator("custom_forward_string_field", server=server_type_remote_process)
Expand All @@ -138,8 +136,8 @@ def test_string_field(server_type_remote_process):


@conftest.raises_for_servers_version_under("5.0")
def test_custom_type_field(server_type_remote_process):
load_all_types_plugin_with_serv(server_type_remote_process)
def test_custom_type_field(server_type_remote_process, testfiles_dir):
load_all_types_plugin_with_serv(server_type_remote_process, testfiles_dir)
f = dpf.CustomTypeField(np.uint64, server=server_type_remote_process)
f.data = np.array([1000000000000, 200000000000000], dtype=np.uint64)
op = dpf.Operator("custom_forward_custom_type_field", server=server_type_remote_process)
Expand All @@ -150,16 +148,16 @@ def test_custom_type_field(server_type_remote_process):
)


def test_scoping(server_type_remote_process):
load_all_types_plugin_with_serv(server_type_remote_process)
def test_scoping(server_type_remote_process, testfiles_dir):
load_all_types_plugin_with_serv(server_type_remote_process, testfiles_dir)
f = dpf.Scoping(location="Elemental", server=server_type_remote_process)
op = dpf.Operator("custom_forward_scoping", server=server_type_remote_process)
op.connect(0, f)
assert op.get_output(0, dpf.types.scoping).location == "Elemental"


def test_fields_container(server_type_remote_process):
load_all_types_plugin_with_serv(server_type_remote_process)
def test_fields_container(server_type_remote_process, testfiles_dir):
load_all_types_plugin_with_serv(server_type_remote_process, testfiles_dir)
f = dpf.fields_factory.create_3d_vector_field(
3, "Elemental", server=server_type_remote_process
)
Expand All @@ -180,8 +178,8 @@ def test_fields_container(server_type_remote_process):
)


def test_scopings_container(server_type_remote_process):
load_all_types_plugin_with_serv(server_type_remote_process)
def test_scopings_container(server_type_remote_process, testfiles_dir):
load_all_types_plugin_with_serv(server_type_remote_process, testfiles_dir)
f = dpf.Scoping(location="Elemental", server=server_type_remote_process)
sc = dpf.ScopingsContainer(server=server_type_remote_process)
sc.add_scoping({}, f)
Expand All @@ -195,8 +193,8 @@ def test_scopings_container(server_type_remote_process):
)


def test_meshes_container(server_type_remote_process):
load_all_types_plugin_with_serv(server_type_remote_process)
def test_meshes_container(server_type_remote_process, testfiles_dir):
load_all_types_plugin_with_serv(server_type_remote_process, testfiles_dir)
f = dpf.MeshedRegion(server=server_type_remote_process)
sc = dpf.MeshesContainer(server=server_type_remote_process)
sc.add_mesh({}, f)
Expand All @@ -207,8 +205,8 @@ def test_meshes_container(server_type_remote_process):
assert len(op.get_output(0, dpf.types.meshes_container)) == 1


def test_data_sources(server_type_remote_process):
load_all_types_plugin_with_serv(server_type_remote_process)
def test_data_sources(server_type_remote_process, testfiles_dir):
load_all_types_plugin_with_serv(server_type_remote_process, testfiles_dir)
f = dpf.DataSources("file.rst", server=server_type_remote_process)
op = dpf.Operator(
"custom_forward_data_sources", server=server_type_remote_process
Expand All @@ -221,8 +219,8 @@ def test_data_sources(server_type_remote_process):

@pytest.mark.skipif(platform.system() == "Windows" and platform.python_version().startswith("3.8"),
reason="Random SEGFAULT in the GitHub pipeline for 3.8 on Windows")
def test_workflow(server_type_remote_process):
load_all_types_plugin_with_serv(server_type_remote_process)
def test_workflow(server_type_remote_process, testfiles_dir):
load_all_types_plugin_with_serv(server_type_remote_process, testfiles_dir)
f = dpf.Workflow(server=server_type_remote_process)
op = dpf.Operator(
"custom_forward_workflow", server=server_type_remote_process
Expand All @@ -231,8 +229,8 @@ def test_workflow(server_type_remote_process):
assert op.get_output(0, dpf.types.workflow) is not None


def test_data_tree(server_type_remote_process):
load_all_types_plugin_with_serv(server_type_remote_process)
def test_data_tree(server_type_remote_process, testfiles_dir):
load_all_types_plugin_with_serv(server_type_remote_process, testfiles_dir)
f = dpf.DataTree(server=server_type_remote_process)
f.add(name="Paul")
op = dpf.Operator(
Expand All @@ -245,11 +243,10 @@ def test_data_tree(server_type_remote_process):


@conftest.raises_for_servers_version_under("4.0")
def test_syntax_error(server_type_remote_process):
current_dir = os.getcwd()
def test_syntax_error(server_type_remote_process, testfiles_dir):
dpf.load_library(dpf.path_utilities.to_server_os(
os.path.join(
current_dir, "testfiles", "pythonPlugins", "syntax_error_plugin"
testfiles_dir, "pythonPlugins", "syntax_error_plugin"
), server_type_remote_process),
"py_raising",
"load_operators",
Expand Down Expand Up @@ -343,10 +340,9 @@ def test_create_properties_specification(server_in_process):


@conftest.raises_for_servers_version_under("4.0")
def test_custom_op_with_spec(server_type_remote_process):
current_dir = os.getcwd()
def test_custom_op_with_spec(server_type_remote_process, testfiles_dir):
dpf.load_library(dpf.path_utilities.to_server_os(
os.path.join(current_dir, "testfiles", "pythonPlugins"), server_type_remote_process),
os.path.join(testfiles_dir, "pythonPlugins"), server_type_remote_process),
"py_operator_with_spec",
"load_operators",
server=server_type_remote_process,
Expand Down

0 comments on commit 1d20003

Please sign in to comment.