Exemplo n.º 1
0
    def test_files(self, data_mock):
        data_annotation = {
            'output.list': {
                'value': [{
                    'file': "element.gz"
                }],
                'type': 'list:basic:file:'
            },
            'output.fastq': {
                'value': {
                    'file': "file.fastq.gz"
                },
                'type': 'basic:file:fastq'
            },
            'output.fastq_archive': {
                'value': {
                    'file': "archive.gz"
                },
                'type': 'basic:file:'
            },
            'input.fastq_url': {
                'value': {
                    'file': "blah"
                },
                'type': 'basic:url:'
            },
            'input.blah': {
                'value': "blah.gz",
                'type': 'basic:file:'
            }
        }
        bad_data_annotation = {
            'output.list': {
                'value': [{
                    'no_file_field_here': "element.gz"
                }],
                'type': 'list:basic:file:'
            },
        }
        data_mock.configure_mock(annotation=data_annotation)

        file_list = Data.files(data_mock)
        self.assertEqual(set(file_list),
                         set(['element.gz', 'archive.gz', 'file.fastq.gz']))
        file_list = Data.files(data_mock, file_name='element.gz')
        self.assertEqual(file_list, ['element.gz'])
        file_list = Data.files(data_mock, field_name='output.fastq')
        self.assertEqual(file_list, ['file.fastq.gz'])

        data_mock.configure_mock(annotation=bad_data_annotation)
        message = r"Item .* does not contain 'file' key."
        with six.assertRaisesRegex(self, KeyError, message):
            Data.files(data_mock)
Exemplo n.º 2
0
    def test_files(self, data_mock):
        data_annotation = {
            'output.fastq': {'value': {'file': "file.fastq.gz"}, 'type': 'basic:file:fastq'},
            'output.fastq_archive': {'value': {'file': "archive.gz"}, 'type': 'basic:file:'},
            'input.fastq_url': {'value': {'file': "blah"}, 'type': 'basic:url:'},
            'input.blah': {'value': "blah.gz", 'type': 'basic:file:'}
            }
        data_mock.configure_mock(annotation=data_annotation)

        file_list = Data.files(data_mock)
        self.assertEqual(set(file_list), set(['archive.gz', 'file.fastq.gz']))
        file_list = Data.files(data_mock, file_name='archive.gz')
        self.assertEqual(file_list, ['archive.gz'])
        file_list = Data.files(data_mock, field_name='output.fastq')
        self.assertEqual(file_list, ['file.fastq.gz'])
Exemplo n.º 3
0
    def test_add_output(self, data_mock):
        data_mock.configure_mock(
            annotation={
                'output.fastq': {
                    'type': 'basic:file:',
                    'value': {
                        'file': 'reads.fq'
                    }
                },
                'output.fasta': {
                    'type': 'basic:file:',
                    'value': {
                        'file': 'genome.fa'
                    }
                }
            })

        files_list = Data.files(data_mock, field_name="output.fastq")
        self.assertEqual(files_list, ['reads.fq'])

        files_list = Data.files(data_mock, field_name="fastq")
        self.assertEqual(files_list, ['reads.fq'])
Exemplo n.º 4
0
    def test_files(self):
        resolwe = MagicMock()
        data = Data(id=123, resolwe=resolwe)
        data._get_dir_files = MagicMock(
            side_effect=[['first_dir/file1.txt'], ['fastq_dir/file2.txt']])

        data.output = {
            'list': [{'file': "element.gz"}],
            'dir_list': [{'dir': "first_dir"}],
            'fastq': {'file': "file.fastq.gz"},
            'fastq_archive': {'file': "archive.gz"},
            'fastq_dir': {'dir': "fastq_dir"},
        }
        data.process = Process(resolwe=resolwe, output_schema=[
            {'name': 'list', 'label': 'List', 'type': 'list:basic:file:'},
            {'name': 'dir_list', 'label': 'Dir_list', 'type': 'list:basic:dir:'},
            {'name': 'fastq', 'label': 'Fastq', 'type': 'basic:file:fastq:'},
            {'name': 'fastq_archive', 'label': 'Fastq_archive', 'type': 'basic:file:'},
            {'name': 'fastq_dir', 'label': 'Fastq_dir', 'type': 'basic:dir:'},
        ])

        file_list = data.files()
        self.assertCountEqual(file_list, [
            'element.gz',
            'archive.gz',
            'file.fastq.gz',
            'first_dir/file1.txt',
            'fastq_dir/file2.txt'
        ])
        file_list = data.files(file_name='element.gz')
        self.assertEqual(file_list, ['element.gz'])
        file_list = data.files(field_name='output.fastq')
        self.assertEqual(file_list, ['file.fastq.gz'])

        data.output = {
            'list': [{'no_file_field_here': "element.gz"}],
        }
        data.process.output_schema = [
            {'name': 'list', 'label': 'List', 'type': 'list:basic:file:'},
        ]
        with self.assertRaisesRegex(KeyError, "does not contain 'file' key."):
            data.files()

        data = Data(resolwe=MagicMock(), id=None)
        with self.assertRaisesRegex(ValueError, "must be saved before"):
            data.files()
