Skip to content
This repository was archived by the owner on Aug 26, 2024. It is now read-only.

Commit 29a367d

Browse files
authored
Merge pull request #146 from DavidCEllis/quieten_warnings
Quieten warnings
2 parents e8717f1 + 569d13c commit 29a367d

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

fuzzywuzzy/process.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@
2828
from . import fuzz
2929
from . import utils
3030
import heapq
31-
import warnings
31+
import logging
3232

33-
warnings.simplefilter('always')
3433

3534
default_scorer = fuzz.WRatio
35+
36+
3637
default_processor = utils.full_process
3738

3839

@@ -101,7 +102,9 @@ def no_process(x):
101102
processed_query = processor(query)
102103

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

106109
# If the scorer performs full_ratio with force ascii don't run full_process twice
107110
if scorer in [fuzz.WRatio, fuzz.QRatio,

fuzzywuzzy/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def decorator(*args, **kwargs):
3232
return func(*args, **kwargs)
3333
return decorator
3434

35+
3536
bad_chars = str("").join([chr(i) for i in range(128, 256)]) # ascii dammit!
3637
if PY3:
3738
translation_table = dict((ord(c), None) for c in bad_chars)

test_fuzzywuzzy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ def test_simplematch(self):
511511

512512
class TestCodeFormat(unittest.TestCase):
513513
def test_pep8_conformance(self):
514-
pep8style = pycodestyle.StyleGuide(quiet=True)
514+
pep8style = pycodestyle.StyleGuide(quiet=False)
515515
pep8style.options.ignore = pep8style.options.ignore + tuple(['E501'])
516516
pep8style.input_dir('fuzzywuzzy')
517517
result = pep8style.check_files()

test_fuzzywuzzy_pytest.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1-
import warnings
21
from fuzzywuzzy import process
32

43

5-
def test_process_warning():
6-
"""Check that a string reduced to 0 by processor raises a warning"""
4+
def test_process_warning(capsys):
5+
"""Check that a string reduced to 0 by processor logs a warning to stderr"""
6+
77
query = ':::::::'
88
choices = [':::::::']
9-
with warnings.catch_warnings(record=True) as w:
10-
result = process.extractOne(query, choices)
11-
assert issubclass(w[-1].category, UserWarning)
12-
assert result == (query, 0)
9+
10+
_ = process.extractOne(query, choices)
11+
12+
out, err = capsys.readouterr()
13+
14+
outstr = ("WARNING:root:Applied processor reduces "
15+
"input query to empty string, "
16+
"all comparisons will have score 0. "
17+
"[Query: ':::::::']\n")
18+
19+
assert err == outstr

0 commit comments

Comments
 (0)