예제 #1
0
def test_raw_to_terminal(raw_config):
    h = harvest.RawHarvester([], raw_config)
    h._results = [
        ('a', {'error': 'mystr'}),
        ('b', {'loc': 24, 'lloc': 27, 'sloc': 15, 'comments': 3,
               'multi': 3, 'single_comments': 3, 'blank': 9}),
        ('c', {'loc': 24, 'lloc': 27, 'sloc': 15, 'comments': 3,
               'multi': 3, 'single_comments': 13, 'blank': 9}),
        ('e', {'loc': 0, 'lloc': 0, 'sloc': 0, 'comments': 0,
               'single_comments': 12, 'multi': 0, 'blank': 0}),
    ]

    assert list(h.to_terminal()) == [
        ('a', ('mystr',), {'error': True}),
        ('b', (), {}),
        ('{0}: {1}', ('LOC', 24), {'indent': 1}),
        ('{0}: {1}', ('LLOC', 27), {'indent': 1}),
        ('{0}: {1}', ('SLOC', 15), {'indent': 1}),
        ('{0}: {1}', ('Comments', 3), {'indent': 1}),
        ('{0}: {1}', ('Single comments', 3), {'indent': 1}),
        ('{0}: {1}', ('Multi', 3), {'indent': 1}),
        ('{0}: {1}', ('Blank', 9), {'indent': 1}),
        ('- Comment Stats', (), {'indent': 1}),
        ('(C % L): {0:.0%}', (0.125,), {'indent': 2}),
        ('(C % S): {0:.0%}', (0.2,), {'indent': 2}),
        ('(C + M % L): {0:.0%}', (0.25,), {'indent': 2}),
        ('c', (), {}),
        ('{0}: {1}', ('LOC', 24), {'indent': 1}),
        ('{0}: {1}', ('LLOC', 27), {'indent': 1}),
        ('{0}: {1}', ('SLOC', 15), {'indent': 1}),
        ('{0}: {1}', ('Comments', 3), {'indent': 1}),
        ('{0}: {1}', ('Single comments', 13), {'indent': 1}),
        ('{0}: {1}', ('Multi', 3), {'indent': 1}),
        ('{0}: {1}', ('Blank', 9), {'indent': 1}),
        ('- Comment Stats', (), {'indent': 1}),
        ('(C % L): {0:.0%}', (0.125,), {'indent': 2}),
        ('(C % S): {0:.0%}', (0.2,), {'indent': 2}),
        ('(C + M % L): {0:.0%}', (0.25,), {'indent': 2}),
        ('e', (), {}),
        ('{0}: {1}', ('LOC', 0), {'indent': 1}),
        ('{0}: {1}', ('LLOC', 0), {'indent': 1}),
        ('{0}: {1}', ('SLOC', 0), {'indent': 1}),
        ('{0}: {1}', ('Comments', 0), {'indent': 1}),
        ('{0}: {1}', ('Single comments', 12), {'indent': 1}),
        ('{0}: {1}', ('Multi', 0), {'indent': 1}),
        ('{0}: {1}', ('Blank', 0), {'indent': 1}),
        ('- Comment Stats', (), {'indent': 1}),
        ('(C % L): {0:.0%}', (0.0,), {'indent': 2}),
        ('(C % S): {0:.0%}', (0.0,), {'indent': 2}),
        ('(C + M % L): {0:.0%}', (0.0,), {'indent': 2}),
        ('** Total **', (), {}),
        ('{0}: {1}', ('LOC', 48), {'indent': 1}),
        ('{0}: {1}', ('LLOC', 54), {'indent': 1}),
        ('{0}: {1}', ('SLOC', 30), {'indent': 1}),
        ('{0}: {1}', ('Comments', 6), {'indent': 1}),
        ('{0}: {1}', ('Single comments', 28), {'indent': 1}),
        ('{0}: {1}', ('Multi', 6), {'indent': 1}),
        ('{0}: {1}', ('Blank', 18), {'indent': 1}),
    ]
예제 #2
0
    def test_gobble(self, analyze_mock, r2d_mock):
        fobj = mock.MagicMock()
        fobj.read.return_value = mock.sentinel.one
        analyze_mock.return_value = mock.sentinel.two

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

        self.assertEqual(fobj.read.call_count, 1)
        analyze_mock.assert_called_once_with(mock.sentinel.one)
        r2d_mock.assert_called_once_with(mock.sentinel.two)
예제 #3
0
파일: raw.py 프로젝트: uasau/wily
    def __init__(self, config, targets):
        """
        Instantiate a new raw operator.

        :param config: The wily configuration.
        :type  config: :class:`WilyConfig`
        """
        # TODO: Use config from wily.cfg for harvester
        logger.debug(f"Using {targets} with {self.defaults} for Raw metrics")
        self.harvester = harvesters.RawHarvester(
            targets, config=Config(**self.defaults))
예제 #4
0
def test_raw_gobble(raw_config, mocker):
    r2d_mock = mocker.patch('radon.cli.harvest.raw_to_dict')
    analyze_mock = mocker.patch('radon.cli.harvest.analyze')
    fobj = mocker.MagicMock()
    fobj.read.return_value = mocker.sentinel.one
    analyze_mock.return_value = mocker.sentinel.two

    h = harvest.RawHarvester([], raw_config)
    h.gobble(fobj)

    assert fobj.read.call_count == 1
    analyze_mock.assert_called_once_with(mocker.sentinel.one)
    r2d_mock.assert_called_once_with(mocker.sentinel.two)
예제 #5
0
def test_raw_as_xml(raw_config):
    h = harvest.RawHarvester([], raw_config)
    with pytest.raises(NotImplementedError):
        h.as_xml()
예제 #6
0
 def test_as_xml(self):
     h = harvest.RawHarvester([], self.config)
     self.assertRaises(NotImplementedError, h.as_xml)