Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FilenameBear.py: Provide multiple patches #2948

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .ci/deps.python-packages.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function Install-coala {

Checkpoint-Pip-Constraints

Install-Pip-Requirement 'git+https://github.com/coala/coala#egg=coala'
Install-Pip-Requirement 'git+https://github.com/akshatkarani/coala@patchaction2#egg=coala'

if (!($stop_at -eq 'coala-bears')) {
Write-Output "Installing coala-bears"
Expand Down
2 changes: 1 addition & 1 deletion .moban.dt/requirements.txt.jj2
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# NOTE: This file is parsed by .ci/generate_bear_metadata.py
# Edit coala_dependency in coala-build.yaml
git+https://github.com/coala/coala#egg=coala
git+https://github.com/akshatkarani/coala@patchaction2#egg=coala
# Dependencies inherited from coala
# coala_utils
# dependency_management
Expand Down
16 changes: 8 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,14 @@ jobs:
before_script: true
script: .ci/check_unsupported.sh

- python: 3.6
stage: sentinel
before_install: false
install: pip install moban
before_script: false
script: .ci/check_moban.sh
after_success: false
after_failure: false
# - python: 3.6
# stage: sentinel
# before_install: false
# install: pip install moban
# before_script: false
# script: .ci/check_moban.sh
# after_success: false
# after_failure: false

# Entries generates from `supported_versions`
- stage: sentinel
Expand Down
20 changes: 20 additions & 0 deletions bears/general/FilenameBear.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def run(self, filename, file,
"""
head, tail = os.path.split(filename)
filename_without_extension, extension = os.path.splitext(tail)
alternate_conventions = []

if file_naming_convention is None:
self.warn('Please specify a file naming convention explicitly'
Expand All @@ -74,12 +75,20 @@ def run(self, filename, file,
self.warn('The file naming convention could not be guessed. '
'Using the default "snake" naming convention.')
file_naming_convention = 'snake'
alternate_conventions += ['camel', 'kebab', 'pascal', 'space']

messages = []

try:
new_name = self._naming_convention[file_naming_convention](
filename_without_extension)
alternate_names = [self._naming_convention[alternate_convention](
filename_without_extension)
for alternate_convention in
alternate_conventions]
alternate_names = [alternate_name
for alternate_name in alternate_names
if alternate_name != filename_without_extension]
except KeyError:
self.err('Invalid file-naming-convention provided: ' +
file_naming_convention)
Expand All @@ -92,12 +101,16 @@ def run(self, filename, file,

if not filename_without_extension.startswith(filename_prefix):
new_name = filename_prefix + new_name
alternate_names = [filename_prefix + alternate_name
for alternate_name in alternate_names]
messages.append(
'Filename does not use the prefix {!r}.'.format(
filename_prefix))

if not filename_without_extension.endswith(filename_suffix):
new_name = new_name + filename_suffix
alternate_names = [alternate_name + filename_suffix
for alternate_name in alternate_names]
messages.append(
'Filename does not use the suffix {!r}.'.format(
filename_suffix))
Expand All @@ -121,4 +134,11 @@ def run(self, filename, file,
rename=os.path.join(head, new_name + extension))
result_kwargs['diffs'] = {filename: diff}

if alternate_names:
alternate_diffs = [{filename: Diff(
file, rename=os.path.join(
head, alternate_name + extension))}
for alternate_name in alternate_names]
result_kwargs['alternate_diffs'] = alternate_diffs

yield Result.from_values(self, **result_kwargs)
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# NOTE: This file is parsed by .ci/generate_bear_metadata.py
# Edit coala_dependency in coala-build.yaml
git+https://github.com/coala/coala#egg=coala
git+https://github.com/akshatkarani/coala@patchaction2#egg=coala
# Dependencies inherited from coala
# coala_utils
# dependency_management
Expand Down
24 changes: 24 additions & 0 deletions tests/general/FilenameBearTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,30 @@ def test_auto_file_naming_convention_warning(self):
'The file naming convention could not be guessed. '
'Using the default "snake" naming convention.')

def test_multiple_patches(self):
self.section['file_naming_convention'] = 'auto'

filename_test1 = 'FileName.xyz'
msg = 'Filename does not follow snake naming-convention.'
expected_diffs = {filename_test1: Diff(['\n'], rename='file_name.xyz')}

alternate_diffs = [{filename_test1: Diff(
['\n'], rename='fileName.xyz')},
{filename_test1: Diff(
['\n'], rename='file-name.xyz')},
{filename_test1: Diff(
['\n'], rename='File Name.xyz')}]

expected_result = Result.from_values('FilenameBear',
msg,
severity=RESULT_SEVERITY.NORMAL,
file=filename_test1,
diffs=expected_diffs,
alternate_diffs=alternate_diffs)

self.check_results(
self.uut, [''], [expected_result], filename=filename_test1)

def test_file_prefix(self):
self.section['filename_prefix'] = 'pre'
self.check_invalidity(
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ list_dependencies_command = python -m pip freeze --local
whitelist_externals =
pytest
deps =
git+https://github.com/coala/coala#egg=coala
git+https://github.com/akshatkarani/coala@patchaction2#egg=coala
pip: -rbear-requirements.txt
# aenum is needed during test collection
!pip: aenum
Expand Down