示例#1
0
    def test_to_terminal(self, ranks_mock, reset_mock):
        ranks_mock.__getitem__.side_effect = lambda j: '<|{0}|>'.format(j)
        reset_mock.__eq__.side_effect = lambda o: o == '__R__'

        h = harvest.MIHarvester([], self.config)
        h._results = [
            ('a', {
                'error': 'mystr'
            }),
            ('b', {
                'mi': 25,
                'rank': 'A'
            }),
            ('c', {
                'mi': 15,
                'rank': 'B'
            }),
            ('d', {
                'mi': 0,
                'rank': 'C'
            }),
        ]

        self.assertEqual(list(h.to_terminal()), [
            ('a', ('mystr', ), {
                'error': True
            }),
            ('{0} - {1}{2}{3}{4}',
             ('c', '<|B|>', 'B', ' (15.00)', '__R__'), {}),
            ('{0} - {1}{2}{3}{4}',
             ('d', '<|C|>', 'C', ' (0.00)', '__R__'), {}),
        ])
示例#2
0
def test_mi_to_terminal(mi_config, mocker):
    reset_mock = mocker.patch('radon.cli.harvest.RESET')
    ranks_mock = mocker.patch('radon.cli.harvest.MI_RANKS')
    ranks_mock.__getitem__.side_effect = lambda j: '<|{0}|>'.format(j)
    reset_mock.__eq__.side_effect = lambda o: o == '__R__'

    h = harvest.MIHarvester([], mi_config)
    h._results = [
        ('a', {
            'error': 'mystr'
        }),
        ('b', {
            'mi': 25,
            'rank': 'A'
        }),
        ('c', {
            'mi': 15,
            'rank': 'B'
        }),
        ('d', {
            'mi': 0,
            'rank': 'C'
        }),
    ]

    assert list(h.to_terminal()) == [
        ('a', ('mystr', ), {
            'error': True
        }),
        ('{0} - {1}{2}{3}{4}', ('c', '<|B|>', 'B', ' (15.00)', '__R__'), {}),
        ('{0} - {1}{2}{3}{4}', ('d', '<|C|>', 'C', ' (0.00)', '__R__'), {}),
    ]
示例#3
0
    def test_gobble(self, mv_mock):
        fobj = mock.MagicMock()
        fobj.read.return_value = mock.sentinel.one
        mv_mock.return_value = 23.5

        h = harvest.MIHarvester([], self.config)
        result = h.gobble(fobj)

        self.assertEqual(fobj.read.call_count, 1)
        mv_mock.assert_called_once_with(mock.sentinel.one, self.config.multi)
        self.assertEqual(result, {'mi': 23.5, 'rank': 'A'})
示例#4
0
    def __init__(self, config, targets):
        """
        Instantiate a new MI operator.

        :param config: The wily configuration.
        :type  config: :class:`WilyConfig`
        """
        # TODO : Import config from wily.cfg
        logger.debug(f"Using {targets} with {self.defaults} for MI metrics")

        self.harvester = harvesters.MIHarvester(targets, config=Config(**self.defaults))
示例#5
0
def test_mi_gobble(mi_config, mocker):
    mv_mock = mocker.patch('radon.cli.harvest.mi_visit')
    fobj = mocker.MagicMock()
    fobj.read.return_value = mocker.sentinel.one
    mv_mock.return_value = 23.5

    h = harvest.MIHarvester([], mi_config)
    result = h.gobble(fobj)

    assert fobj.read.call_count == 1
    mv_mock.assert_called_once_with(mocker.sentinel.one, mi_config.multi)
    assert result == {'mi': 23.5, 'rank': 'A'}
示例#6
0
def test_mi_as_json(mi_config, mocker):
    d_mock = mocker.patch('radon.cli.harvest.json.dumps')
    h = harvest.MIHarvester([], mi_config)
    h.config.min = 'C'
    h._results = [
        ('a', {'error': 'mystr'}),
        ('b', {'mi': 25, 'rank': 'A'}),
        ('c', {'mi': 15, 'rank': 'B'}),
        ('d', {'mi': 0, 'rank': 'C'}),
    ]

    h.as_json()
    d_mock.assert_called_with(dict([h._results[0], h._results[-1]]))
示例#7
0
    def test_as_json(self, d_mock):
        h = harvest.MIHarvester([], self.config)
        h.config.min = 'C'
        h._results = [
            ('a', {
                'error': 'mystr'
            }),
            ('b', {
                'mi': 25,
                'rank': 'A'
            }),
            ('c', {
                'mi': 15,
                'rank': 'B'
            }),
            ('d', {
                'mi': 0,
                'rank': 'C'
            }),
        ]

        h.as_json()
        d_mock.assert_called_with(dict([h._results[0], h._results[-1]]))
示例#8
0
def test_mi_as_xml(mi_config):
    h = harvest.MIHarvester([], mi_config)
    with pytest.raises(NotImplementedError):
        h.as_xml()
示例#9
0
 def test_as_xml(self):
     h = harvest.MIHarvester([], self.config)
     self.assertRaises(NotImplementedError, h.as_xml)