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
|
# ----------------------------------------------------------------------------
# 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 pathlib
from q2_fragment_insertion._format import PlacementsFormat
from qiime2.plugin.testing import TestPluginBase
from qiime2.plugin import ValidationError
class TestTransformers(TestPluginBase):
package = 'q2_fragment_insertion.tests'
def test_dict_to_placements_format(self):
transformer = self.get_transformer(dict, PlacementsFormat)
obs = transformer({'foo': 1})
with self.assertRaisesRegex(ValidationError, r'found \[\'foo\'\]'):
# A bit of a cop-out, but this means we were able to parse the
# JSON document.
obs.validate(level='max')
def test_placements_format_to_dict(self):
transformer = self.get_transformer(PlacementsFormat, dict)
fp = pathlib.Path(self.temp_dir.name) / pathlib.Path('placements.json')
fp.write_text('{"foo": 1}')
input_ = PlacementsFormat(str(fp), mode='r')
with self.assertRaisesRegex(ValidationError, r'found \[\'foo\'\]'):
# A bit of a cop-out, but this means we were able to parse the
# JSON document.
input_.validate(level='max')
obs = transformer(input_)
self.assertEqual(obs, {'foo': 1})
|