Skip to content

Commit

Permalink
unix/variants/coverage: Add test for manifest freeze_mpy().
Browse files Browse the repository at this point in the history
This uses the frozentest.mpy that is also used by ports/minimal.

Also fixes two bugs that these new tests picked up:
 - File extension matching in manifestfile.py.
 - Handling of freeze_mpy results in makemanifest.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
  • Loading branch information
jimmo authored and dpgeorge committed Sep 19, 2022
1 parent 6ecdf1a commit 920da9c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 7 deletions.
1 change: 1 addition & 0 deletions ports/unix/variants/coverage/manifest.py
@@ -1,2 +1,3 @@
freeze_as_str("frzstr")
freeze_as_mpy("frzmpy")
freeze_mpy("$(MPY_DIR)/tests/frozen")
5 changes: 5 additions & 0 deletions tests/unix/extra_coverage.py
Expand Up @@ -96,3 +96,8 @@
from frzqstr import returns_NULL

print(returns_NULL())

# test for freeze_mpy
import frozentest

print(frozentest.__file__)
10 changes: 10 additions & 0 deletions tests/unix/extra_coverage.py.exp
Expand Up @@ -199,3 +199,13 @@ X
'\x1b'
b'\x00\xff'
NULL
uPy
a long string that is not interned
a string that has unicode αβγ chars
b'bytes 1234\x01'
123456789
0
1
2
3
frozentest.py
6 changes: 3 additions & 3 deletions tools/makemanifest.py
Expand Up @@ -210,9 +210,9 @@ def main():
ts_outfile = get_timestamp(outfile)
mpy_files.append(outfile)
else:
assert kind == manifestfile.KIND_FREEZE_MPY
mpy_files.append(full_path)
ts_outfile = timestamp
assert result.kind == manifestfile.KIND_FREEZE_MPY
mpy_files.append(result.full_path)
ts_outfile = result.timestamp
ts_newest = max(ts_newest, ts_outfile)

# Check if output file needs generating
Expand Down
17 changes: 13 additions & 4 deletions tools/manifestfile.py
Expand Up @@ -394,28 +394,37 @@ def freeze(self, path, script=None, opt=None):
`opt` is the optimisation level to pass to mpy-cross when compiling .py
to .mpy.
"""
self._freeze_internal(path, script, exts=(".py", ".mpy"), kind=KIND_FREEZE_AUTO, opt=opt)
self._freeze_internal(
path,
script,
exts=(
".py",
".mpy",
),
kind=KIND_FREEZE_AUTO,
opt=opt,
)

def freeze_as_str(self, path):
"""
Freeze the given `path` and all .py scripts within it as a string,
which will be compiled upon import.
"""
self._search(path, None, None, exts=(".py"), kind=KIND_FREEZE_AS_STR)
self._search(path, None, None, exts=(".py",), kind=KIND_FREEZE_AS_STR)

def freeze_as_mpy(self, path, script=None, opt=None):
"""
Freeze the input (see above) by first compiling the .py scripts to
.mpy files, then freezing the resulting .mpy files.
"""
self._freeze_internal(path, script, exts=(".py"), kind=KIND_FREEZE_AS_MPY, opt=opt)
self._freeze_internal(path, script, exts=(".py",), kind=KIND_FREEZE_AS_MPY, opt=opt)

def freeze_mpy(self, path, script=None, opt=None):
"""
Freeze the input (see above), which must be .mpy files that are
frozen directly.
"""
self._freeze_internal(path, script, exts=(".mpy"), kind=KIND_FREEZE_MPY, opt=opt)
self._freeze_internal(path, script, exts=(".mpy",), kind=KIND_FREEZE_MPY, opt=opt)


# Generate a temporary file with a line appended to the end that adds __version__.
Expand Down

0 comments on commit 920da9c

Please sign in to comment.