Exemplo n.º 5
0
    def test_files(self):
        data = Data(id=123, resolwe=MagicMock())
        data._get_dir_files = MagicMock(
            side_effect=[['first_dir/file1.txt'], ['fastq_dir/file2.txt']])

        data.output = {
            'list': [{'file': "element.gz"}],
            'dir_list': [{'dir': "first_dir"}],
            'fastq': {'file': "file.fastq.gz"},
            'fastq_archive': {'file': "archive.gz"},
            'fastq_dir': {'dir': "fastq_dir"},
        }
        data.process_output_schema = [
            {'name': 'list', 'label': 'List', 'type': 'list:basic:file:'},
            {'name': 'dir_list', 'label': 'Dir_list', 'type': 'list:basic:dir:'},
            {'name': 'fastq', 'label': 'Fastq', 'type': 'basic:file:fastq:'},
            {'name': 'fastq_archive', 'label': 'Fastq_archive', 'type': 'basic:file:'},
            {'name': 'fastq_dir', 'label': 'Fastq_dir', 'type': 'basic:dir:'},
        ]

        file_list = data.files()
        self.assertCountEqual(file_list, [
            'element.gz',
            'archive.gz',
            'file.fastq.gz',
            'first_dir/file1.txt',
            'fastq_dir/file2.txt'
        ])
        file_list = data.files(file_name='element.gz')
        self.assertEqual(file_list, ['element.gz'])
        file_list = data.files(field_name='output.fastq')
        self.assertEqual(file_list, ['file.fastq.gz'])

        data.output = {
            'list': [{'no_file_field_here': "element.gz"}],
        }
        data.process_output_schema = [
            {'name': 'list', 'label': 'List', 'type': 'list:basic:file:'},
        ]
        with self.assertRaisesRegex(KeyError, "does not contain 'file' key."):
            data.files()

        data = Data(resolwe=MagicMock(), id=None)
        with self.assertRaisesRegex(ValueError, "must be saved before"):
            data.files()
Exemplo n.º 6
0
    def test_files(self):
        data = Data(id=123, resolwe=MagicMock())
        data._get_dir_files = MagicMock(
            side_effect=[['first_dir/file1.txt'], ['fastq_dir/file2.txt']])

        data.annotation = {
            'output.list': {'value': [{'file': "element.gz"}], 'type': 'list:basic:file:'},
            'output.dir_list': {'value': [{'dir': "first_dir"}], 'type': 'list:basic:dir:'},
            'output.fastq': {'value': {'file': "file.fastq.gz"}, 'type': 'basic:file:fastq'},
            'output.fastq_archive': {'value': {'file': "archive.gz"}, 'type': 'basic:file:'},
            'output.fastq_dir': {'value': {'dir': "fastq_dir"}, 'type': 'basic:dir:'},
            'input.fastq_url': {'value': {'file': "blah"}, 'type': 'basic:url:'},
            'input.blah': {'value': "blah.gz", 'type': 'basic:file:'}
        }

        file_list = data.files()
        six.assertCountEqual(self, file_list, [
            'element.gz',
            'archive.gz',
            'file.fastq.gz',
            'first_dir/file1.txt',
            'fastq_dir/file2.txt'
        ])
        file_list = data.files(file_name='element.gz')
        self.assertEqual(file_list, ['element.gz'])
        file_list = data.files(field_name='output.fastq')
        self.assertEqual(file_list, ['file.fastq.gz'])

        data.annotation = {
            'output.list': {'value': [{'no_file_field_here': "element.gz"}],
                            'type': 'list:basic:file:'},
        }
        with six.assertRaisesRegex(self, KeyError, "does not contain 'file' key."):
            data.files()

        data = Data(resolwe=MagicMock(), id=None)
        with six.assertRaisesRegex(self, ValueError, "must be saved before"):
            data.files()
