File: test_pathmapper.py

package info (click to toggle)
cwltool 1.0.20181217162649%2Bdfsg-10
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,632 kB
  • sloc: python: 11,008; makefile: 153; sh: 22
file content (90 lines) | stat: -rw-r--r-- 2,335 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import pytest

from cwltool.pathmapper import PathMapper, normalizeFilesDirs


def test_subclass():
    class SubPathMapper(PathMapper):
        def __init__(self, referenced_files, basedir, stagedir, new):
            super(SubPathMapper, self).__init__(referenced_files, basedir, stagedir)
            self.new = new

    pathmap = SubPathMapper([], '', '', 'new')
    assert pathmap.new is not None, 'new'

normalization_parameters = [
    ('strip trailing slashes',
     {'class': 'Directory',
      'location': '/foo/bar/'
      },
     {'class': 'Directory',
      'location': '/foo/bar',
      'basename': 'bar'
      }
     ),
    ('file',
     {'class': 'File',
      'location': 'file1.txt'
      },
     {'class': 'File',
      'location': 'file1.txt',
      'basename': 'file1.txt',
      'nameext': '.txt',
      'nameroot': 'file1'
      }
     ),
    ('file with local uri',
     {'class': 'File',
      'location': 'file:///foo/file1.txt'
      },
     {'class': 'File',
      'location': 'file:///foo/file1.txt',
      'basename': 'file1.txt',
      'nameext': '.txt',
      'nameroot': 'file1'
      }
     ),
    ('file with http url',
     {'class': 'File',
      'location': 'http://example.com/file1.txt'
      },
     {'class': 'File',
      'location': 'http://example.com/file1.txt',
      'basename': 'file1.txt',
      'nameext': '.txt',
      'nameroot': 'file1'
      }
     )
]

@pytest.mark.parametrize('name,file_dir,expected', normalization_parameters)
def test_normalizeFilesDirs(name, file_dir, expected):
    normalizeFilesDirs(file_dir)
    assert file_dir == expected, name

# (filename, expected: (nameroot, nameext))
basename_generation_parameters = [
    ('foo.bar', ('foo', '.bar')),
    ('foo', ('foo', '')),
    ('.foo', ('.foo', '')),
    ('foo.', ('foo', '.')),
    ('foo.bar.baz', ('foo.bar', '.baz'))
]
@pytest.mark.parametrize('filename,expected', basename_generation_parameters)
def test_basename_field_generation(filename, expected):
    nameroot, nameext = expected
    expected = {
        'class': 'File',
        'location': '/foo/' + filename,
        'basename': filename,
        'nameroot': nameroot,
        'nameext': nameext
    }

    file = {
        'class': 'File',
        'location': '/foo/' + filename
    }

    normalizeFilesDirs(file)
    assert file == expected