# Path: q2_types/sample_data/_format.py
# class AlphaDiversityFormat(model.TextFileFormat):
#     def _validate_(self, level):
#         with self.open() as fh:
#             header, records_seen, is_min = None, 0, level == 'min'
#             fh_ = csv.reader(fh, delimiter='\t')
#             file_ = enumerate(fh_, 1) if is_min else zip(range(1, 11), fh_)
#             for i, cells in file_:
#                 if header is None:
#                     if len(cells) < 2:
#                         raise ValidationError(
#                             'Found header on line %d with the following '
#                             'columns: %s (length: %d), expected at least 2 '
#                             'columns.' % (i, cells, len(cells)))
#                     else:
#                         header = cells
#                 else:
#                     if len(cells) != len(header):
#                         raise ValidationError(
#                             'Line %d has %s cells (%s), expected %s.'
#                             % (i, len(cells), cells, len(header)))
# 
#                     records_seen += 1
# 
#             # The first non-comment and non-blank row observed will always be
#             # the header row, and since we have no requirement on the field
#             # names (because they are dynamically defined), so no need to check
#             # for the presence (or validity) of a header row at this point.
# 
#             if records_seen == 0:
#                 raise ValidationError('No records found in file, only '
#                                       'observed comments, blank lines, and/or '
#                                       'a header row.')


import unittest
import pandas as pd
import qiime2
from pandas.testing import assert_series_equal
from q2_types.sample_data import AlphaDiversityFormat
from qiime2.plugin.testing import TestPluginBase
        exp_index = pd.Index(['Sample1', 'Sample4'], dtype=object)
        exp = pd.Series([0.970950594455, 0.721928094887],
                        name='shannon', index=exp_index)
        assert_series_equal(exp, obs)

    def test_alpha_diversity_format_to_pd_series_int_indices(self):
        filename = 'alpha-diversity-int-indices.tsv'
        _, obs = self.transform_format(AlphaDiversityFormat, pd.Series,
                                       filename)

        exp_index = pd.Index(['1', '4'], dtype=object)
        exp = pd.Series([0.97, 0.72], name='foo', index=exp_index)
        assert_series_equal(exp, obs)

    def test_alpha_diversity_format_to_metadata(self):
        filename = 'alpha-diversity.tsv'
        _, obs = self.transform_format(AlphaDiversityFormat, qiime2.Metadata,
                                       filename)

        exp_index = pd.Index(['Sample1', 'Sample4'], name='Sample ID',
                             dtype=object)
        exp_df = pd.DataFrame([[0.9709505944546688], [0.7219280948873623]],
                              columns=['shannon'], index=exp_index)
        exp_md = qiime2.Metadata(exp_df)

        self.assertEqual(obs, exp_md)

    def test_non_alpha_diversity(self):
        filename = 'also-not-alpha-diversity.tsv'
        with self.assertRaisesRegex(ValueError, 'Non-numeric values '):

# Path: q2_types/sample_data/_format.py
# class AlphaDiversityFormat(model.TextFileFormat):
#     def _validate_(self, level):
#         with self.open() as fh:
#             header, records_seen, is_min = None, 0, level == 'min'
#             fh_ = csv.reader(fh, delimiter='\t')
#             file_ = enumerate(fh_, 1) if is_min else zip(range(1, 11), fh_)
#             for i, cells in file_:
#                 if header is None:
#                     if len(cells) < 2:
#                         raise ValidationError(
#                             'Found header on line %d with the following '
#                             'columns: %s (length: %d), expected at least 2 '
#                             'columns.' % (i, cells, len(cells)))
#                     else:
#                         header = cells
#                 else:
#                     if len(cells) != len(header):
#                         raise ValidationError(
#                             'Line %d has %s cells (%s), expected %s.'
#                             % (i, len(cells), cells, len(header)))
# 
#                     records_seen += 1
# 
#             # The first non-comment and non-blank row observed will always be
#             # the header row, and since we have no requirement on the field
#             # names (because they are dynamically defined), so no need to check
#             # for the presence (or validity) of a header row at this point.
# 
#             if records_seen == 0:
#                 raise ValidationError('No records found in file, only '
#                                       'observed comments, blank lines, and/or '
#                                       'a header row.')


# Path: q2_types/sample_data/tests/test_transformer.py
import unittest
import pandas as pd
import qiime2
from pandas.testing import assert_series_equal
from q2_types.sample_data import AlphaDiversityFormat
from qiime2.plugin.testing import TestPluginBase

        exp_index = pd.Index(['Sample1', 'Sample4'], dtype=object)
        exp = pd.Series([0.970950594455, 0.721928094887],
                        name='shannon', index=exp_index)
        assert_series_equal(exp, obs)

    def test_alpha_diversity_format_to_pd_series_int_indices(self):
        filename = 'alpha-diversity-int-indices.tsv'
        _, obs = self.transform_format(AlphaDiversityFormat, pd.Series,
                                       filename)

        exp_index = pd.Index(['1', '4'], dtype=object)
        exp = pd.Series([0.97, 0.72], name='foo', index=exp_index)
        assert_series_equal(exp, obs)

    def test_alpha_diversity_format_to_metadata(self):
        filename = 'alpha-diversity.tsv'
        _, obs = self.transform_format(AlphaDiversityFormat, qiime2.Metadata,
                                       filename)

        exp_index = pd.Index(['Sample1', 'Sample4'], name='Sample ID',
                             dtype=object)
        exp_df = pd.DataFrame([[0.9709505944546688], [0.7219280948873623]],
                              columns=['shannon'], index=exp_index)
        exp_md = qiime2.Metadata(exp_df)

        self.assertEqual(obs, exp_md)

    def test_non_alpha_diversity(self):
        filename = 'also-not-alpha-diversity.tsv'
        with self.assertRaisesRegex(ValueError, 'Non-numeric values '):

            self.transform_format(AlphaDiversityFormat, pd.Series, filename)