Exemplo n.º 7
0
    def test_files(self):
        data = Data(id=123, resolwe=MagicMock())
        data._get_dir_files = MagicMock(
            side_effect=[['first_dir/file1.txt'], ['fastq_dir/file2.txt']])

        data.annotation = {
            'output.list': {
                'value': [{
                    'file': "element.gz"
                }],
                'type': 'list:basic:file:'
            },
            'output.dir_list': {
                'value': [{
                    'dir': "first_dir"
                }],
                'type': 'list:basic:dir:'
            },
            'output.fastq': {
                'value': {
                    'file': "file.fastq.gz"
                },
                'type': 'basic:file:fastq'
            },
            'output.fastq_archive': {
                'value': {
                    'file': "archive.gz"
                },
                'type': 'basic:file:'
            },
            'output.fastq_dir': {
                'value': {
                    'dir': "fastq_dir"
                },
                'type': 'basic:dir:'
            },
            'input.fastq_url': {
                'value': {
                    'file': "blah"
                },
                'type': 'basic:url:'
            },
            'input.blah': {
                'value': "blah.gz",
                'type': 'basic:file:'
            }
        }

        file_list = data.files()
        six.assertCountEqual(self, file_list, [
            'element.gz', 'archive.gz', 'file.fastq.gz', 'first_dir/file1.txt',
            'fastq_dir/file2.txt'
        ])
        file_list = data.files(file_name='element.gz')
        self.assertEqual(file_list, ['element.gz'])
        file_list = data.files(field_name='output.fastq')
        self.assertEqual(file_list, ['file.fastq.gz'])

        data.annotation = {
            'output.list': {
                'value': [{
                    'no_file_field_here': "element.gz"
                }],
                'type': 'list:basic:file:'
            },
        }
        with six.assertRaisesRegex(self, KeyError,
                                   "does not contain 'file' key."):
            data.files()

        data = Data(resolwe=MagicMock(), id=None)
        with six.assertRaisesRegex(self, ValueError, "must be saved before"):
            data.files()
Exemplo n.º 8
0
    def test_files(self):
        resolwe = MagicMock()
        data = Data(id=123, resolwe=resolwe)
        data._get_dir_files = MagicMock(
            side_effect=[["first_dir/file1.txt"], ["fastq_dir/file2.txt"]])

        data.output = {
            "list": [{
                "file": "element.gz"
            }],
            "dir_list": [{
                "dir": "first_dir"
            }],
            "fastq": {
                "file": "file.fastq.gz"
            },
            "fastq_archive": {
                "file": "archive.gz"
            },
            "fastq_dir": {
                "dir": "fastq_dir"
            },
        }
        data.process = Process(
            resolwe=resolwe,
            output_schema=[
                {
                    "name": "list",
                    "label": "List",
                    "type": "list:basic:file:"
                },
                {
                    "name": "dir_list",
                    "label": "Dir_list",
                    "type": "list:basic:dir:"
                },
                {
                    "name": "fastq",
                    "label": "Fastq",
                    "type": "basic:file:fastq:"
                },
                {
                    "name": "fastq_archive",
                    "label": "Fastq_archive",
                    "type": "basic:file:",
                },
                {
                    "name": "fastq_dir",
                    "label": "Fastq_dir",
                    "type": "basic:dir:"
                },
            ],
        )

        file_list = data.files()
        self.assertCountEqual(
            file_list,
            [
                "element.gz",
                "archive.gz",
                "file.fastq.gz",
                "first_dir/file1.txt",
                "fastq_dir/file2.txt",
            ],
        )
        file_list = data.files(file_name="element.gz")
        self.assertEqual(file_list, ["element.gz"])
        file_list = data.files(field_name="output.fastq")
        self.assertEqual(file_list, ["file.fastq.gz"])

        data.output = {
            "list": [{
                "no_file_field_here": "element.gz"
            }],
        }
        data.process.output_schema = [
            {
                "name": "list",
                "label": "List",
                "type": "list:basic:file:"
            },
        ]
        with self.assertRaisesRegex(KeyError, "does not contain 'file' key."):
            data.files()

        data = Data(resolwe=MagicMock(), id=None)
        with self.assertRaisesRegex(ValueError, "must be saved before"):
            data.files()