Skip to content

Commit a1ff3fb

Browse files
committed
Upgrade from pycodestyle to flake8
1 parent be47e90 commit a1ff3fb

16 files changed

+93
-87
lines changed

.travis.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ branches:
44
- dev
55

66
language: python
7-
dist: xenial
87

98
before_install:
109
- sudo apt-get update -qq
@@ -16,6 +15,10 @@ python:
1615
- "3.5"
1716
- "3.6"
1817
- "3.7"
18+
- "3.8"
19+
jobs:
20+
allow_failures:
21+
- python: "3.8"
1922
# don't rebuild pocketsphinx for every build
2023
cache:
2124
- pip
@@ -31,6 +34,7 @@ install:
3134
# command to run tests
3235
script:
3336
- pycodestyle mycroft test
37+
- flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
3438
- ./start-mycroft.sh unittest
3539

3640
after_success:

mycroft/client/speech/hotword_factory.py

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from contextlib import suppress
2222
from glob import glob
2323
from os.path import dirname, exists, join, abspath, expanduser, isfile, isdir
24+
from shutil import rmtree
2425
from threading import Timer, Event, Thread
2526
from urllib.error import HTTPError
2627

mycroft/tts/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ def create():
513513
if tts_module != 'mimic':
514514
LOG.exception('The selected TTS backend couldn\'t be loaded. '
515515
'Falling back to Mimic')
516+
from mycroft.tts.mimic_tts import Mimic
516517
tts = Mimic(tts_lang, tts_config)
517518
tts.validator.validate()
518519
else:

mycroft/util/lang/parse_nl.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1429,9 +1429,9 @@ def isFractional_nl(input_str, short_scale=True):
14291429
if num > 2:
14301430
fracts[_SHORT_ORDINAL_STRING_NL[num]] = num
14311431
else:
1432-
for num in _LONG_ORDINAL_STRING_EN:
1432+
for num in _LONG_ORDINAL_STRING_NL:
14331433
if num > 2:
1434-
fracts[_LONG_ORDINAL_STRING_EN[num]] = num
1434+
fracts[_LONG_ORDINAL_STRING_NL[num]] = num
14351435

14361436
if input_str.lower() in fracts:
14371437
return 1.0 / fracts[input_str.lower()]

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
six==1.10.0
1+
six==1.13.0
22
cryptography==2.6.1
33
requests==2.20.0
44
gTTS==2.0.4

test-requirements.txt

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
pycodestyle===2.5.0
2-
coveralls==1.5.0
3-
pytest==3.5.0
4-
pytest-cov==2.5.1
1+
coveralls==1.8.2
2+
flake8==3.7.9
3+
pytest==5.2.4
4+
pytest-cov==2.8.1
55
cov-core==1.15.0
6-
sphinx==1.8.2
7-
sphinx-rtd-theme==0.4.2
6+
sphinx==2.2.1
7+
sphinx-rtd-theme==0.4.3

test/unittests/api/test_api.py

+34-34
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ def setUp(self):
6666
def test_init(self, mock_identity_get):
6767
mock_identity_get.return_value = create_identity('1234')
6868
a = mycroft.api.Api('test-path')
69-
self.assertEquals(a.url, 'https://api-test.mycroft.ai')
70-
self.assertEquals(a.version, 'v1')
71-
self.assertEquals(a.identity.uuid, '1234')
69+
self.assertEqual(a.url, 'https://api-test.mycroft.ai')
70+
self.assertEqual(a.version, 'v1')
71+
self.assertEqual(a.identity.uuid, '1234')
7272

7373
@patch('mycroft.api.IdentityManager')
7474
@patch('mycroft.api.requests.request')
@@ -84,7 +84,7 @@ def test_send(self, mock_request, mock_identity_manager):
8484
req = {'path': 'something', 'headers': {}}
8585

8686
# Check successful
87-
self.assertEquals(a.send(req), mock_response_ok.json())
87+
self.assertEqual(a.send(req), mock_response_ok.json())
8888

8989
# check that a 300+ status code generates Exception
9090
mock_request.return_value = mock_response_301
@@ -121,8 +121,8 @@ def test_init(self, mock_request, mock_identity_get):
121121
mock_identity_get.return_value = create_identity('1234')
122122

123123
device = mycroft.api.DeviceApi()
124-
self.assertEquals(device.identity.uuid, '1234')
125-
self.assertEquals(device.path, 'device')
124+
self.assertEqual(device.identity.uuid, '1234')
125+
self.assertEqual(device.path, 'device')
126126

