<commit_before># ----------------------------------------------------------------------------
# Copyright (c) 2016--, QIIME 2 development team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
# ----------------------------------------------------------------------------

import os.path
import unittest
import tempfile
import shutil

from click.testing import CliRunner
from qiime import Artifact, Visualization
from qiime.core.testing.type import IntSequence1
from qiime.core.archive import ImportProvenanceCapture


from q2cli.info import info
from q2cli.tools import tools
from q2cli.commands import RootCommand


class CliTests(unittest.TestCase):

    def setUp(self):
        self.runner = CliRunner()
        self.tempdir = tempfile.mkdtemp(prefix='qiime2-test-temp-')
        self.artifact1_path = os.path.join(self.tempdir, 'a1.qza')

        artifact1 = Artifact._from_view(
            IntSequence1, [0, 42, 43], list,
            provenance_capture=ImportProvenanceCapture())
        artifact1.save(self.artifact1_path)
        self.artifact1_root_dir = str(artifact1.uuid)

    def tearDown(self):
        shutil.rmtree(self.tempdir)

    def test_info(self):
        result = self.runner.invoke(info)
        self.assertEqual(result.exit_code, 0)
        # May not always start with "System versions" if cache updating message
        # is printed.
        self.assertIn('System versions', result.output)
        self.assertIn('Installed plugins', result.output)
        self.assertIn('dummy-plugin', result.output)

    def test_list_commands(self):
        # top level commands, including a plugin, are present
        qiime_cli = RootCommand()
        commands = qiime_cli.list_commands(ctx=None)
        self.assertTrue('info' in commands)
        self.assertTrue('tools' in commands)
        self.assertTrue('dummy-plugin' in commands)

    def test_plugin_list_commands(self):
        # plugin commands are present including method (from function),
        # method (from markdown) and visualizer
        qiime_cli = RootCommand()
        command = qiime_cli.get_command(ctx=None, name='dummy-plugin')
        commands = command.list_commands(ctx=None)
        self.assertTrue('split-ints' in commands)
        self.assertTrue('split-ints-markdown' in commands)
        self.assertTrue('mapping-viz' in commands)

        self.assertFalse('split_ints' in commands)
        self.assertFalse('split_ints_markdown' in commands)
        self.assertFalse('mapping_viz' in commands)

    def test_extract(self):
        result = self.runner.invoke(
            tools, ['extract', self.artifact1_path, '--output-dir',
                    self.tempdir])
        # command completes sucessfully and creates the correct
        # output directory
        self.assertEqual(result.exit_code, 0)<commit_msg>MAINT: update tests for markdown method removal (#105)<commit_after># ----------------------------------------------------------------------------
# Copyright (c) 2016--, QIIME 2 development team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
# ----------------------------------------------------------------------------

import os.path
import unittest
import tempfile
import shutil

from click.testing import CliRunner
from qiime import Artifact, Visualization
from qiime.core.testing.type import IntSequence1
from qiime.core.archive import ImportProvenanceCapture


from q2cli.info import info
from q2cli.tools import tools
from q2cli.commands import RootCommand


class CliTests(unittest.TestCase):

    def setUp(self):
        self.runner = CliRunner()
        self.tempdir = tempfile.mkdtemp(prefix='qiime2-test-temp-')
        self.artifact1_path = os.path.join(self.tempdir, 'a1.qza')

        artifact1 = Artifact._from_view(
            IntSequence1, [0, 42, 43], list,
            provenance_capture=ImportProvenanceCapture())
        artifact1.save(self.artifact1_path)
        self.artifact1_root_dir = str(artifact1.uuid)

    def tearDown(self):
        shutil.rmtree(self.tempdir)

    def test_info(self):
        result = self.runner.invoke(info)
        self.assertEqual(result.exit_code, 0)
        # May not always start with "System versions" if cache updating message
        # is printed.
        self.assertIn('System versions', result.output)
        self.assertIn('Installed plugins', result.output)
        self.assertIn('dummy-plugin', result.output)

    def test_list_commands(self):
        # top level commands, including a plugin, are present
        qiime_cli = RootCommand()
        commands = qiime_cli.list_commands(ctx=None)
        self.assertTrue('info' in commands)
        self.assertTrue('tools' in commands)
        self.assertTrue('dummy-plugin' in commands)

    def test_plugin_list_commands(self):
        # plugin commands are present including a method and visualizer
        qiime_cli = RootCommand()
        command = qiime_cli.get_command(ctx=None, name='dummy-plugin')
        commands = command.list_commands(ctx=None)
        self.assertTrue('split-ints' in commands)
        self.assertTrue('mapping-viz' in commands)

        self.assertFalse('split_ints' in commands)
        self.assertFalse('mapping_viz' in commands)

    def test_extract(self):
        result = self.runner.invoke(
            tools, ['extract', self.artifact1_path, '--output-dir',
                    self.tempdir])
        # command completes sucessfully and creates the correct
        # output directory
        self.assertEqual(result.exit_code, 0)
{'fraction_non_alphanumeric': 0.14094903339191564, 'fraction_numerical': 0.009666080843585237, 'mean_word_length': 2.5064695009242146, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5735919', 'n_tokens_mistral': 1601, 'n_tokens_neox': 1524, 'n_words': 398}