<commit_before># -*- coding: utf-8 -*-
from __future__ import unicode_literals, print_function, absolute_import
import unittest
from pybsd.systems import System, SystemError
from pybsd.systems.commands import BaseCommand, CommandError


class NoNameCommand(BaseCommand):
    pass

class NoBinaryCommand(BaseCommand):
    name = 'command_name'

class BaseCommandTestCase(unittest.TestCase):

    def test_no_name_command(self):
        with self.assertRaises(CommandError) as context_manager:
            _bc = NoNameCommand(env='something')
        self.assertEqual(context_manager.exception.message, u'`name` property is missing')

    def test_env_executor(self):
        with self.assertRaises(SystemError) as context_manager:
            _bc = NoBinaryCommand(env='something')
        self.assertEqual(context_manager.exception.message, u'`something` must have a callable Executor method')

    # def test_no_binary_command(self):
    #     with self.assertRaises(SystemError) as context_manager:
    #         _bc = NoBinaryCommand(env='something')
    #     self.assertEqual(context_manager.exception.message, u'`something` must have a callable Executor method')<commit_msg>Adds a couple of systems.commands tests<commit_after># -*- coding: utf-8 -*-
from __future__ import unicode_literals, print_function, absolute_import
import six
import unittest
from pybsd.systems import System, SystemError
from pybsd.systems.commands import BaseCommand, CommandError


class NoNameCommand(BaseCommand):
    pass

class NoBinaryCommand(BaseCommand):
    name = 'command_name'

class BaseCommandTestCase(unittest.TestCase):

    params = {
        'name': 'system',
        'hostname': 'system.foo.bar',
        'ext_if': ('re0', ['8.8.8.8/24']),
        'int_if': ('eth0', ['192.168.0.0/24'])
    }

    def setUp(self):
        self.system = System(**self.params)

    def test_no_name_command(self):
        with self.assertRaises(CommandError) as context_manager:
            _bc = NoNameCommand(env='something')
        self.assertEqual(context_manager.exception.message, u'`name` property is missing')

    def test_env_no_executor(self):
        with self.assertRaises(SystemError) as context_manager:
            _bc = NoBinaryCommand(env='something')
        self.assertEqual(context_manager.exception.message, u'`something` must have a callable Executor method')

    def test_env_executor_not_callable(self):
        self.system._exec = None
        with self.assertRaises(SystemError) as context_manager:
            _bc = NoBinaryCommand(env='something')
        self.assertEqual(context_manager.exception.message, u'`something` must have a callable Executor method')

    def test_no_binary_command(self):
        _bc = NoBinaryCommand(env=self.system)
        with self.assertRaises(NotImplementedError) as context_manager:
            _bc.invoke()
        message = context_manager.exception.message if six.PY2 else context_manager.exception.args[0]
        self.assertEqual(message, u'`command_name` is not implemented on this system')

    # def test_no_binary_command(self):
    #     with self.assertRaises(SystemError) as context_manager:
    #         _bc = NoBinaryCommand(env='something')
    #     self.assertEqual(context_manager.exception.message, u'`something` must have a callable Executor method')
{'fraction_non_alphanumeric': 0.09873570138470801, 'fraction_numerical': 0.006622516556291391, 'mean_word_length': 3.915680473372781, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '2220308', 'n_tokens_mistral': 965, 'n_tokens_neox': 936, 'n_words': 212}