127127
@patch('mycroft.api.IdentityManager.get')
128128
@patch('mycroft.api.requests.request')
@@ -133,8 +133,8 @@ def test_device_activate(self, mock_request, mock_identity_get):
133133
device = mycroft.api.DeviceApi()
134134
device.activate('state', 'token')
135135
json = mock_request.call_args[1]['json']
136-
self.assertEquals(json['state'], 'state')
137-
self.assertEquals(json['token'], 'token')
136+
self.assertEqual(json['state'], 'state')
137+
self.assertEqual(json['token'], 'token')
138138

139139
@patch('mycroft.api.IdentityManager.get')
140140
@patch('mycroft.api.requests.request')
@@ -145,7 +145,7 @@ def test_device_get(self, mock_request, mock_identity_get):
145145
device = mycroft.api.DeviceApi()
146146
device.get()
147147
url = mock_request.call_args[0][1]
148-
self.assertEquals(url, 'https://api-test.mycroft.ai/v1/device/1234')
148+
self.assertEqual(url, 'https://api-test.mycroft.ai/v1/device/1234')
149149

150150
@patch('mycroft.api.IdentityManager.update')
151151
@patch('mycroft.api.IdentityManager.get')
@@ -156,9 +156,9 @@ def test_device_get_code(self, mock_request, mock_identity_get,
156156
mock_identity_get.return_value = create_identity('1234')
157157
device = mycroft.api.DeviceApi()
158158
ret = device.get_code('state')
159-
self.assertEquals(ret, '123ABC')
159+
self.assertEqual(ret, '123ABC')
160160
url = mock_request.call_args[0][1]
161-
self.assertEquals(
161+
self.assertEqual(
162162
url, 'https://api-test.mycroft.ai/v1/device/code?state=state')
163163

164164
@patch('mycroft.api.IdentityManager.get')
@@ -169,7 +169,7 @@ def test_device_get_settings(self, mock_request, mock_identity_get):
169169
device = mycroft.api.DeviceApi()
170170
device.get_settings()
171171
url = mock_request.call_args[0][1]
172-
self.assertEquals(
172+
self.assertEqual(
173173
url, 'https://api-test.mycroft.ai/v1/device/1234/setting')
174174

175175
@patch('mycroft.api.IdentityManager.get')
@@ -184,9 +184,9 @@ def test_device_report_metric(self, mock_request, mock_identity_get):
184184

185185
content_type = params['headers']['Content-Type']
186186
correct_json = {'data': 'mydata'}
187-
self.assertEquals(content_type, 'application/json')
188-
self.assertEquals(params['json'], correct_json)
189-
self.assertEquals(
187+
self.assertEqual(content_type, 'application/json')
188+
self.assertEqual(params['json'], correct_json)
189+
self.assertEqual(
190190
url, 'https://api-test.mycroft.ai/v1/device/1234/metric/mymetric')
191191

192192
@patch('mycroft.api.IdentityManager.get')
@@ -201,9 +201,9 @@ def test_device_send_email(self, mock_request, mock_identity_get):
201201

202202
content_type = params['headers']['Content-Type']
203203
correct_json = {'body': 'body', 'sender': 'sender', 'title': 'title'}
204-
self.assertEquals(content_type, 'application/json')
205-
self.assertEquals(params['json'], correct_json)
206-
self.assertEquals(
204+
self.assertEqual(content_type, 'application/json')
205+
self.assertEqual(params['json'], correct_json)
206+
self.assertEqual(
207207
url, 'https://api-test.mycroft.ai/v1/device/1234/message')
208208

209209
@patch('mycroft.api.IdentityManager.get')
@@ -215,7 +215,7 @@ def test_device_get_oauth_token(self, mock_request, mock_identity_get):
215215
device.get_oauth_token(1)
216216
url = mock_request.call_args[0][1]
217217

218-
self.assertEquals(
218+
self.assertEqual(
219219
url, 'https://api-test.mycroft.ai/v1/device/1234/token/1')
220220

221221
@patch('mycroft.api.IdentityManager.get')
@@ -226,7 +226,7 @@ def test_device_get_location(self, mock_request, mock_identity_get):
226226
device = mycroft.api.DeviceApi()
227227
device.get_location()
228228
url = mock_request.call_args[0][1]
229-
self.assertEquals(
229+
self.assertEqual(
230230
url, 'https://api-test.mycroft.ai/v1/device/1234/location')
231231

232232
@patch('mycroft.api.IdentityManager.get')
@@ -237,7 +237,7 @@ def test_device_get_subscription(self, mock_request, mock_identity_get):
237237
device = mycroft.api.DeviceApi()
238238
device.get_subscription()
239239
url = mock_request.call_args[0][1]
240-
self.assertEquals(
240+
self.assertEqual(
241241
url, 'https://api-test.mycroft.ai/v1/device/1234/subscription')
242242

243243
mock_request.return_value = create_response(200, {'@type': 'free'})
@@ -260,7 +260,7 @@ def test_device_upload_skills_data(self, mock_request, mock_identity_get):
260260
data = mock_request.call_args[1]['json']
261261

262262
# Check that the correct url is called
263-
self.assertEquals(
263+
self.assertEqual(
264264
url, 'https://api-test.mycroft.ai/v1/device/1234/skillJson')
265265

266266
# Check that the correct data is sent as json
@@ -276,7 +276,7 @@ def test_stt(self, mock_request, mock_identity_get):
276276
mock_request.return_value = create_response(200, {})
277277
mock_identity_get.return_value = create_identity('1234')
278278
stt = mycroft.api.STTApi('stt')
279-
self.assertEquals(stt.path, 'stt')
279+
self.assertEqual(stt.path, 'stt')
280280

281281
@patch('mycroft.api.IdentityManager.get')
282282
@patch('mycroft.api.requests.request')
@@ -286,11 +286,11 @@ def test_stt_stt(self, mock_request, mock_identity_get):
286286
stt = mycroft.api.STTApi('stt')
287287
stt.stt('La la la', 'en-US', 1)
288288
url = mock_request.call_args[0][1]
289-
self.assertEquals(url, 'https://api-test.mycroft.ai/v1/stt')
289+
self.assertEqual(url, 'https://api-test.mycroft.ai/v1/stt')
290290
data = mock_request.call_args[1].get('data')
291-
self.assertEquals(data, 'La la la')
291+
self.assertEqual(data, 'La la la')
292292
params = mock_request.call_args[1].get('params')
293-
self.assertEquals(params['lang'], 'en-US')
293+
self.assertEqual(params['lang'], 'en-US')
294294

295295
@patch('mycroft.api.IdentityManager.load')
296296
def test_has_been_paired(self, mock_identity_load):
@@ -347,10 +347,10 @@ def test_upload_meta(self, mock_request, mock_identity_get):
347347
params = mock_request.call_args[1]
348348

349349
content_type = params['headers']['Content-Type']
350-
self.assertEquals(content_type, 'application/json')
351-
self.assertEquals(method, 'PUT')
352-
self.assertEquals(params['json'], settings_meta)
353-
self.assertEquals(
350+
self.assertEqual(content_type, 'application/json')
351+
self.assertEqual(method, 'PUT')
352+
self.assertEqual(params['json'], settings_meta)
353+
self.assertEqual(
354354
url, 'https://api-test.mycroft.ai/v1/device/1234/settingsMeta')
355355

356356
def test_get_skill_settings(self, mock_request, mock_identity_get):
@@ -362,8 +362,8 @@ def test_get_skill_settings(self, mock_request, mock_identity_get):
362362
url = mock_request.call_args[0][1]
363363
params = mock_request.call_args[1]
364364

365-
self.assertEquals(method, 'GET')
366-
self.assertEquals(
365+
self.assertEqual(method, 'GET')
366+
self.assertEqual(
367367
url, 'https://api-test.mycroft.ai/v1/device/1234/skill/settings')
368368

369369

@@ -389,9 +389,9 @@ def test_is_paired_true(self, mock_request, mock_identity_get):
389389

390390
self.assertTrue(mycroft.api.is_paired())
391391

392-
self.assertEquals(num_calls, mock_identity_get.num_calls)
392+
self.assertEqual(num_calls, mock_identity_get.num_calls)
393393
url = mock_request.call_args[0][1]
394-
self.assertEquals(url, 'https://api-test.mycroft.ai/v1/device/1234')
394+
self.assertEqual(url, 'https://api-test.mycroft.ai/v1/device/1234')
395395

396396
def test_is_paired_false_local(self, mock_request, mock_identity_get):
397397
mock_request.return_value = create_response(200)

test/unittests/audio/test_service.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def setUp(self):
5252
def test_load(self):
5353
services = audio_service.load_services({}, TestService.emitter,
5454
TestService.service_path)
55-
self.assertEquals(len(services), 1)
55+
self.assertEqual(len(services), 1)
5656

5757

5858
if __name__ == "__main__":

test/unittests/client/test_audio_consumer.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def callback(message):
123123
utterances = monitor.get('utterances')
124124
self.assertIsNotNone(utterances)
125125
self.assertTrue(len(utterances) == 1)
126-
self.assertEquals("what's the weather next week", utterances[0])
126+
self.assertEqual("what's the weather next week", utterances[0])
127127

128128
@unittest.skip('Disabled while unittests are brought upto date')
129129
def test_wakeword(self):
@@ -141,7 +141,7 @@ def callback(message):
141141
utterances = monitor.get('utterances')
142142
self.assertIsNotNone(utterances)
143143
self.assertTrue(len(utterances) == 1)
144-
self.assertEquals("silence", utterances[0])
144+
self.assertEqual("silence", utterances[0])
145145

146146
def test_ignore_wakeword_when_sleeping(self):
147147
self.queue.put((AUDIO_DATA,
@@ -186,7 +186,7 @@ def utterance_callback(message):
186186
utterances = monitor.get('utterances')
187187
self.assertIsNotNone(utterances)
188188
self.assertTrue(len(utterances) == 1)
189-
self.assertEquals("stop", utterances[0])
189+
self.assertEqual("stop", utterances[0])
190190

191191
@unittest.skip('Disabled while unittests are brought upto date')
192192
def test_record(self):
@@ -208,4 +208,4 @@ def utterance_callback(message):
208208
utterances = monitor.get('utterances')
209209
self.assertIsNotNone(utterances)
210210
self.assertTrue(len(utterances) == 1)
211-
self.assertEquals("record", utterances[0])
211+
self.assertEqual("record", utterances[0])

test/unittests/client/test_hotword_factory.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ def testDefault(self):
2828
}
2929
p = HotWordFactory.create_hotword('hey mycroft', config)
3030
config = config['hey mycroft']
31-
self.assertEquals(config['phonemes'], p.phonemes)
32-
self.assertEquals(config['threshold'], p.threshold)
31+
self.assertEqual(config['phonemes'], p.phonemes)
32+
self.assertEqual(config['threshold'], p.threshold)
3333

3434
def testInvalid(self):
3535
config = {
@@ -40,8 +40,8 @@ def testInvalid(self):
4040
}
4141
}
4242
p = HotWordFactory.create_hotword('hey Zeds', config)
43-
self.assertEquals(p.phonemes, 'HH EY . M AY K R AO F T')
44-
self.assertEquals(p.key_phrase, 'hey mycroft')
43+
self.assertEqual(p.phonemes, 'HH EY . M AY K R AO F T')
44+
self.assertEqual(p.key_phrase, 'hey mycroft')
4545

4646
def testVictoria(self):
4747
config = {
@@ -53,5 +53,5 @@ def testVictoria(self):
5353
}
5454
p = HotWordFactory.create_hotword('hey victoria', config)
5555
config = config['hey victoria']
56-
self.assertEquals(config['phonemes'], p.phonemes)
57-
self.assertEquals(p.key_phrase, 'hey victoria')
56+
self.assertEqual(config['phonemes'], p.phonemes)
57+
self.assertEqual(p.key_phrase, 'hey victoria')

test/unittests/client/test_local_recognizer.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,17 @@ def testRecognizer(self, mock_config_get):
5757

5858
# Test "Hey Mycroft"
5959
rl = RecognizerLoop()
60-
self.assertEquals(rl.wakeword_recognizer.key_phrase, "hey mycroft")
60+
self.assertEqual(rl.wakeword_recognizer.key_phrase, "hey mycroft")
6161

6262
# Test "Hey Victoria"
6363
test_config['listener']['wake_word'] = 'hey victoria'
6464
test_config['listener']['phonemes'] = 'HH EY . V IH K T AO R IY AH'
6565
test_config['listener']['threshold'] = 1e-90
6666
rl = RecognizerLoop()
67-
self.assertEquals(rl.wakeword_recognizer.key_phrase, "hey victoria")
67+
self.assertEqual(rl.wakeword_recognizer.key_phrase, "hey victoria")
6868

6969
# Test Invalid"
7070
test_config['listener']['wake_word'] = 'hey victoria'
7171
test_config['listener']['phonemes'] = 'ZZZZZZZZZZZZ'
7272
rl = RecognizerLoop()
73-
self.assertEquals(rl.wakeword_recognizer.key_phrase, "hey mycroft")
73+
self.assertEqual(rl.wakeword_recognizer.key_phrase, "hey mycroft")

0 commit comments

Comments
 (0)