Skip to content

Commit

Permalink
Remove warnings and errors from checkpoints (google#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
iblancasa authored and drigz committed Sep 5, 2017
1 parent 51f7a6f commit 2efb7f6
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 39 deletions.
18 changes: 8 additions & 10 deletions checkpoints/check_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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...')
24 changes: 12 additions & 12 deletions checkpoints/check_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand All @@ -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...')
9 changes: 4 additions & 5 deletions checkpoints/check_wifi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


Expand All @@ -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


Expand All @@ -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...')
22 changes: 10 additions & 12 deletions checkpoints/load_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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():
Expand All @@ -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:
Expand Down Expand Up @@ -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...')

0 comments on commit 2efb7f6

Please sign in to comment.