<commit_before>import sys
from unittest import TestCase

from mock import MagicMock, patch

from apsconnectcli.apsconnect import APSConnectUtil
from apsconnectcli.hub import APS, Hub, osaapi_raise_for_status

if sys.version_info >= (3,):
    _BUILTINS_OPEN = 'builtins.open'
    _BUILTINS_PRINT = 'builtins.print'
else:
    _BUILTINS_OPEN = 'apsconnectcli.apsconnect.open'
    _BUILTINS_PRINT = 'apsconnectcli.apsconnect.print'


class OsaApiRaiseForStatusTest(TestCase):
    """Tests for apsconnect._osaapi_raise_for_status"""

    _SUCCESS_CODE = 0
    _FAKE_ERR_CODE = 100500
    _FAKE_ERR_MSG = 'Not enough minerals.'

    def test_response_with_error_message(self):
        resp_with_err_msg = {
            'status': self._FAKE_ERR_CODE,
            'error_message': self._FAKE_ERR_MSG
        }
        self.assertRaisesRegexp(Exception,
                                r'Error: {}'.format(self._FAKE_ERR_MSG),
                                osaapi_raise_for_status,
                                resp_with_err_msg)

    def test_response_with_status_without_err_msg(self):
        response = {
            'status': self._FAKE_ERR_CODE
        }
        self.assertRaisesRegexp(Exception,
                                r'Error: Unknown {}'.format(response),
                                osaapi_raise_for_status,
                                response)

    def test_successful_response(self):
        response = {
            'status': self._SUCCESS_CODE
        }
        osaapi_raise_for_status(response)  # no exceptions


class TestHub(TestCase):
    def test_supported_version(self):
        with patch('apsconnectcli.hub.sys') as sys_mock:
            _assert_supported_version('oa-8.2-1216')

            sys_mock.exit.assert_not_called()

    def test_unsupported_version(self):
        with patch('apsconnectcli.hub.sys') as sys_mock:
            _assert_supported_version('oa-7.0-1216')

            sys_mock.exit.assert_called_with(1)

    def test_get_resclass_name_for_current_units(self):
        data = {
            'Kbit/sec': 'rc.saas.resource.kbps',
            'kb': 'rc.saas.resource',
            'mb-h': 'rc.saas.resource.mbh',
            'mhz': 'rc.saas.resource.mhz',
            'mhzh': 'rc.saas.resource.mhzh',
            'unit': 'rc.saas.resource.unit',
            'unit-h': 'rc.saas.resource.unith'
        }

        for key, value in data.items():
            self.assertEqual(Hub._get_resclass_name(key), value)

    def test_get_resclass_name_for_new_unit(self):
        self.assertEqual(
            Hub._get_resclass_name('new-unit'),
            'rc.saas.resource.unit',
        )
<commit_msg>Fixed test after identation issue<commit_after>import sys
from unittest import TestCase

from mock import MagicMock, patch

from apsconnectcli.apsconnect import APSConnectUtil
from apsconnectcli.hub import APS, Hub, osaapi_raise_for_status

if sys.version_info >= (3,):
    _BUILTINS_OPEN = 'builtins.open'
    _BUILTINS_PRINT = 'builtins.print'
else:
    _BUILTINS_OPEN = 'apsconnectcli.apsconnect.open'
    _BUILTINS_PRINT = 'apsconnectcli.apsconnect.print'


class OsaApiRaiseForStatusTest(TestCase):
    """Tests for apsconnect._osaapi_raise_for_status"""

    _SUCCESS_CODE = 0
    _FAKE_ERR_CODE = 100500
    _FAKE_ERR_MSG = 'Not enough minerals.'

    def test_response_with_error_message(self):
        resp_with_err_msg = {
            'status': self._FAKE_ERR_CODE,
            'error_message': self._FAKE_ERR_MSG
        }
        self.assertRaisesRegexp(Exception,
                                r'Error: {}'.format(self._FAKE_ERR_MSG),
                                osaapi_raise_for_status,
                                resp_with_err_msg)

    def test_response_with_status_without_err_msg(self):
        response = {
            'status': self._FAKE_ERR_CODE
        }
        self.assertRaisesRegexp(Exception,
                                r'Error: Unknown {}'.format(response),
                                osaapi_raise_for_status,
                                response)

    def test_successful_response(self):
        response = {
            'status': self._SUCCESS_CODE
        }
        osaapi_raise_for_status(response)  # no exceptions


class TestHub(TestCase):
    def test_supported_version(self):
        with patch('apsconnectcli.hub.sys') as sys_mock:
            HUB._assert_supported_version('oa-8.2-1216')

            sys_mock.exit.assert_not_called()

    def test_unsupported_version(self):
        with patch('apsconnectcli.hub.sys') as sys_mock:
            HUB._assert_supported_version('oa-7.0-1216')

            sys_mock.exit.assert_called_with(1)

    def test_get_resclass_name_for_current_units(self):
        data = {
            'Kbit/sec': 'rc.saas.resource.kbps',
            'kb': 'rc.saas.resource',
            'mb-h': 'rc.saas.resource.mbh',
            'mhz': 'rc.saas.resource.mhz',
            'mhzh': 'rc.saas.resource.mhzh',
            'unit': 'rc.saas.resource.unit',
            'unit-h': 'rc.saas.resource.unith'
        }

        for key, value in data.items():
            self.assertEqual(Hub._get_resclass_name(key), value)

    def test_get_resclass_name_for_new_unit(self):
        self.assertEqual(
            Hub._get_resclass_name('new-unit'),
            'rc.saas.resource.unit',
        )

{'fraction_non_alphanumeric': 0.0990990990990991, 'fraction_numerical': 0.007882882882882882, 'mean_word_length': 2.212176009644364, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3171831', 'n_tokens_mistral': 1736, 'n_tokens_neox': 1669, 'n_words': 252}