Skip to content

Commit

Permalink
misc: Add LineCountBear
Browse files Browse the repository at this point in the history
  • Loading branch information
sils committed Feb 5, 2015
1 parent 43264e9 commit 9331194
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
16 changes: 16 additions & 0 deletions bears/misc/LineCountBear.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from coalib.bears.LocalBear import LocalBear
from coalib.results.RESULT_SEVERITY import RESULT_SEVERITY
from coalib.results.Result import Result
from coalib.misc.i18n import _


class LineCountBear(LocalBear):
def run_bear(self, filename, file, *args):
"""
Counts the lines of each file.
"""
return [Result(
self.__class__.__name__,
_("This file has {count} lines.").format(count=len(file)),
RESULT_SEVERITY.INFO
)]
35 changes: 35 additions & 0 deletions bears/tests/misc/LineCountBearTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from queue import Queue
import sys

sys.path.insert(0, ".")
import unittest
from coalib.settings.Section import Section
from coalib.results.Result import Result, RESULT_SEVERITY
from bears.tests.LocalBearTestHelper import LocalBearTestHelper
from bears.misc.LineCountBear import LineCountBear, _


class SpaceConsistencyBearTest(LocalBearTestHelper):
def setUp(self):
self.uut = LineCountBear(Section("name"), Queue())

def test_run(self):
self.assertLinesYieldResult(
self.uut,
["1", "2", "3"],
Result("LineCountBear",
_("This file has {count} lines.").format(count=3),
RESULT_SEVERITY.INFO
)
)
self.assertLinesYieldResult(
self.uut,
[],
Result("LineCountBear",
_("This file has {count} lines.").format(count=0),
RESULT_SEVERITY.INFO)
)


if __name__ == '__main__':
unittest.main(verbosity=2)

1 comment on commit 9331194

@fneu
Copy link
Contributor

@fneu fneu commented on 9331194 Feb 5, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack

Please sign in to comment.