1
- import tempfile
1
+ import typing as ty
2
2
import attrs
3
3
from pathlib import Path
4
4
import pytest
10
10
from conftest import write_test_file
11
11
12
12
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 ))
16
17
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 ))
21
18
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 ))
23
24
24
25
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" ]):
28
29
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"
34
32
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
+ )
36
40
37
41
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 ):
59
43
60
44
fspath = work_dir / "test.foo"
61
45
write_test_file (fspath )
62
46
assert attrs .asdict (Bar .get_converter (Foo ).task ) == attrs .asdict (FooBarConverter ())
63
47
64
48
65
- def test_get_converter_shellcmd (FooQuxConverter , work_dir ):
49
+ def test_get_converter_shellcmd (work_dir ):
66
50
67
51
fspath = work_dir / "test.foo"
68
52
write_test_file (fspath )
@@ -77,7 +61,7 @@ def test_get_converter_fail(work_dir):
77
61
Baz .get_converter (Foo )
78
62
79
63
80
- def test_convert_functask (FooBarConverter , work_dir ):
64
+ def test_convert_functask (work_dir ):
81
65
82
66
fspath = work_dir / "test.foo"
83
67
write_test_file (fspath )
@@ -87,7 +71,7 @@ def test_convert_functask(FooBarConverter, work_dir):
87
71
assert bar .raw_contents == foo .raw_contents
88
72
89
73
90
- def test_convert_shellcmd (FooQuxConverter , work_dir ):
74
+ def test_convert_shellcmd (work_dir ):
91
75
92
76
fspath = work_dir / "test.foo"
93
77
write_test_file (fspath )
@@ -97,11 +81,19 @@ def test_convert_shellcmd(FooQuxConverter, work_dir):
97
81
assert qux .raw_contents == foo .raw_contents
98
82
99
83
100
- def test_convert_mapped_conversion (BazBarConverter , work_dir ):
84
+ def test_convert_mapped_conversion (work_dir ):
101
85
102
86
fspath = work_dir / "test.baz"
103
87
write_test_file (fspath )
104
88
baz = Baz (fspath )
105
89
bar = Bar .convert (baz )
106
90
assert type (bar ) is Bar
107
91
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