<commit_before>from ceph_installer import models, tasks


class TestCallAnsible(object):

    def setup(self):
        models.Task(
            identifier='aaaa',
            endpoint='/api/test/',
        )
        models.commit()

    def test_set_exit_code_on_error(self, session):
        tasks.call_ansible.apply(args=([], 'aaaa')).get()
        task = models.Task.get(1)
        assert task.exit_code == -1

    def test_set_exception_on_stderr(self, session, monkeypatch):
        def error(*a, **kw): raise OSError('a severe error')
        monkeypatch.setattr(tasks.process, 'run', error)
        tasks.call_ansible.apply(args=([], 'aaaa')).get()
        task = models.Task.get(1)<commit_msg>patch make_ansible_command in tests<commit_after>from ceph_installer import models, tasks


class TestCallAnsible(object):

    def setup(self):
        models.Task(
            identifier='aaaa',
            endpoint='/api/test/',
        )
        models.commit()

    def test_set_exit_code_on_error(self, session, monkeypatch):
        monkeypatch.setattr(
            tasks.process,
            'make_ansible_command',
            lambda *a, **kw: ['echo']
        )
        tasks.call_ansible.apply(args=([], 'aaaa')).get()
        task = models.Task.get(1)
        assert task.exit_code == -1

    def test_set_exception_on_stderr(self, session, monkeypatch):
        def error(*a, **kw): raise OSError('a severe error')
        monkeypatch.setattr(tasks.process, 'run', error)
        monkeypatch.setattr(
            tasks.process,
            'make_ansible_command',
            lambda *a, **kw: ['echo']
        )
        tasks.call_ansible.apply(args=([], 'aaaa')).get()
        task = models.Task.get(1)
{'fraction_non_alphanumeric': 0.13570180547466512, 'fraction_numerical': 0.0034944670937682005, 'mean_word_length': 2.456740442655936, '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': '6325017', 'n_tokens_mistral': 548, 'n_tokens_neox': 528, 'n_words': 99}