summaryrefslogtreecommitdiff
path: root/tests/extmod
diff options
context:
space:
mode:
authorScott Shawcroft <scott@chickadee.tech>2016-09-19 13:32:29 -0700
committerScott Shawcroft <scott@chickadee.tech>2016-09-19 13:32:29 -0700
commitbb03afdb77c95b9cb23e531e5763167ccb09c8e4 (patch)
tree509722778a03b10c933963a35c93eb5670a5cdb5 /tests/extmod
parent345dd1484c4e68f53ea242c5778a2de99119db9a (diff)
parent60592fd23c8acd4ed4f70d8fbe8f8b11ea58082c (diff)
Merge remote-tracking branch 'micropython/master'
Diffstat (limited to 'tests/extmod')
-rw-r--r--tests/extmod/framebuf1.py41
-rw-r--r--tests/extmod/framebuf1.py.exp9
-rw-r--r--tests/extmod/machine_pulse.py54
-rw-r--r--tests/extmod/machine_pulse.py.exp9
-rw-r--r--tests/extmod/urandom_basic.py6
-rw-r--r--tests/extmod/urandom_extra.py37
-rw-r--r--tests/extmod/uzlib_decompio.py15
-rw-r--r--tests/extmod/uzlib_decompio.py.exp3
8 files changed, 173 insertions, 1 deletions
diff --git a/tests/extmod/framebuf1.py b/tests/extmod/framebuf1.py
new file mode 100644
index 000000000..f550b6b4f
--- /dev/null
+++ b/tests/extmod/framebuf1.py
@@ -0,0 +1,41 @@
+try:
+ import framebuf
+except ImportError:
+ print("SKIP")
+ import sys
+ sys.exit()
+
+w = 5
+h = 16
+buf = bytearray(w * h // 8)
+fbuf = framebuf.FrameBuffer1(buf, w, h, w)
+
+# fill
+fbuf.fill(1)
+print(buf)
+fbuf.fill(0)
+print(buf)
+
+# put pixel
+fbuf.pixel(0, 0, 1)
+fbuf.pixel(4, 0, 1)
+fbuf.pixel(0, 15, 1)
+fbuf.pixel(4, 15, 1)
+print(buf)
+
+# get pixel
+print(fbuf.pixel(0, 0), fbuf.pixel(1, 1))
+
+# scroll
+fbuf.fill(0)
+fbuf.pixel(2, 7, 1)
+fbuf.scroll(0, 1)
+print(buf)
+fbuf.scroll(0, -2)
+print(buf)
+fbuf.scroll(1, 0)
+print(buf)
+fbuf.scroll(-1, 0)
+print(buf)
+fbuf.scroll(2, 2)
+print(buf)
diff --git a/tests/extmod/framebuf1.py.exp b/tests/extmod/framebuf1.py.exp
new file mode 100644
index 000000000..8fd8c3709
--- /dev/null
+++ b/tests/extmod/framebuf1.py.exp
@@ -0,0 +1,9 @@
+bytearray(b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff')
+bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
+bytearray(b'\x01\x00\x00\x00\x01\x80\x00\x00\x00\x80')
+1 0
+bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00')
+bytearray(b'\x00\x00@\x00\x00\x00\x00\x00\x00\x00')
+bytearray(b'\x00\x00\x00@\x00\x00\x00\x00\x00\x00')
+bytearray(b'\x00\x00@\x00\x00\x00\x00\x00\x00\x00')
+bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01')
diff --git a/tests/extmod/machine_pulse.py b/tests/extmod/machine_pulse.py
new file mode 100644
index 000000000..b6e126435
--- /dev/null
+++ b/tests/extmod/machine_pulse.py
@@ -0,0 +1,54 @@
+try:
+ import umachine as machine
+except ImportError:
+ import machine
+try:
+ machine.PinBase
+ machine.time_pulse_us
+except AttributeError:
+ print("SKIP")
+ import sys
+ sys.exit()
+
+
+class ConstPin(machine.PinBase):
+
+ def __init__(self, value):
+ self.v = value
+
+ def value(self, v=None):
+ if v is None:
+ return self.v
+ else:
+ self.v = v
+
+
+class TogglePin(machine.PinBase):
+
+ def __init__(self):
+ self.v = 0
+
+ def value(self, v=None):
+ if v is None:
+ self.v = 1 - self.v
+ print("value:", self.v)
+ return self.v
+
+
+p = TogglePin()
+
+t = machine.time_pulse_us(p, 1)
+print(type(t))
+t = machine.time_pulse_us(p, 0)
+print(type(t))
+
+p = ConstPin(0)
+try:
+ machine.time_pulse_us(p, 1, 10)
+except OSError:
+ print("OSError")
+
+try:
+ machine.time_pulse_us(p, 0, 10)
+except OSError:
+ print("OSError")
diff --git a/tests/extmod/machine_pulse.py.exp b/tests/extmod/machine_pulse.py.exp
new file mode 100644
index 000000000..f9a474218
--- /dev/null
+++ b/tests/extmod/machine_pulse.py.exp
@@ -0,0 +1,9 @@
+value: 1
+value: 0
+<class 'int'>
+value: 1
+value: 0
+value: 1
+<class 'int'>
+OSError
+OSError
diff --git a/tests/extmod/urandom_basic.py b/tests/extmod/urandom_basic.py
index 7e4d8bf34..bf00035bd 100644
--- a/tests/extmod/urandom_basic.py
+++ b/tests/extmod/urandom_basic.py
@@ -17,3 +17,9 @@ random.seed(1)
r = random.getrandbits(16)
random.seed(1)
print(random.getrandbits(16) == r)
+
+# check that it throws an error for zero bits
+try:
+ random.getrandbits(0)
+except ValueError:
+ print('ValueError')
diff --git a/tests/extmod/urandom_extra.py b/tests/extmod/urandom_extra.py
index a9ecd881d..004fb10cc 100644
--- a/tests/extmod/urandom_extra.py
+++ b/tests/extmod/urandom_extra.py
@@ -16,6 +16,31 @@ for i in range(50):
assert 2 <= random.randrange(2, 6) < 6
assert -2 <= random.randrange(-2, 2) < 2
assert random.randrange(1, 9, 2) in (1, 3, 5, 7)
+ assert random.randrange(2, 1, -1) in (1, 2)
+
+# empty range
+try:
+ random.randrange(0)
+except ValueError:
+ print('ValueError')
+
+# empty range
+try:
+ random.randrange(2, 1)
+except ValueError:
+ print('ValueError')
+
+# zero step
+try:
+ random.randrange(2, 1, 0)
+except ValueError:
+ print('ValueError')
+
+# empty range
+try:
+ random.randrange(2, 1, 1)
+except ValueError:
+ print('ValueError')
print('randint')
for i in range(50):
@@ -23,11 +48,23 @@ for i in range(50):
assert 2 <= random.randint(2, 6) <= 6
assert -2 <= random.randint(-2, 2) <= 2
+# empty range
+try:
+ random.randint(2, 1)
+except ValueError:
+ print('ValueError')
+
print('choice')
lst = [1, 2, 5, 6]
for i in range(50):
assert random.choice(lst) in lst
+# empty sequence
+try:
+ random.choice([])
+except IndexError:
+ print('IndexError')
+
print('random')
for i in range(50):
assert 0 <= random.random() < 1
diff --git a/tests/extmod/uzlib_decompio.py b/tests/extmod/uzlib_decompio.py
index ee3204d07..75a6df0ca 100644
--- a/tests/extmod/uzlib_decompio.py
+++ b/tests/extmod/uzlib_decompio.py
@@ -7,7 +7,7 @@ import uio as io
# Raw DEFLATE bitstream
buf = io.BytesIO(b'\xcbH\xcd\xc9\xc9\x07\x00')
-inp = zlib.DecompIO(buf)
+inp = zlib.DecompIO(buf, -8)
print(buf.seek(0, 1))
print(inp.read(1))
print(buf.seek(0, 1))
@@ -17,3 +17,16 @@ print(buf.seek(0, 1))
print(inp.read(1))
print(inp.read())
print(buf.seek(0, 1))
+
+
+# zlib bitstream
+inp = zlib.DecompIO(io.BytesIO(b'x\x9c30\xa0=\x00\x00\xb3q\x12\xc1'))
+print(inp.read(10))
+print(inp.read())
+
+# zlib bitstream, wrong checksum
+inp = zlib.DecompIO(io.BytesIO(b'x\x9c30\xa0=\x00\x00\xb3q\x12\xc0'))
+try:
+ print(inp.read())
+except OSError as e:
+ print(repr(e))
diff --git a/tests/extmod/uzlib_decompio.py.exp b/tests/extmod/uzlib_decompio.py.exp
index 6ef811d7d..3f5f360fa 100644
--- a/tests/extmod/uzlib_decompio.py.exp
+++ b/tests/extmod/uzlib_decompio.py.exp
@@ -7,3 +7,6 @@ b'lo'
b''
b''
7
+b'0000000000'
+b'000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
+OSError(22,)