summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-01-05 13:44:06 +0000
committerDamien George <damien.p.george@gmail.com>2014-01-05 13:44:06 +0000
commitf0691f4ed58cab324dee151886ec13cecc1b6771 (patch)
treebae713f78b7263dbef2f4658fa89685d6d5d4b84
parenta3ab68e9493481a3fcbd1b74278d199c53a3c2f6 (diff)
downloadmicropython-f0691f4ed58cab324dee151886ec13cecc1b6771.tar.gz
micropython-f0691f4ed58cab324dee151886ec13cecc1b6771.zip
Fix qstr in objlist.c; add more tests for list.index.
list.index fails on an edge case.
-rw-r--r--py/objlist.c2
-rw-r--r--tests/basics/tests/list_index.py14
2 files changed, 14 insertions, 2 deletions
diff --git a/py/objlist.c b/py/objlist.c
index 7b3b6f1772..6c0de405fe 100644
--- a/py/objlist.c
+++ b/py/objlist.c
@@ -194,7 +194,7 @@ static mp_obj_t list_index(int n_args, const mp_obj_t *args) {
}
}
- nlr_jump(mp_obj_new_exception_msg(rt_q_ValueError, "Object not in list."));
+ nlr_jump(mp_obj_new_exception_msg(MP_QSTR_ValueError, "object not in list"));
}
static MP_DEFINE_CONST_FUN_OBJ_2(list_append_obj, mp_obj_list_append);
diff --git a/tests/basics/tests/list_index.py b/tests/basics/tests/list_index.py
index cc853fe0e7..f28263fba6 100644
--- a/tests/basics/tests/list_index.py
+++ b/tests/basics/tests/list_index.py
@@ -1,12 +1,24 @@
a = [1, 2, 3]
+print(a.index(1))
+print(a.index(2))
+print(a.index(3))
+print(a.index(3, 2))
+try:
+ print(a.index(3, 2, 2))
+except ValueError:
+ print("Raised ValueError")
+else:
+ print("Did not raise ValueError")
+
a = a + a
b = [0, 0, a]
print(a.index(2))
print(b.index(a))
print(a.index(2, 2))
+
try:
a.index(2, 2, 2)
except ValueError:
print("Raised ValueError")
else:
- raise AssertionError("Did not raise ValueError")
+ print("Did not raise ValueError")