black
This commit is contained in:
parent
3de883529e
commit
481d615920
2 changed files with 15 additions and 9 deletions
|
|
@ -64,7 +64,7 @@ _CHANGED_STATE = const(0x04)
|
|||
|
||||
# Find out whether the current CircuitPython supports time.monotonic_ns(),
|
||||
# which doesn't have the accuracy limitation.
|
||||
if hasattr(time, 'monotonic_ns'):
|
||||
if hasattr(time, "monotonic_ns"):
|
||||
TICKS_PER_SEC = 1_000_000_000
|
||||
MONOTONIC_TICKS = time.monotonic_ns
|
||||
else:
|
||||
|
|
@ -129,7 +129,6 @@ class Debouncer:
|
|||
"""The debounce delay, in seconds"""
|
||||
return self._interval_ticks / TICKS_PER_SEC
|
||||
|
||||
|
||||
@interval.setter
|
||||
def interval(self, new_interval_s):
|
||||
self._interval_ticks = new_interval_s * TICKS_PER_SEC
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ import adafruit_debouncer
|
|||
|
||||
def _true():
|
||||
return True
|
||||
|
||||
|
||||
def _false():
|
||||
return False
|
||||
|
||||
|
|
@ -53,17 +55,20 @@ def test_back_and_forth():
|
|||
assertEqual(db.fell, False)
|
||||
assertEqual(db.rose, False)
|
||||
time.sleep(0.02)
|
||||
assert 0.019 < db.current_duration <= 1, \
|
||||
assert 0.019 < db.current_duration <= 1, (
|
||||
"Unit error? sleep .02 -> duration %d" % db.current_duration
|
||||
)
|
||||
db.update()
|
||||
assertEqual(db.value, False)
|
||||
assertEqual(db.rose, False)
|
||||
assertEqual(db.fell, True)
|
||||
|
||||
assert 0 < db.current_duration <= 0.1, \
|
||||
assert 0 < db.current_duration <= 0.1, (
|
||||
"Unit error? time to run asserts %d" % db.current_duration
|
||||
assert 0 < db.last_duration < 0.1, \
|
||||
)
|
||||
assert 0 < db.last_duration < 0.1, (
|
||||
"Unit error? Last dur should be ~.02, is %d" % db.last_duration
|
||||
)
|
||||
|
||||
|
||||
def test_interval_is_the_same():
|
||||
|
|
@ -115,7 +120,7 @@ def run():
|
|||
passes = 0
|
||||
fails = 0
|
||||
for name, test in locals().items():
|
||||
if name.startswith('test_') and callable(test):
|
||||
if name.startswith("test_") and callable(test):
|
||||
try:
|
||||
print()
|
||||
print(name)
|
||||
|
|
@ -129,7 +134,8 @@ def run():
|
|||
|
||||
print(passes, "passed,", fails, "failed")
|
||||
if passes and not fails:
|
||||
print(r"""
|
||||
print(
|
||||
r"""
|
||||
________
|
||||
< YATTA! >
|
||||
--------
|
||||
|
|
@ -137,8 +143,9 @@ def run():
|
|||
\ (oo)\_______
|
||||
(__)\ )\/\
|
||||
||----w |
|
||||
|| ||""")
|
||||
|| ||"""
|
||||
)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
run()
|
||||
|
|
|
|||
Loading…
Reference in a new issue