Skip to content

Commit

Permalink
FilenameBearTest: Fix testcases
Browse files Browse the repository at this point in the history
Match several testcases in `FilenameBearTest` with the actual
result, especially for the expected `Result` objects that
its `diffs` argument was forgotten.

Closes coala#2564
  • Loading branch information
refeed committed Jul 5, 2018
1 parent 300d81d commit 570b7da
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions tests/general/FilenameBearTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from bears.general.FilenameBear import FilenameBear
from coalib.testing.LocalBearTestHelper import LocalBearTestHelper
from coalib.results.Diff import Diff
from coalib.results.Result import RESULT_SEVERITY, Result
from coalib.output.printers.LOG_LEVEL import LOG_LEVEL
from coalib.settings.Section import Section
Expand Down Expand Up @@ -115,13 +116,16 @@ def test_file_prefix(self):
self.uut, [''], filename='filename.xyz')
self.check_validity(
self.uut, [''], filename='prefilename.xyz')

expected_diff = Diff(['\n'], rename='prefilename.xyz')
self.check_results(
self.uut,
[''],
[Result.from_values('FilenameBear',
"Filename does not use the prefix 'pre'.",
severity=RESULT_SEVERITY.NORMAL,
file='filename.xyz')],
file='filename.xyz',
diffs={'filename.xyz': expected_diff})],
filename='filename.xyz')

def test_file_suffix(self):
Expand All @@ -130,26 +134,32 @@ def test_file_suffix(self):
self.uut, [''], filename='filename.xyz')
self.check_validity(
self.uut, [''], filename='filenamesuffix.xyz')

expected_diff = Diff(['\n'], rename='filenamefix.xyz')
self.check_results(
self.uut,
[''],
[Result.from_values('FilenameBear',
"Filename does not use the suffix 'fix'.",
severity=RESULT_SEVERITY.NORMAL,
file='filename.xyz')],
file='filename.xyz',
diffs={'filename.xyz': expected_diff})],
filename='filename.xyz')

def test_file_prefix_suffix(self):
self.section['filename_prefix'] = 'pre'
self.section['filename_suffix'] = 'fix'

expected_diff = Diff(['\n'], rename='prefilenamefix.xyz')
self.check_results(
self.uut,
[''],
[Result.from_values('FilenameBear',
"- Filename does not use the prefix 'pre'.\n"
"- Filename does not use the suffix 'fix'.",
severity=RESULT_SEVERITY.NORMAL,
file='filename.xyz')],
file='filename.xyz',
diffs={'filename.xyz': expected_diff})],
filename='filename.xyz')

def test_file_with_too_long_filename(self):
Expand Down Expand Up @@ -181,12 +191,15 @@ def test_message_too_long_file_with_other_errors(self):
msg = ("- Filename does not use the prefix 'pre'.\n"
'- Filename is too long ({} > {}).'
)

expected_diff = Diff(['\n'], rename=('pre' + filename_test1))
self.check_results(
self.uut,
[''],
[Result.from_values('FilenameBear',
msg.format(len(filename_test1),
max_filename_length),
severity=RESULT_SEVERITY.NORMAL,
file=filename_test1)],
file=filename_test1,
diffs={filename_test1: expected_diff})],
filename=filename_test1)

0 comments on commit 570b7da

Please sign in to comment.