New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix tests on targets that don't support floats #3969
Conversation
py/objstr.c
Outdated
@@ -2098,11 +2098,11 @@ bool mp_obj_str_equal(mp_obj_t s1, mp_obj_t s2) { | |||
|
|||
STATIC NORETURN void bad_implicit_conversion(mp_obj_t self_in) { | |||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { | |||
mp_raise_TypeError("can't convert to str implicitly"); | |||
mp_raise_TypeError("Can't convert to str implicitly"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most (I thought it was "all" but apparently not) of the CPython error messages start with a lower case letter, so that's what we try and do consistently in uPy. And we don't match 100% with CPython error messages because it's not really important. So I don't see a reason to make this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason I changed is that the test would otherwise fail (apparently run-tests is testing against CPython?). But with the changes suggested below this isn't necessary anymore.
py/objstr.c
Outdated
} else { | ||
const qstr src_name = mp_obj_get_type(self_in)->name; | ||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, | ||
"can't convert '%q' object to %q implicitly", | ||
"Can't convert '%q' object to %q implicitly", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above comment
tests/basics/op_precedence.py
Outdated
except SyntaxError: | ||
print('0.5') # skip test | ||
else: | ||
print(2**-1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! What it's really testing is order or parsing of ** -
, not FP, so I think it's best to change it to something that works without FP. How about 2**-0
? Or even 2**-(-1)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, of course! 2**-0
doesn't use floating point so that works.
tests/extmod/urandom_extra.py
Outdated
pass | ||
else: | ||
for i in range(50): | ||
assert 0 <= random.random() < 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll see that ujson
float tests are split out into separate files. Let's do the same here: move all float related functions from this file into urandom_extra_float.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. That's a lot nicer.
tests/misc/print_exception.py
Outdated
@@ -31,7 +31,7 @@ def print_exc(e): | |||
|
|||
# basic exception message | |||
try: | |||
1/0 | |||
'1'+1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about 1//0
, to try and make a minimal change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea!
tests/misc/print_exception.py
Outdated
@@ -40,7 +40,7 @@ def print_exc(e): | |||
def f(): | |||
g() | |||
def g(): | |||
2/0 | |||
''+2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above, 2//0
?
At some point in the past there was an effort to make the tests in |
f4ff3a8
to
5ced89c
Compare
Those are all good suggestions. I've updated the PR. EDIT: I'll investigate soonish why it doesn't work at the moment. It is probably because divide by zero gives a different error message in CPython and MicroPython (that's what it was the last time I looked). |
Yes that's right. The aim of |
Fixed it. Together with #3970 I can use my emulator for the PCA10028 passing all tests. |
Thanks! Merged in 6572029 |
Fixes and Enhancement for Touch Alarm
While trying to get the nrf51 emulator to work (which passes most tests now!), I noticed there is no full support for targets that don't support floating point as some tests assume the presence of a floating point unit.
EDIT: offtopic, but with a bigger heap I managed to pass all tests in the nrf51 emulator :D apparently 10kB was a bit too small for a few tests (they all caused a MemoryError).