def get_tests(): plugin = create_plugin() tests = [] pm = PluginManager(add_plugins=False) pm.add_plugin(plugin) for action in plugin.actions.values(): for name in action.examples: tests.append((action, name)) return tests
class ReplayConfig(): """ fields: -use the usage driver to be used for provenance replay - dump_recorded_metadata If True, replay should write the metadata recorded in provenance to disk in .tsv format - use_recorded_metadata If True, replay should use the metadata recorded in provenance - pm an instance of the QIIME 2 PluginManager - md_context_has_been_printed a flag set by default and used internally, allows context to be printed once and only once. - no_provenance_context_has_been_printed indicates the no-provenance context documentation has not been printed - header if True, an introductory how-to header should be rendered to the script - verbose if True, progress will be reported to stdout - md_out_fp the directory path where caputred metadata should be written """ use: Usage use_recorded_metadata: bool = False pm: PluginManager = PluginManager() md_context_has_been_printed: bool = False no_provenance_context_has_been_printed: bool = False header: bool = True verbose: bool = False dump_recorded_metadata: bool = True md_out_fp: FileName = ''
def setUp(self): # setup test plugin self.test_plugin = Plugin(name='validator_test_plugin', version='0.0.1', website='test.com', package='qiime2.core.tests', project_name='validator_test') self.pm = PluginManager() # setup test data self.simple_int_seq = IntSequenceFormat() with self.simple_int_seq.open() as fh: fh.write('\n'.join(map(str, range(3)))) self.simple_int_seq.validate(level='max')
def __init__(self, action_type, plugin_id, action_id): from qiime2.sdk import PluginManager super().__init__() self._plugin = PluginManager().get_plugin(id=plugin_id) self.action = self._plugin.actions[action_id] self.action_type = action_type self.inputs = OrderedKeyValue() self.parameters = OrderedKeyValue() self.output_name = '' self._action_citations = [] for idx, citation in enumerate(self.action.citations): citation_key = self.make_citation_key( 'action', self._plugin, ':'.join([self.action_type, self.action.id]), idx) self.citations[citation_key.key] = citation self._action_citations.append(citation_key)
def test_get_qiime2_type_name_and_predicate(self): pm = PluginManager() q2plugin = pm.plugins['feature-classifier'] parameters = q2plugin.methods['classify_sklearn'].signature.parameters # testing regular parameters exp = ('Int', None) obs = get_qiime2_type_name_and_predicate(parameters['n_jobs']) self.assertEqual(exp, obs) # testing union parameters exp = ('Float', { 'type': 'predicate', 'name': 'Range', 'range': [0, 1], 'inclusive': [True, True] }) obs = get_qiime2_type_name_and_predicate(parameters['confidence']) self.assertEqual(exp, obs)
def test_validator_sorts(self): self.pm = PluginManager() test_object = self.pm.validators[Squid] self.assertFalse(test_object._is_sorted) exp = [ 'validator_sort_first', 'validator_sort_middle', 'validator_sort_middle_b', 'validator_sort_last' ] exp2 = [ 'validator_sort_first', 'validator_sort_middle_b', 'validator_sort_middle', 'validator_sort_last' ] obs = [record.validator.__name__ for record in test_object.validators] self.assertIn(obs, [exp, exp2]) self.assertTrue(test_object._is_sorted)
class TestValidatorIntegration(unittest.TestCase): def setUp(self): # setup test plugin self.test_plugin = Plugin(name='validator_test_plugin', version='0.0.1', website='test.com', package='qiime2.core.tests', project_name='validator_test') self.pm = PluginManager() # setup test data self.simple_int_seq = IntSequenceFormat() with self.simple_int_seq.open() as fh: fh.write('\n'.join(map(str, range(3)))) self.simple_int_seq.validate(level='max') def tearDown(self): # This is a deadman switch to ensure that the test_plugin has been # added self.assertIn(self.test_plugin.name, self.pm.plugins) self.pm.forget_singleton() def test_validator_from_each_type_in_expression(self): @self.test_plugin.register_validator(IntSequence1 | AscIntSequence) def blank_validator(data: list, level): pass self.pm.add_plugin(self.test_plugin) def test_no_transformer_available(self): @self.test_plugin.register_validator(IntSequence1 | Kennel[Dog]) def blank_validator(data: list, level): pass with self.assertRaisesRegex( AssertionError, r"Kennel\[Dog\].*blank_validator.*transform.*builtins:list"): self.pm.add_plugin(self.test_plugin)
# 1. We are going to loop on the Q2_EXTRA_COMMANDS to check which extra # commands we want to add, extra from those given in the next step # 2. We are going loop over QIITA_Q2_SEMANTIC_TYPE (lookup table) so we can # retrieve the q2plugin and their methods that work with that given Q2/Qiita # semantic type. Then we will ignore any plugin not in Q2_ALLOWED_PLUGINS so # we avoid adding plugins that we don't want; like deblur or dada2. Finally, # we are going to loop over the different inputs, outputs and parameters from # Q2 and convert them to QIITA's req_params, opt_params and outputs. # # Note that Qiita users like to have descriptions of the paramters # (q2-description) vs. the parameter itself (q2-parameter) so to allow this # we are going to store each parameter twice: one in the # opt_params[q2-description]: value; and # req_params['qp-hide-param' + q2-description]: q2-parameter pm = PluginManager() methods_to_add = [] for plugin_name, method_name in Q2_EXTRA_COMMANDS: q2plugin = pm.plugins[plugin_name] m = q2plugin.methods[method_name] methods_to_add.append((q2plugin, m)) for qiita_artifact, q2_artifacts in QIITA_Q2_SEMANTIC_TYPE.items(): if q2_artifacts['expression']: actions = [ a for e in q2_artifacts['expression'] for a in actions_by_input_type('%s[%s]' % (q2_artifacts['name'], e)) ] else: actions = actions_by_input_type(q2_artifacts['name'])
def setUp(self): pm = PluginManager(add_plugins=False) pm.add_plugin(self.plugin)