Skip to content

Commit d4ba3c1

Browse files
authored
Merge pull request #104 from ArcanaFramework/fixes-pydra-import
moves test_converter into extras package and fixes pydra import
2 parents c31a2ee + 69249ff commit d4ba3c1

File tree

2 files changed

+17
-26
lines changed

2 files changed

+17
-26
lines changed

fileformats/core/tests/test_converter.py renamed to extras/fileformats/extras/core/tests/test_converter.py

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,33 @@
99
from fileformats.core.exceptions import FormatConversionError
1010
from conftest import write_test_file
1111

12-
try:
13-
import pydra.mark
14-
except ImportError:
15-
pydra = None
1612

17-
18-
@pytest.fixture(scope="session")
19-
def foo_bar_converter():
13+
@pytest.fixture
14+
def FooBarConverter():
2015
work_dir = Path(tempfile.mkdtemp())
2116

2217
@converter
2318
@python.define(outputs={"out_file": Bar}) # type: ignore[misc]
24-
def foo_bar_converter_(in_file: Foo):
19+
def FooBarConverter_(in_file: Foo):
2520
return Bar(write_test_file(work_dir / "bar.bar", in_file.raw_contents))
2621

27-
return foo_bar_converter_
22+
return FooBarConverter_
2823

2924

30-
@pytest.fixture(scope="session")
31-
def baz_bar_converter():
25+
@pytest.fixture
26+
def BazBarConverter():
3227
work_dir = Path(tempfile.mkdtemp())
3328

3429
@converter(out_file="out")
3530
@python.define(outputs={"out": Bar}) # type: ignore[misc]
36-
def baz_bar_converter_(in_file: Baz):
31+
def BazBarConverter_(in_file: Baz):
3732
assert in_file
3833
return Bar(write_test_file(work_dir / "bar.bar", in_file.raw_contents))
3934

40-
return baz_bar_converter_
35+
return BazBarConverter_
4136

4237

43-
@pytest.fixture(scope="session")
38+
@pytest.fixture
4439
def FooQuxConverter():
4540
@converter(source_format=Foo, target_format=Qux)
4641
@shell.define
@@ -60,25 +55,20 @@ class Outputs(shell.Outputs):
6055
return FooQuxConverter_
6156

6257

63-
@pytest.mark.skipif(pydra is None, reason="Pydra could not be imported")
64-
def test_get_converter_functask(foo_bar_converter, work_dir):
58+
def test_get_converter_functask(FooBarConverter, work_dir):
6559

6660
fspath = work_dir / "test.foo"
6761
write_test_file(fspath)
68-
assert attrs.asdict(Bar.get_converter(Foo).task) == attrs.asdict(
69-
foo_bar_converter()
70-
)
62+
assert attrs.asdict(Bar.get_converter(Foo).task) == attrs.asdict(FooBarConverter())
7163

7264

73-
@pytest.mark.skipif(pydra is None, reason="Pydra could not be imported")
7465
def test_get_converter_shellcmd(FooQuxConverter, work_dir):
7566

7667
fspath = work_dir / "test.foo"
7768
write_test_file(fspath)
7869
assert attrs.asdict(Qux.get_converter(Foo).task) == attrs.asdict(FooQuxConverter())
7970

8071

81-
@pytest.mark.skipif(pydra is None, reason="Pydra could not be imported")
8272
def test_get_converter_fail(work_dir):
8373

8474
fspath = work_dir / "test.foo"
@@ -87,8 +77,7 @@ def test_get_converter_fail(work_dir):
8777
Baz.get_converter(Foo)
8878

8979

90-
@pytest.mark.skipif(pydra is None, reason="Pydra could not be imported")
91-
def test_convert_functask(foo_bar_converter, work_dir):
80+
def test_convert_functask(FooBarConverter, work_dir):
9281

9382
fspath = work_dir / "test.foo"
9483
write_test_file(fspath)
@@ -98,7 +87,6 @@ def test_convert_functask(foo_bar_converter, work_dir):
9887
assert bar.raw_contents == foo.raw_contents
9988

10089

101-
@pytest.mark.skipif(pydra is None, reason="Pydra could not be imported")
10290
def test_convert_shellcmd(FooQuxConverter, work_dir):
10391

10492
fspath = work_dir / "test.foo"
@@ -109,8 +97,7 @@ def test_convert_shellcmd(FooQuxConverter, work_dir):
10997
assert qux.raw_contents == foo.raw_contents
11098

11199

112-
@pytest.mark.skipif(pydra is None, reason="Pydra could not be imported")
113-
def test_convert_mapped_conversion(baz_bar_converter, work_dir):
100+
def test_convert_mapped_conversion(BazBarConverter, work_dir):
114101

115102
fspath = work_dir / "test.baz"
116103
write_test_file(fspath)

fileformats/core/extras.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ def type_match(mtype: ty.Union[str, type], ftype: ty.Union[str, type]) -> bool:
9595
ftype : Union[str, type]
9696
the type of the function argument
9797
"""
98+
99+
if isinstance(mtype, str) and not isinstance(ftype, str):
100+
mtype = eval(mtype, implementation.__globals__)
101+
98102
return (
99103
mtype is ty.Any # type: ignore[comparison-overlap]
100104
or mtype == ftype

0 commit comments

Comments
 (0)