summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYonatan Goldschmidt <yon.goldschmidt@gmail.com>2020-01-22 20:44:52 +0100
committerDamien George <damien.p.george@gmail.com>2020-01-24 10:57:17 +1100
commit35e664d7790b123dab54faff766f41991f4620d1 (patch)
treef78a0182f8bbfaf923c89ecff262ffcf3c2afc2e
parentd9433d3e9497a4ec4cd51eb78d6ca602f310ce91 (diff)
tests/unix: Add coverage tests for mp_obj_is_type() and variants.
-rw-r--r--ports/unix/coverage.c23
-rw-r--r--tests/unix/extra_coverage.py.exp8
2 files changed, 30 insertions, 1 deletions
diff --git a/ports/unix/coverage.c b/ports/unix/coverage.c
index e4d2d68fc..1b6132cdd 100644
--- a/ports/unix/coverage.c
+++ b/ports/unix/coverage.c
@@ -16,6 +16,8 @@
#include "py/binary.h"
#include "py/bc.h"
+// expected output of this file is found in extra_coverage.py.exp
+
#if defined(MICROPY_UNIX_COVERAGE)
// stream testing object
@@ -539,7 +541,7 @@ STATIC mp_obj_t extra_coverage(void) {
ringbuf.iput = 0;
ringbuf.iget = 0;
mp_printf(&mp_plat_print, "%d\n", ringbuf_get16(&ringbuf));
-
+
// Two-byte get from ringbuf with one byte available.
ringbuf.iput = 0;
ringbuf.iget = 0;
@@ -576,6 +578,25 @@ STATIC mp_obj_t extra_coverage(void) {
pairheap_test(MP_ARRAY_SIZE(t5), t5);
}
+ // mp_obj_is_type and derivatives
+ {
+ mp_printf(&mp_plat_print, "# mp_obj_is_type\n");
+
+ // mp_obj_is_bool accepts only booleans
+ mp_printf(&mp_plat_print, "%d %d\n", mp_obj_is_bool(mp_const_true), mp_obj_is_bool(mp_const_false));
+ mp_printf(&mp_plat_print, "%d %d\n", mp_obj_is_bool(MP_OBJ_NEW_SMALL_INT(1)), mp_obj_is_bool(mp_const_none));
+
+ // mp_obj_is_integer accepts ints and booleans
+ mp_printf(&mp_plat_print, "%d %d\n", mp_obj_is_integer(MP_OBJ_NEW_SMALL_INT(1)), mp_obj_is_integer(mp_obj_new_int_from_ll(1)));
+ mp_printf(&mp_plat_print, "%d %d\n", mp_obj_is_integer(mp_const_true), mp_obj_is_integer(mp_const_false));
+ mp_printf(&mp_plat_print, "%d %d\n", mp_obj_is_integer(mp_obj_new_str("1", 1)), mp_obj_is_integer(mp_const_none));
+
+ // mp_obj_is_int accepts small int and object ints
+ mp_printf(&mp_plat_print, "%d %d\n", mp_obj_is_int(MP_OBJ_NEW_SMALL_INT(1)), mp_obj_is_int(mp_obj_new_int_from_ll(1)));
+ }
+
+ mp_printf(&mp_plat_print, "# end coverage.c\n");
+
mp_obj_streamtest_t *s = m_new_obj(mp_obj_streamtest_t);
s->base.type = &mp_type_stest_fileio;
s->buf = NULL;
diff --git a/tests/unix/extra_coverage.py.exp b/tests/unix/extra_coverage.py.exp
index 9c3b036b9..6130a0651 100644
--- a/tests/unix/extra_coverage.py.exp
+++ b/tests/unix/extra_coverage.py.exp
@@ -115,6 +115,14 @@ create: 1 1 1 1 1
pop all: 1 3 4
create: 3 3 3 1 1 1
pop all: 1 2 4 5
+# mp_obj_is_type
+1 1
+0 0
+1 1
+1 1
+0 0
+1 1
+# end coverage.c
0123456789 b'0123456789'
7300
7300