Skip to content

Commit 1113403

Browse files
committed
Run flake when running tests
Also fix a typo in an error message
1 parent ef26d64 commit 1113403

12 files changed

+43
-16
lines changed

dev-requirements.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
nose>=1.3.0
22
tox>=2.6.0
3-
wheel
4-
twine
53
invoke>=0.15.0
64
mock
5+
flake8==3.5.0

run_tests.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@
1212
python run_tests.py no-internet
1313
'''
1414
from __future__ import unicode_literals
15-
import nose
15+
import subprocess
1616
import sys
17+
18+
import nose
19+
1720
from textblob.compat import PY2
1821

1922
PY26 = PY2 and int(sys.version_info[1]) < 7
@@ -22,6 +25,9 @@
2225

2326
def main():
2427
args = get_argv()
28+
retcode = subprocess.call(['flake8', 'textblob'])
29+
if retcode:
30+
sys.exit(1)
2531
success = nose.run(argv=args)
2632
sys.exit(0) if success else sys.exit(1)
2733

@@ -59,5 +65,6 @@ def get_argv():
5965
args.extend(["-A", attr_expression])
6066
return args
6167

68+
6269
if __name__ == '__main__':
6370
main()

setup.cfg

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,19 @@
22
universal = 1
33

44
[flake8]
5-
ignore = E501,E127,E128,E265,E302
5+
ignore = E501,E127,E128,E265,E302,E266
66
max-line-length = 90
7+
exclude =
8+
.git,
9+
.ropeproject,
10+
.tox,
11+
docs,
12+
.git,
13+
build,
14+
env,
15+
venv,
16+
# Exclude vendorized code
17+
textblob/en,
18+
textblob/unicodecsv,
19+
textblob/_text.py,
20+
textblob/compat.py

textblob/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def itokenize(self, text, *args, **kwargs):
6565

6666
##### SENTIMENT ANALYZERS ####
6767

68+
6869
DISCRETE = 'ds'
6970
CONTINUOUS = 'co'
7071

textblob/blob.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ def sentiment_assessments(self):
433433
:rtype: namedtuple of the form ``Sentiment(polarity, subjectivity,
434434
assessments)``
435435
"""
436-
return self.analyzer.analyze(self.raw,keep_assessments=True)
436+
return self.analyzer.analyze(self.raw, keep_assessments=True)
437437

438438
@cached_property
439439
def polarity(self):

textblob/classifiers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ def basic_extractor(document, train_set):
8989
try:
9090
assert(isinstance(el_zero[0], basestring))
9191
word_features = _get_words_from_dataset(chain([el_zero], train_set))
92-
except:
93-
raise ValueError('train_set is proabably malformed.')
92+
except Exception:
93+
raise ValueError('train_set is probably malformed.')
9494

9595
tokens = _get_document_tokens(document)
9696
features = dict(((u'contains({0})'.format(word), (word in tokens))
@@ -136,7 +136,7 @@ def __init__(self, train_set, feature_extractor=basic_extractor, format=None, **
136136
self.train_set = self._read_data(train_set, format)
137137
else: # train_set is a list of tuples
138138
self.train_set = train_set
139-
self._word_set = _get_words_from_dataset(self.train_set) #Keep a hidden set of unique words.
139+
self._word_set = _get_words_from_dataset(self.train_set) # Keep a hidden set of unique words.
140140
self.train_features = None
141141

142142
def _read_data(self, dataset, format=None):

textblob/download_corpora.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,6 @@ def main():
4646
download_all()
4747
print("Finished.")
4848

49+
4950
if __name__ == '__main__':
5051
main()

textblob/en/sentiments.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,25 @@ class PatternAnalyzer(BaseSentimentAnalyzer):
2323
where [assessments] is a list of the assessed tokens and their
2424
polarity and subjectivity scores
2525
"""
26-
2726
kind = CONTINUOUS
27+
# This is only here for backwards-compatibility.
28+
# The return type is actually determined upon calling analyze()
29+
RETURN_TYPE = namedtuple('Sentiment', ['polarity', 'subjectivity'])
2830

2931
def analyze(self, text, keep_assessments=False):
3032
"""Return the sentiment as a named tuple of the form:
3133
``Sentiment(polarity, subjectivity, [assessments])``.
3234
"""
3335
#: Return type declaration
3436
if keep_assessments:
35-
RETURN_TYPE = namedtuple('Sentiment', ['polarity', 'subjectivity', 'assessments'])
37+
Sentiment = namedtuple('Sentiment', ['polarity', 'subjectivity', 'assessments'])
3638
assessments = pattern_sentiment(text).assessments
37-
polarity,subjectivity = pattern_sentiment(text)
38-
return RETURN_TYPE( polarity,subjectivity,assessments )
39+
polarity, subjectivity = pattern_sentiment(text)
40+
return Sentiment(polarity, subjectivity, assessments)
3941

4042
else:
41-
RETURN_TYPE = namedtuple('Sentiment', ['polarity', 'subjectivity'])
42-
return RETURN_TYPE(*pattern_sentiment(text))
43+
Sentiment = namedtuple('Sentiment', ['polarity', 'subjectivity'])
44+
return Sentiment(*pattern_sentiment(text))
4345

4446

4547
def _default_feature_extractor(words):

textblob/exceptions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class TextBlobError(Exception):
1515
"""A TextBlob-related error."""
1616
pass
1717

18+
1819
TextBlobException = TextBlobError # Backwards compat
1920

2021
class MissingCorpusError(TextBlobError):
@@ -25,6 +26,7 @@ class MissingCorpusError(TextBlobError):
2526
def __init__(self, message=MISSING_CORPUS_MESSAGE, *args, **kwargs):
2627
super(MissingCorpusError, self).__init__(message, *args, **kwargs)
2728

29+
2830
MissingCorpusException = MissingCorpusError # Backwards compat
2931

3032
class DeprecationError(TextBlobError):

textblob/formats.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ def detect(cls, stream):
127127
except ValueError:
128128
return False
129129

130+
130131
_registry = OrderedDict([
131132
('csv', CSV),
132133
('json', JSON),

textblob/tokenizers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def tokenize(self, text):
5656
'''Return a list of sentences.'''
5757
return nltk.tokenize.sent_tokenize(text)
5858

59+
5960
#: Convenience function for tokenizing sentences
6061
sent_tokenize = SentenceTokenizer().itokenize
6162

textblob/translate.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ def _unescape(text):
9898
"""Unescape unicode character codes within a string.
9999
"""
100100
pattern = r'\\{1,2}u[0-9a-fA-F]{4}'
101-
decode = lambda x: codecs.getdecoder('unicode_escape')(x.group())[0]
102-
return re.sub(pattern, decode, text)
101+
return re.sub(pattern, lambda x: codecs.getdecoder('unicode_escape')(x.group())[0], text)
103102

104103

105104
def _calculate_tk(source):

0 commit comments

Comments
 (0)