Skip to content

Commit

Permalink
SQUASH: Added test .tsv files added a test method
Browse files Browse the repository at this point in the history
  • Loading branch information
David-Rod committed Aug 9, 2019
1 parent 51cbb8f commit 608dfc6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
16 changes: 9 additions & 7 deletions q2_types/feature_data/_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def _check_n_records(self, n=None):
file_ = enumerate(fh) if n is None else zip(range(n), fh)

for i, line in file_:
# Checks rows in the file, excludes header row
# Tracks line count for error reporting
i = i + 1
if line == '':
# EOF
Expand All @@ -122,15 +122,17 @@ def _check_n_records(self, n=None):
"must be the first two header "
"values to be valid.\n\n The "
"first two header values "
"provided are: {}."
.format(cells[:2]))
"provided are: {}.\nIssue on "
"line {}"
.format(cells[:2], i))
header = cells
else:
if len(cells) != len(header):
raise ValidationError('Number of columns are not the '
'same as number of headers in '
'the file. \nHeader values: '
'{} \nColumn values: {} '
raise ValidationError("Number of columns are not the "
"same as number of headers in "
"the file. \nHeader values: "
"{} \nColumn values: {}\nIssue "
"on line: {}"
.format(header, cells[:], i))

data_lines += 1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Feature ID Taxon
seq1 k__Bacteria; p__Proteobacteria -1.0
seq2 k__Bacteria 1.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Feature ID Taxon Confidence Random
seq1 k__Foo; p__Bar -1.0
seq2 k__Foo; p__Baz -42.0
12 changes: 12 additions & 0 deletions q2_types/feature_data/tests/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,18 @@ def test_tsv_taxonomy_directory_format(self):

format.validate()

def test_tsv_taxonomy_format_column_header_lengths(self):
filenames = ['greater-column-length.tsv', 'greater-header-length.tsv']

filepaths = [self.get_data_path(os.path.join('taxonomy', filename))
for filename in filenames]

for filepath in filepaths:
format = TSVTaxonomyFormat(filepath, mode='r')

with self.assertRaisesRegex(ValidationError, 'Number of columns'):
format.validate()


class TestDNAFASTAFormats(TestPluginBase):
package = 'q2_types.feature_data.tests'
Expand Down

0 comments on commit 608dfc6

Please sign in to comment.