From 4fb8205cab1967e939a625af6caf82a4db549c9d Mon Sep 17 00:00:00 2001 From: Marek Ventur Date: Wed, 29 Aug 2018 12:38:59 +0100 Subject: [PATCH] Fix tests, remove debug leftovers --- .development/copy_via_repl_header.py | 8 +++++-- .development/pyboard_util.py | 6 +++-- boot.py | 2 +- lib/homescreen.py | 4 ++-- lib/test_ntp.py | 8 +++++-- lib/test_wifi.py | 9 ++++---- lib/wifi.py | 33 ++++++++++++---------------- synth/main.py | 1 - 8 files changed, 37 insertions(+), 34 deletions(-) diff --git a/.development/copy_via_repl_header.py b/.development/copy_via_repl_header.py index f695f7d..3e139fc 100644 --- a/.development/copy_via_repl_header.py +++ b/.development/copy_via_repl_header.py @@ -48,13 +48,17 @@ def h(p): def w(p, c): try: + print("file", p) makedirs(dirname(p)) with open(p, "wb") as f: f.write(binascii.a2b_base64(c)) os.sync() + print("OK") except Exception as e: - print(str(e)) - return None + import sys + print("Error while writing file %s" % p) + sys.print_exception(e) + pass def clean(path=""): for s in os.listdir(path): diff --git a/.development/pyboard_util.py b/.development/pyboard_util.py index 17d767f..9ae4faf 100644 --- a/.development/pyboard_util.py +++ b/.development/pyboard_util.py @@ -179,8 +179,10 @@ def write_via_repl(args, content, rel_path): return False cmd = "w(%s, \"%s\")\n" % (rel_path_as_string, content) - execbuffer(pyb,cmd) - return True + result = returnbuffer(pyb,cmd) + if "OK" in result: + return True + raise Exception("Couldn't write %s to badge: %s" % (rel_path, result)) def end_copy_via_repl(args): # do we need to do anything? diff --git a/boot.py b/boot.py index baa583e..e319cdc 100644 --- a/boot.py +++ b/boot.py @@ -17,7 +17,7 @@ def file(file, remove): os.remove(file) return app(a) except Exception as e: - print(str(e)) + print("Not found: %s" % file) def any_home(): h = [a for a in root if a.startswith("home")] diff --git a/lib/homescreen.py b/lib/homescreen.py index 106407b..af1d177 100644 --- a/lib/homescreen.py +++ b/lib/homescreen.py @@ -17,9 +17,9 @@ They also *may*: """ ___license___ = "MIT" -___dependencies___ = ["database", "buttons", "random", "app", "sleep", "ugfx_helper"] +___dependencies___ = ["database", "buttons", "random", "app", "sleep", "ugfx_helper", "wifi"] -import database, ugfx, random, buttons, tilda, sleep, ugfx_helper +import database, ugfx, random, buttons, tilda, sleep, ugfx_helper, wifi from app import App _state = None diff --git a/lib/test_ntp.py b/lib/test_ntp.py index 4eb2c8a..4058ef9 100644 --- a/lib/test_ntp.py +++ b/lib/test_ntp.py @@ -1,15 +1,19 @@ """Tests for ntp""" ___license___ = "MIT" -___dependencies___ = ["upip:unittest", "ntp", "wifi"] +___dependencies___ = ["upip:unittest", "ntp", "wifi", "ugfx_helper"] -import unittest, wifi, ntp, machine +import unittest, wifi, ntp, machine, ugfx_helper class TestWifi(unittest.TestCase): def setUpClass(self): + ugfx_helper.init() wifi.connect() + def tearDownClass(self): + ugfx_helper.deinit() + def test_get_time(self): t = ntp.get_NTP_time() self.assertTrue(t > 588699276) diff --git a/lib/test_wifi.py b/lib/test_wifi.py index 94a64ba..c768348 100644 --- a/lib/test_wifi.py +++ b/lib/test_wifi.py @@ -1,19 +1,18 @@ """Tests for wifi""" ___license___ = "MIT" -___dependencies___ = ["upip:unittest", "wifi"] +___dependencies___ = ["upip:unittest", "wifi", "ugfx_helper"] -import unittest, wifi, ugfx +import unittest, wifi, ugfx_helper from machine import Pin class TestWifi(unittest.TestCase): def setUpClass(self): - ugfx.init() - Pin(Pin.PWM_LCD_BLIGHT).on() + ugfx_helper.init() def tearDownClass(self): - Pin(Pin.PWM_LCD_BLIGHT).off() + ugfx_helper.deinit() def test_connect(self): wifi.connect(show_wait_message=True) diff --git a/lib/wifi.py b/lib/wifi.py index 3ef236a..c7e7e6a 100644 --- a/lib/wifi.py +++ b/lib/wifi.py @@ -85,20 +85,22 @@ def connect_wifi(details, timeout, wait=False): def is_connected(): return nic().isconnected() +def get_strength(): + n = nic() + if n.isconnected(): + r + else: + return None + def get_security_level(ap): #todo: fix this n = nic() - levels = {} - try: - levels = { - n.SCAN_SEC_OPEN: 0, # I am awful - n.SCAN_SEC_WEP: 'WEP', - n.SCAN_SEC_WPA: 'WPA', - n.SCAN_SEC_WPA2: 'WPA2', - } - except AttributeError: - print("Firmware too old to query wifi security level, please upgrade.") - return None + levels = { + n.SCAN_SEC_OPEN: 0, # I am awful + n.SCAN_SEC_WEP: 'WEP', + n.SCAN_SEC_WPA: 'WPA', + n.SCAN_SEC_WPA2: 'WPA2', + } return levels.get(ap.get('security', None), None) @@ -111,9 +113,7 @@ def choose_wifi(dialog_title='TiLDA'): print(visible_aps) sleep.sleep_ms(300) #todo: timeout - print(visible_aps) visible_aps.sort(key=lambda x:x[3], reverse=True) - print(visible_aps) # We'll get one result for each AP, so filter dupes for ap in visible_aps: title = ap[0] @@ -128,7 +128,6 @@ def choose_wifi(dialog_title='TiLDA'): if ap['ssid'] not in [ a['ssid'] for a in filtered_aps ]: filtered_aps.append(ap) del visible_aps - print(filtered_aps) ap = dialogs.prompt_option( filtered_aps, @@ -142,11 +141,7 @@ def choose_wifi(dialog_title='TiLDA'): if ap['security'] == None: ap['security'] = 'wifi' - key = dialogs.prompt_text( - "Enter %s key" % ap['security'], - width = 310, - height = 220 - ) + key = dialogs.prompt_text("Enter %s key" % ap['security']) with open("wifi.json", "wt") as file: if key: conn_details = {"ssid": ap['ssid'], "pw": key} diff --git a/synth/main.py b/synth/main.py index 7e47faa..7b17eb6 100644 --- a/synth/main.py +++ b/synth/main.py @@ -9,7 +9,6 @@ ___categories___ = ["Sound"] ___dependencies___ = ["speaker", "buttons", "ugfx_helper"] import ugfx, speaker, ugfx_helper -from app import * from tilda import Buttons from buttons import *