diff --git a/checkpoints/check_audio.py b/checkpoints/check_audio.py index 2f9d79ae..80a7710e 100755 --- a/checkpoints/check_audio.py +++ b/checkpoints/check_audio.py @@ -13,8 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -"""Check that the voiceHAT audio input and output are both working. -""" +"""Check that the voiceHAT audio input and output are both working.""" import os import subprocess @@ -59,17 +58,17 @@ def get_sound_cards(): def is_service_active(): - """Returns True if the voice-recognizer service is active.""" + """Return True if the voice-recognizer service is active.""" output = subprocess.check_output(['systemctl', 'show', SERVICE_NAME]).decode('utf-8') if ACTIVE_STR in output: return True elif INACTIVE_STR in output: return False - else: - print('WARNING: failed to parse output:') - print(output) - return False + + print('WARNING: failed to parse output:') + print(output) + return False def ask(prompt): @@ -107,13 +106,11 @@ def start_service(): def check_voicehat_present(): """Check that the voiceHAT is present.""" - return any(VOICEHAT_ID in card for card in get_sound_cards().values()) def check_voicehat_is_first_card(): """Check that the voiceHAT is the first card on the system.""" - cards = get_sound_cards() return 0 in cards and VOICEHAT_ID in cards[0] @@ -185,10 +182,11 @@ def main(): if should_restart: start_service() + if __name__ == '__main__': try: main() input('Press Enter to close...') - except: # pylint: disable=bare-except + except Exception: # pylint: disable=W0703 traceback.print_exc() input('Press Enter to close...') diff --git a/checkpoints/check_cloud.py b/checkpoints/check_cloud.py index ce98af12..75927be4 100755 --- a/checkpoints/check_cloud.py +++ b/checkpoints/check_cloud.py @@ -13,8 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -"""Check that the Cloud Speech API can be used. -""" +"""Check that the Cloud Speech API can be used.""" import json import os @@ -60,15 +59,15 @@ def check_speech_reco(): print('Speech recognition failed with', p.returncode) print(output) return False - else: - # speech.py succeeded, check the text was recognized - if RECOGNIZED_TEXT in output: - return True - else: - print('Speech recognition output not as expected:') - print(output) - print('Expected:', RECOGNIZED_TEXT) - return False + + # speech.py succeeded, check the text was recognized + if RECOGNIZED_TEXT in output: + return True + + print('Speech recognition output not as expected:') + print(output) + print('Expected:', RECOGNIZED_TEXT) + return False def main(): @@ -92,10 +91,11 @@ def main(): print("Everything's set up to use the Google Cloud.") + if __name__ == '__main__': try: main() input('Press Enter to close...') - except: # pylint: disable=bare-except + except Exception: # pylint: disable=W0703 traceback.print_exc() input('Press Enter to close...') diff --git a/checkpoints/check_wifi.py b/checkpoints/check_wifi.py index a70096b1..cb52f326 100755 --- a/checkpoints/check_wifi.py +++ b/checkpoints/check_wifi.py @@ -13,8 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -"""Check that the WiFi is working. -""" +"""Check that the WiFi is working.""" import socket import subprocess @@ -27,7 +26,6 @@ def check_wifi_is_configured(): """Check wpa_supplicant.conf has at least one network configured.""" output = subprocess.check_output(['sudo', 'cat', WPA_CONF_PATH]).decode('utf-8') - return 'network=' in output @@ -45,7 +43,7 @@ def check_can_reach_google_server(): sock = socket.create_connection(GOOGLE_SERVER_ADDRESS, timeout=10) sock.close() return True - except: # Many exceptions can come from sockets. pylint: disable=bare-except + except Exception: # pylint: disable=W0703 return False @@ -71,10 +69,11 @@ def main(): print('The WiFi connection seems to be working.') + if __name__ == '__main__': try: main() input('Press Enter to close...') - except: # pylint: disable=bare-except + except Exception: # pylint: disable=W0703 traceback.print_exc() input('Press Enter to close...') diff --git a/checkpoints/load_test.py b/checkpoints/load_test.py index 0dc51520..776d804f 100755 --- a/checkpoints/load_test.py +++ b/checkpoints/load_test.py @@ -13,8 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -"""Synthetic load test simillar to running the actual app. -""" +"""Synthetic load test simillar to running the actual app.""" import json import os @@ -60,17 +59,17 @@ def check_credentials_valid(): def is_service_active(): - """Returns True if the voice-recognizer service is active.""" + """Return True if the voice-recognizer service is active.""" output = subprocess.check_output(['systemctl', 'show', SERVICE_NAME]).decode('utf-8') if ACTIVE_STR in output: return True elif INACTIVE_STR in output: return False - else: - print('WARNING: failed to parse output:') - print(output) - return False + + print('WARNING: failed to parse output:') + print(output) + return False def stop_service(): @@ -103,10 +102,7 @@ def check_speech_reco(): stdout=subprocess.PIPE, stderr=subprocess.STDOUT) p.communicate()[0].decode('utf-8') - if p.returncode: - return False - else: - return True + return not p.returncode def play_wav(): @@ -130,11 +126,13 @@ def record_wav(): def led_status(status): + """Get the led status.""" with open(LED_FIFO, 'w') as led: led.write(status + '\n') def run_test(): + """Start the test.""" print('Running test forever - press Ctrl+C to stop...') try: while True: @@ -182,6 +180,6 @@ def main(): try: main() input('Press Enter to close...') - except: # pylint: disable=bare-except + except Exception: # pylint: disable=W0703 traceback.print_exc() input('Press Enter to close...')