workflow_job_tests.py 5.15 KB
Newer Older
1
2
import unittest
from chipathlon.workflow_job import WorkflowJob
3
from Pegasus.DAX3 import *
4
5
6
import yaml
import os

7

8
9
10
class WorkflowJobTests(unittest.TestCase):

    def setUp(self):
11
        self.base_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "workflow_job")
12
13
14
15
        return

    def test_invalid_base(self):
        job = WorkflowJob(
16
            os.path.join(self.base_path, "invalid_base.yaml"),
17
18
19
20
21
22
23
24
            {},
            debug=True
        )
        self.assertFalse(job.is_valid(), msg=job.get_error_string())
        return

    def test_no_file_type(self):
        job = WorkflowJob(
25
            os.path.join(self.base_path, "no_file_type.yaml"),
26
27
28
29
30
31
32
33
            {},
            debug=True
        )
        self.assertFalse(job.is_valid(), msg=job.get_error_string())
        return

    def test_missing_resources(self):
        job = WorkflowJob(
34
            os.path.join(self.base_path, "missing_resources.yaml"),
35
36
37
38
39
40
41
42
            {},
            debug=True
        )
        self.assertFalse(job.is_valid(), msg=job.get_error_string())
        return

    def test_bad_resources(self):
        job = WorkflowJob(
43
            os.path.join(self.base_path, "bad_resources.yaml"),
44
45
46
47
48
49
50
51
            {},
            debug=True
        )
        self.assertFalse(job.is_valid(), msg=job.get_error_string())
        return

    def test_bad_arguments(self):
        job = WorkflowJob(
52
            os.path.join(self.base_path, "bad_arguments.yaml"),
53
54
55
56
57
58
59
60
            {},
            debug=True
        )
        self.assertFalse(job.is_valid(), msg=job.get_error_string())
        return

    def test_bad_references(self):
        job = WorkflowJob(
61
            os.path.join(self.base_path, "bad_references.yaml"),
62
63
64
65
66
67
68
69
            {},
            debug=True
        )
        self.assertFalse(job.is_valid(), msg=job.get_error_string())
        return

    def test_valid_job(self):
        job = WorkflowJob(
70
            os.path.join(self.base_path, "download_from_encode.yaml"),
71
72
73
74
75
76
            {},
            debug=True
        )
        self.assertTrue(job.is_valid(), msg=job.get_error_string())
        return

77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
    def test_create_job_missing_inputs(self):
        job = WorkflowJob(
            os.path.join(self.base_path, "download_from_encode.yaml"),
            {},
            debug=True
        )
        executable = Executable(name="ls", os="linux", arch="x86_64", installed=True)
        executable.addPFN(PFN(os.path.join("file://", "/bin/ls"), "local"))
        job.add_executable(executable)
        pegasus_job = job.create_job(
            {
                "md5": {
                    "name": "md5",
                    "type": "string",
                    "value": "asdfasdf"
                }
            },
            {
                "downloaded_file": {
                    "name": "full-name.fastq",
                    "type": "file",
                    "transfer": True,
                    "file": File("full-name.fastq")
                }
            }
        )
        self.assertEqual(pegasus_job, None, msg=job.get_error_string())
        return

    def test_create_job_missing_outputs(self):
        job = WorkflowJob(
            os.path.join(self.base_path, "download_from_encode.yaml"),
            {},
            debug=True
        )
        executable = Executable(name="ls", os="linux", arch="x86_64", installed=True)
        executable.addPFN(PFN(os.path.join("file://", "/bin/ls"), "local"))
        job.add_executable(executable)
        pegasus_job = job.create_job(
            {
                "url": {
                    "name": "url",
                    "type": "string",
                    "value": "some.encode.url.org/asdf"
                },
                "md5": {
                    "name": "md5",
                    "type": "string",
                    "value": "asdfasdf"
                }
            },
            {}
        )
        self.assertEqual(pegasus_job, None, msg=job.get_error_string())
        return

    def test_create_job_valid(self):
        job = WorkflowJob(
            os.path.join(self.base_path, "download_from_encode.yaml"),
            {},
            debug=True
        )
        executable = Executable(name="ls", os="linux", arch="x86_64", installed=True)
        executable.addPFN(PFN(os.path.join("file://", "/bin/ls"), "local"))
        job.add_executable(executable)
        pegasus_job = job.create_job(
            {
                "url": {
                    "name": "url",
                    "type": "string",
                    "value": "some.encode.url.org/asdf"
                },
                "md5": {
                    "name": "md5",
                    "type": "string",
                    "value": "asdfasdf"
                }
            },
            {
                "downloaded_file": {
                    "name": "full-name.fastq",
                    "type": "file",
                    "transfer": True,
                    "file": File("full-name.fastq")
                }
            }
        )
        self.assertEqual(pegasus_job, None, msg=job.get_error_string())
        return

167
168
169
170
if __name__ == "__main__":
    unittest.TextTestRunner(verbosity=2).run(
        unittest.TestLoader().loadTestsFromTestCase(WorkflowJobTests)
    )