Skip to content

Commit

Permalink
Merge pull request #146 from DavidCEllis/quieten_warnings
Browse files Browse the repository at this point in the history
Quieten warnings
  • Loading branch information
josegonzalez committed Nov 4, 2016
2 parents e8717f1 + 569d13c commit 29a367d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
9 changes: 6 additions & 3 deletions fuzzywuzzy/process.py
Expand Up @@ -28,11 +28,12 @@
from . import fuzz
from . import utils
import heapq
import warnings
import logging

warnings.simplefilter('always')

default_scorer = fuzz.WRatio


default_processor = utils.full_process


Expand Down Expand Up @@ -101,7 +102,9 @@ def no_process(x):
processed_query = processor(query)

if len(processed_query) == 0:
warnings.warn("Applied processor reduces input query to empty string, all comparisons will have score 0.")
logging.warning("Applied processor reduces input query to empty string, "
"all comparisons will have score 0. "
"[Query: \'{0}\']".format(query))

# If the scorer performs full_ratio with force ascii don't run full_process twice
if scorer in [fuzz.WRatio, fuzz.QRatio,
Expand Down
1 change: 1 addition & 0 deletions fuzzywuzzy/utils.py
Expand Up @@ -32,6 +32,7 @@ def decorator(*args, **kwargs):
return func(*args, **kwargs)
return decorator


bad_chars = str("").join([chr(i) for i in range(128, 256)]) # ascii dammit!
if PY3:
translation_table = dict((ord(c), None) for c in bad_chars)
Expand Down
2 changes: 1 addition & 1 deletion test_fuzzywuzzy.py
Expand Up @@ -511,7 +511,7 @@ def test_simplematch(self):

class TestCodeFormat(unittest.TestCase):
def test_pep8_conformance(self):
pep8style = pycodestyle.StyleGuide(quiet=True)
pep8style = pycodestyle.StyleGuide(quiet=False)
pep8style.options.ignore = pep8style.options.ignore + tuple(['E501'])
pep8style.input_dir('fuzzywuzzy')
result = pep8style.check_files()
Expand Down
21 changes: 14 additions & 7 deletions test_fuzzywuzzy_pytest.py
@@ -1,12 +1,19 @@
import warnings
from fuzzywuzzy import process


def test_process_warning():
"""Check that a string reduced to 0 by processor raises a warning"""
def test_process_warning(capsys):
"""Check that a string reduced to 0 by processor logs a warning to stderr"""

query = ':::::::'
choices = [':::::::']
with warnings.catch_warnings(record=True) as w:
result = process.extractOne(query, choices)
assert issubclass(w[-1].category, UserWarning)
assert result == (query, 0)

_ = process.extractOne(query, choices)

out, err = capsys.readouterr()

outstr = ("WARNING:root:Applied processor reduces "
"input query to empty string, "
"all comparisons will have score 0. "
"[Query: ':::::::']\n")

assert err == outstr

0 comments on commit 29a367d

Please sign in to comment.