def test_parse_q2_data_file_does_not_exist(self): resource_file = self.create_tempfile(suffix='.qza') resource_filename = resource_file.name resource_file.close() with self.assertRaisesRegex(ConfigurationError, r"does not exist"): _parse_q2_data(resource_filename, SampleData[AlphaDiversity], view_type=pd.Series)
def test_parse_q2_data_wrong_semantic_type(self): resource_filename = self.create_tempfile(suffix='.qza').name test_series = pd.Series({'feature1': 'k__1', 'feature2': 'k__2'}, name='Taxon') test_series.index.name = 'Feature ID' imported_artifact = Artifact.import_data( # the distincion here is that this is not alpha diversity "FeatureData[Taxonomy]", test_series ) imported_artifact.save(resource_filename) with self.assertRaisesRegex(ConfigurationError, r"Expected (.*) " r"'SampleData\[AlphaDiversity\]'. " r"Received 'FeatureData\[Taxonomy\]'."): _parse_q2_data(resource_filename, SampleData[AlphaDiversity], view_type=pd.Series)
def test_parse_q2_data(self): resource_filename = self.create_tempfile(suffix='.qza').name test_series = pd.Series({'sample1': 7.15, 'sample2': 9.04}, name='chao1') imported_artifact = Artifact.import_data( "SampleData[AlphaDiversity]", test_series ) imported_artifact.save(resource_filename) loaded_artifact = _parse_q2_data(resource_filename, SampleData[AlphaDiversity], view_type=pd.Series) assert_series_equal(test_series, loaded_artifact)