<commit_before>import ceph_medic
from ceph_medic import runner
from ceph_medic.tests import base_metadata
from textwrap import dedent
from ceph_medic.util import configuration


class TestRunner(object):

    def setup(self):
        runner.metadata = base_metadata

    def teardown(self):
        runner.metadata = base_metadata

    def test_calculate_total_hosts_is_0(self):
        run = runner.Runner()
        assert run.total_hosts == 0

    def test_calculate_hosts_single_daemon_type(self):
        ceph_medic.metadata['nodes']['osds'] = [{'host': 'node1'},{'host': 'node2'}]
        runner.metadata = ceph_medic.metadata
        run = runner.Runner()
        assert run.total_hosts == 2

    def test_count_from_different_daemon_types(self):
        ceph_medic.metadata['nodes']['osds'] = [{'host': 'node1'},{'host': 'node2'}]
        ceph_medic.metadata['nodes']['mons'] = [{'host': 'node3'},{'host': 'node4'}]
        runner.metadata = ceph_medic.metadata
        run = runner.Runner()
        assert run.total_hosts == 4


class TestReport(object):

    def setup(self):
        runner.metadata = base_metadata
        runner.metadata['nodes'] = {}
        self.results = runner.Runner()

    def test_reports_errors(self, terminal):
        self.results.errors = ['I am an error']
        runner.report(self.results)
        assert 'While running checks, ceph-medic had unhandled errors' in terminal.calls[-1]

    def test_reports_no_errors(self, terminal):
        runner.report(self.results)
        assert terminal.calls[0] == '\n0 passed, on 0 hosts'


class TestReportBasicOutput(object):

    def setup(self):
        contents = dedent("""
        [global]
        #
        """)
        conf = configuration.load_string(contents)
        ceph_medic.config.file = conf
        runner.metadata = base_metadata
        runner.metadata['cluster_name'] = 'ceph'
        runner.Runner().run()

    def teardown(self):
        runner.metadata = base_metadata

    def test_has_version(self, terminal):
        assert 'Version: ' in terminal.get_output()

    def test_has_cluster_name(self, terminal):
        assert 'Cluster Name: "ceph"' in terminal.get_output()<commit_msg>tests: verify new separate warning/error reporting<commit_after>import ceph_medic
from ceph_medic import runner
from ceph_medic.tests import base_metadata
from textwrap import dedent
from ceph_medic.util import configuration


class TestRunner(object):

    def setup(self):
        runner.metadata = base_metadata

    def teardown(self):
        runner.metadata = base_metadata

    def test_calculate_total_hosts_is_0(self):
        run = runner.Runner()
        assert run.total_hosts == 0

    def test_calculate_hosts_single_daemon_type(self):
        ceph_medic.metadata['nodes']['osds'] = [{'host': 'node1'},{'host': 'node2'}]
        runner.metadata = ceph_medic.metadata
        run = runner.Runner()
        assert run.total_hosts == 2

    def test_count_from_different_daemon_types(self):
        ceph_medic.metadata['nodes']['osds'] = [{'host': 'node1'},{'host': 'node2'}]
        ceph_medic.metadata['nodes']['mons'] = [{'host': 'node3'},{'host': 'node4'}]
        runner.metadata = ceph_medic.metadata
        run = runner.Runner()
        assert run.total_hosts == 4


class TestReport(object):

    def setup(self):
        runner.metadata = base_metadata
        runner.metadata['nodes'] = {}
        self.results = runner.Runner()

    def test_reports_internal_errors(self, terminal):
        self.results.internal_errors = ['I am an error']
        runner.report(self.results)
        assert 'While running checks, ceph-medic had 1 unhandled errors' in terminal.calls[-1]

    def test_reports_no_errors(self, terminal):
        runner.report(self.results)
        assert terminal.calls[0] == '\n0 passed, on 0 hosts'

    def test_reports_warning(self, terminal):
        self.results.warnings = 1
        runner.report(self.results)
        assert terminal.calls[0] == '\n0 passed, 1 warning, on 0 hosts'

    def test_reports_warnings(self, terminal):
        self.results.warnings = 2
        runner.report(self.results)
        assert terminal.calls[0] == '\n0 passed, 2 warnings, on 0 hosts'

    def test_reports_error(self, terminal):
        self.results.errors = 1
        runner.report(self.results)
        assert terminal.calls[0] == '\n0 passed, 1 error, on 0 hosts'

    def test_reports_errors(self, terminal):
        self.results.errors = 2
        runner.report(self.results)
        assert terminal.calls[0] == '\n0 passed, 2 errors, on 0 hosts'

    def test_reports_error_and_warning(self, terminal):
        self.results.errors = 1
        self.results.warnings = 1
        runner.report(self.results)
        assert terminal.calls[0] == '\n0 passed, 1 error, 1 warning, on 0 hosts'

    def test_reports_errors_and_warnings(self, terminal):
        self.results.errors = 2
        self.results.warnings = 2
        runner.report(self.results)
        assert terminal.calls[0] == '\n0 passed, 2 errors, 2 warnings, on 0 hosts'


class TestReportBasicOutput(object):

    def setup(self):
        contents = dedent("""
        [global]
        #
        """)
        conf = configuration.load_string(contents)
        ceph_medic.config.file = conf
        runner.metadata = base_metadata
        runner.metadata['cluster_name'] = 'ceph'
        runner.Runner().run()

    def teardown(self):
        runner.metadata = base_metadata

    def test_has_version(self, terminal):
        assert 'Version: ' in terminal.get_output()

    def test_has_cluster_name(self, terminal):
        assert 'Cluster Name: "ceph"' in terminal.get_output()
{'fraction_non_alphanumeric': 0.11704565485633704, 'fraction_numerical': 0.01110523532522475, 'mean_word_length': 2.973389355742297, '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': '1186304', 'n_tokens_mistral': 1765, 'n_tokens_neox': 1689, 'n_words': 383}