Skip to content

Commit

Permalink
feat(raw): add comment stats to raw summary
Browse files Browse the repository at this point in the history
Fixes #110
  • Loading branch information
rubik committed May 30, 2017
1 parent 2568444 commit 38b9794
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
20 changes: 20 additions & 0 deletions radon/cli/harvest.py
Expand Up @@ -211,10 +211,30 @@ def to_terminal(self):
{'indent': 2})

if self.config.summary:
_get = lambda k, v=0: sum_metrics.get(k, v)
comments = float(_get('Comments'))
yield '** Total **', (), {}
for header in self.headers:
yield '{0}: {1}', (header, sum_metrics[header]), {'indent': 1}

yield '- Comment Stats', (), {'indent': 1}
yield (
'(C % L): {0:.0%}',
(comments / (_get('LOC', 1) or 1),),
{'indent': 2},
)
yield (
'(C % S): {0:.0%}',
(comments / (_get('SLOC', 1) or 1),),
{'indent': 2},
)
yield (
'(C + M % L): {0:.0%}',
(float(_get('Comments', 0) + _get('Multi')) /
(_get('LOC', 1) or 1),),
{'indent': 2},
)


class MIHarvester(Harvester):
'''A class that analyzes Python modules' Maintainability Index.'''
Expand Down
2 changes: 1 addition & 1 deletion radon/tests/run.py
@@ -1,3 +1,3 @@
if __name__ == '__main__':
import pytest
pytest.main(['-v'])
pytest.main(['--strict'])
4 changes: 4 additions & 0 deletions radon/tests/test_cli_harvest.py
Expand Up @@ -274,6 +274,10 @@ def test_raw_to_terminal(raw_config):
('{0}: {1}', ('Single comments', 28), {'indent': 1}),
('{0}: {1}', ('Multi', 6), {'indent': 1}),
('{0}: {1}', ('Blank', 18), {'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}),
]


Expand Down

0 comments on commit 38b9794

Please sign in to comment.