Skip to content

Conversation

@jepler
Copy link
Contributor

@jepler jepler commented Nov 2, 2024

The test case was producing the following error:

Traceback (most recent call last):
  File "<stdin>", line 12, in <module>
UnicodeError:

which did not demonstrate the intended difference. (this particular non-json-serializable object DID throw an exception! just not TypeError)

The updated version creates the non-conforming json string "<module 'json'>" instead, better illustrating the problem.

I tested by manually running the example using a coverage build & in cpython.

@codecov
Copy link

codecov bot commented Nov 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.57%. Comparing base (0e490b7) to head (5016780).
Report is 15 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #16140   +/-   ##
=======================================
  Coverage   98.57%   98.57%           
=======================================
  Files         164      164           
  Lines       21345    21345           
=======================================
+ Hits        21040    21041    +1     
+ Misses        305      304    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jepler jepler force-pushed the fix-json-difference-test branch from 7226a7b to fc729b9 Compare November 3, 2024 13:00
x = json.loads(z)
print("Should not get here")
z = json.dumps(json)
print("Produced non-conforming json string", repr(z))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the original test was testing that bytes are not serialisable, which would be more of a subtle difference between CPython and MicroPython than trying to serialise a module.

Suggest to simply do:

try:
    print(json.dumps(b"shouldn't be able to serialise this")
except TypeError:
    print("TypeError")

@dpgeorge dpgeorge added the tests Relates to tests/ directory in source label Nov 4, 2024
@jepler
Copy link
Contributor Author

jepler commented Nov 7, 2024

In documentation, the existing test gives a UnicodeError. That's why I decided to try a whole different kind of object.
image

I'll change the test case as you suggest.

The test case was producing the following error:
```
Traceback (most recent call last):
  File "<stdin>", line 12, in <module>
UnicodeError:
```
which did not demonstrate the intended difference. (this particular
non-json-serializable object DID throw an exception! just not TypeError)

The updated test uses a byte string with all ASCII bytes inside,
which better illustrates the diference.

Signed-off-by: Jeff Epler <jepler@gmail.com>
@jepler jepler force-pushed the fix-json-difference-test branch from fc729b9 to 5016780 Compare November 7, 2024 16:43
@jepler
Copy link
Contributor Author

jepler commented Nov 7, 2024

Updated...

@jepler
Copy link
Contributor Author

jepler commented Nov 7, 2024

There are CI errors but they appear unrelated to this change.

1 tests failed: time_time_ns
1 tests failed: thread_lock4
-- /home/runner/work/micropython/micropython/tests/results/thread_thread_lock4.py.exp	2024-11-07 16:44:53.393277488 +0000
+++ /home/runner/work/micropython/micropython/tests/results/thread_thread_lock4.py.out	2024-11-07 16:44:53.393277488 +0000
@@ -58,3 +58,4 @@
 77 145183092028285869634070784086308284983740379224208358846781574688061991349156420080065207861248000000000000000000
 78 11324281178206297831457521158732046228731749579488251990048962825668835325234200766245086213177344000000000000000000
 79 894618213078297528685144171539831652069808216779571907213868063227837990693501860533361810841010176000000000000000000
+CRASH
\ No newline at end of file

FAILURE /home/runner/work/micropython/micropython/tests/results/thread_thread_lock4.py
--- /home/runner/work/micropython/micropython/tests/results/extmod_time_time_ns.py.exp	2024-11-07 16:44:35.601734727 +0000
+++ /home/runner/work/micropython/micropython/tests/results/extmod_time_time_ns.py.out	2024-11-07 16:44:35.601734727 +0000
@@ -4,7 +4,7 @@
 True
 True
 True
-True
+False
 True
 True
 True

FAILURE /home/runner/work/micropython/micropython/tests/results/extmod_time_time_ns.py

@dpgeorge
Copy link
Member

I reran the failing CI and now it passes.

@dpgeorge
Copy link
Member

Rebased and merged in 3844733

@dpgeorge dpgeorge closed this Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests Relates to tests/ directory in source

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants