comparison env/lib/python3.9/site-packages/cwltool/tests/test_pathmapper.py @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
1 from typing import List, Tuple
2
3 import pytest
4
5 from cwltool.pathmapper import PathMapper
6 from cwltool.utils import CWLObjectType, normalizeFilesDirs
7
8
9 def test_subclass() -> None:
10 class SubPathMapper(PathMapper):
11 def __init__(
12 self,
13 referenced_files: List[CWLObjectType],
14 basedir: str,
15 stagedir: str,
16 new: str,
17 ):
18 super().__init__(referenced_files, basedir, stagedir)
19 self.new = new
20
21 pathmap = SubPathMapper([], "", "", "new")
22 assert pathmap.new is not None, "new"
23
24
25 normalization_parameters = [
26 (
27 "strip trailing slashes",
28 {"class": "Directory", "location": "/foo/bar/"},
29 {"class": "Directory", "location": "/foo/bar", "basename": "bar"},
30 ),
31 (
32 "file",
33 {"class": "File", "location": "file1.txt"},
34 {
35 "class": "File",
36 "location": "file1.txt",
37 "basename": "file1.txt",
38 "nameext": ".txt",
39 "nameroot": "file1",
40 },
41 ),
42 (
43 "file with local uri",
44 {"class": "File", "location": "file:///foo/file1.txt"},
45 {
46 "class": "File",
47 "location": "file:///foo/file1.txt",
48 "basename": "file1.txt",
49 "nameext": ".txt",
50 "nameroot": "file1",
51 },
52 ),
53 (
54 "file with http url",
55 {"class": "File", "location": "http://example.com/file1.txt"},
56 {
57 "class": "File",
58 "location": "http://example.com/file1.txt",
59 "basename": "file1.txt",
60 "nameext": ".txt",
61 "nameroot": "file1",
62 },
63 ),
64 ]
65
66
67 @pytest.mark.parametrize("name,file_dir,expected", normalization_parameters)
68 def test_normalizeFilesDirs(
69 name: str, file_dir: CWLObjectType, expected: CWLObjectType
70 ) -> None:
71 normalizeFilesDirs(file_dir)
72 assert file_dir == expected, name
73
74
75 # (filename, expected: (nameroot, nameext))
76 basename_generation_parameters = [
77 ("foo.bar", ("foo", ".bar")),
78 ("foo", ("foo", "")),
79 (".foo", (".foo", "")),
80 ("foo.", ("foo", ".")),
81 ("foo.bar.baz", ("foo.bar", ".baz")),
82 ]
83
84
85 @pytest.mark.parametrize("filename,expected", basename_generation_parameters)
86 def test_basename_field_generation(filename: str, expected: Tuple[str, str]) -> None:
87 nameroot, nameext = expected
88 expected2 = {
89 "class": "File",
90 "location": "/foo/" + filename,
91 "basename": filename,
92 "nameroot": nameroot,
93 "nameext": nameext,
94 }
95
96 my_file = {"class": "File", "location": "/foo/" + filename}
97
98 normalizeFilesDirs(my_file)
99 assert my_file == expected2