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 91 92 93 94 95 96 97 98 99 100
|
# ----------------------------------------------------------------------------
# Copyright (c) 2016-2023, QIIME 2 development team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file LICENSE, distributed with this software.
# ----------------------------------------------------------------------------
import os
import shutil
from q2_fragment_insertion._format import (
PlacementsFormat, SeppReferenceDirFmt, RAxMLinfoFormat)
from qiime2.plugin.testing import TestPluginBase
from qiime2.plugin import ValidationError
class TestPlacementFormat(TestPluginBase):
package = 'q2_fragment_insertion.tests'
def test_validate_positive(self):
filepath = self.get_data_path('placements.json')
fmt = PlacementsFormat(filepath, mode='r')
fmt.validate()
self.assertTrue(True)
def test_validate_negative_array(self):
filepath = self.get_data_path('root-array.json')
fmt = PlacementsFormat(filepath, mode='r')
with self.assertRaisesRegex(ValidationError, 'JSON object'):
fmt.validate()
def test_validate_negative_missing_keys(self):
filepath = self.get_data_path('placements-missing.json')
fmt = PlacementsFormat(filepath, mode='r')
with self.assertRaisesRegex(ValidationError,
'found.*placements.*tree'):
fmt.validate()
class TestSeppReferenceDirFmt(TestPluginBase):
package = 'q2_fragment_insertion.tests'
def _cp_fp(self, frm, to):
shutil.copy(self.get_data_path(frm),
os.path.join(self.temp_dir.name, to))
def test_validate_positive(self):
self._cp_fp('ref-tree.nwk', 'tree.nwk')
self._cp_fp('ref-seqs-aligned.fasta', 'aligned-dna-sequences.fasta')
self._cp_fp('ref-raxml-info.txt', 'raxml-info.txt')
fmt = SeppReferenceDirFmt(self.temp_dir.name, mode='r')
fmt.validate()
self.assertTrue(True)
def test_validate_negative_missing_seqs(self):
self._cp_fp('ref-tree.nwk', 'tree.nwk')
self._cp_fp('seqs-to-query.fasta', 'aligned-dna-sequences.fasta')
self._cp_fp('ref-raxml-info.txt', 'raxml-info.txt')
fmt = SeppReferenceDirFmt(self.temp_dir.name, mode='r')
with self.assertRaisesRegex(ValidationError,
'missing in the phylogeny.*testseqa'):
fmt.validate()
def test_validate_negative_missing_tips(self):
self._cp_fp('another-ref-tree.nwk', 'tree.nwk')
self._cp_fp('ref-seqs-aligned.fasta', 'aligned-dna-sequences.fasta')
self._cp_fp('ref-raxml-info.txt', 'raxml-info.txt')
fmt = SeppReferenceDirFmt(self.temp_dir.name, mode='r')
with self.assertRaisesRegex(ValidationError,
'missing in the alignment.*b.*c'):
fmt.validate()
class TestRAxMLinfoFormat(TestPluginBase):
package = 'q2_fragment_insertion.tests'
def test_validate_positive(self):
filepath = self.get_data_path('ref-raxml-info.txt')
fmt = RAxMLinfoFormat(filepath, mode='r')
fmt.validate()
self.assertTrue(True)
def test_validate_negative_array(self):
filepath = self.get_data_path('root-array.json')
fmt = RAxMLinfoFormat(filepath, mode='r')
with self.assertRaisesRegex(ValidationError, 'Missing.*RAxML'):
fmt.validate()
|