1- import tempfile
1+ import typing as ty
22import attrs
33from pathlib import Path
44import pytest
1010from conftest import write_test_file
1111
1212
13- @pytest .fixture
14- def FooBarConverter ():
15- work_dir = Path (tempfile .mkdtemp ())
13+ @converter
14+ @python .define (outputs = {"out_file" : Bar }) # type: ignore[misc]
15+ def FooBarConverter (in_file : Foo ):
16+ return Bar (write_test_file (Path .cwd () / "bar.bar" , in_file .raw_contents ))
1617
17- @converter
18- @python .define (outputs = {"out_file" : Bar }) # type: ignore[misc]
19- def FooBarConverter_ (in_file : Foo ):
20- return Bar (write_test_file (work_dir / "bar.bar" , in_file .raw_contents ))
2118
22- return FooBarConverter_
19+ @converter (out_file = "out" )
20+ @python .define (outputs = {"out" : Bar }) # type: ignore[misc]
21+ def BazBarConverter (in_file : Baz ):
22+ assert in_file
23+ return Bar (write_test_file (Path .cwd () / "bar.bar" , in_file .raw_contents ))
2324
2425
25- @pytest . fixture
26- def BazBarConverter ():
27- work_dir = Path ( tempfile . mkdtemp ())
26+ @converter ( source_format = Foo , target_format = Qux )
27+ @ shell . define
28+ class FooQuxConverter ( shell . Task [ "FooQuxConverter.Outputs" ]):
2829
29- @converter (out_file = "out" )
30- @python .define (outputs = {"out" : Bar }) # type: ignore[misc]
31- def BazBarConverter_ (in_file : Baz ):
32- assert in_file
33- return Bar (write_test_file (work_dir / "bar.bar" , in_file .raw_contents ))
30+ in_file : File = shell .arg (help = "the input file" , argstr = "" )
31+ executable = "cp"
3432
35- return BazBarConverter_
33+ class Outputs (shell .Outputs ):
34+ out_file : File = shell .outarg (
35+ help = "output file" ,
36+ argstr = "" ,
37+ position = - 1 ,
38+ path_template = "out.qux" ,
39+ )
3640
3741
38- @pytest .fixture
39- def FooQuxConverter ():
40- @converter (source_format = Foo , target_format = Qux )
41- @shell .define
42- class FooQuxConverter_ (shell .Task ["FooQuxConverter_.Outputs" ]):
43-
44- in_file : File = shell .arg (help = "the input file" , argstr = "" )
45- executable = "cp"
46-
47- class Outputs (shell .Outputs ):
48- out_file : File = shell .outarg (
49- help = "output file" ,
50- argstr = "" ,
51- position = - 1 ,
52- path_template = "out.qux" ,
53- )
54-
55- return FooQuxConverter_
56-
57-
58- def test_get_converter_functask (FooBarConverter , work_dir ):
42+ def test_get_converter_functask (work_dir ):
5943
6044 fspath = work_dir / "test.foo"
6145 write_test_file (fspath )
6246 assert attrs .asdict (Bar .get_converter (Foo ).task ) == attrs .asdict (FooBarConverter ())
6347
6448
65- def test_get_converter_shellcmd (FooQuxConverter , work_dir ):
49+ def test_get_converter_shellcmd (work_dir ):
6650
6751 fspath = work_dir / "test.foo"
6852 write_test_file (fspath )
@@ -77,7 +61,7 @@ def test_get_converter_fail(work_dir):
7761 Baz .get_converter (Foo )
7862
7963
80- def test_convert_functask (FooBarConverter , work_dir ):
64+ def test_convert_functask (work_dir ):
8165
8266 fspath = work_dir / "test.foo"
8367 write_test_file (fspath )
@@ -87,7 +71,7 @@ def test_convert_functask(FooBarConverter, work_dir):
8771 assert bar .raw_contents == foo .raw_contents
8872
8973
90- def test_convert_shellcmd (FooQuxConverter , work_dir ):
74+ def test_convert_shellcmd (work_dir ):
9175
9276 fspath = work_dir / "test.foo"
9377 write_test_file (fspath )
@@ -97,11 +81,19 @@ def test_convert_shellcmd(FooQuxConverter, work_dir):
9781 assert qux .raw_contents == foo .raw_contents
9882
9983
100- def test_convert_mapped_conversion (BazBarConverter , work_dir ):
84+ def test_convert_mapped_conversion (work_dir ):
10185
10286 fspath = work_dir / "test.baz"
10387 write_test_file (fspath )
10488 baz = Baz (fspath )
10589 bar = Bar .convert (baz )
10690 assert type (bar ) is Bar
10791 assert bar .raw_contents == baz .raw_contents
92+
93+
94+ def test_convertible_from ():
95+
96+ assert Bar .convertible_from () == ty .Union [Bar , Foo , Baz ]
97+ assert Qux .convertible_from () == ty .Union [Qux , Foo ]
98+ assert Foo .convertible_from () == Foo
99+ assert Baz .convertible_from () == Baz
0 commit comments