Skip to content

Commit

Permalink
Refine README
Browse files Browse the repository at this point in the history
  • Loading branch information
nizox committed Mar 26, 2021
1 parent 82ef1f6 commit 23136cd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
24 changes: 10 additions & 14 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Python Mini Racer
.. image:: https://dev.azure.com/sqreenci/PyMiniRacer/_apis/build/status/sqreen.PyMiniRacer?branchName=master
:target: https://dev.azure.com/sqreenci/PyMiniRacer/_build/latest?definitionId=10&branchName=master

Minimal, modern embedded V8 for Python.
Minimal, modern embedded V8 for Python based on ctypes.

* Free software: ISC license

Expand All @@ -17,19 +17,19 @@ Minimal, modern embedded V8 for Python.
Features
--------

* WASM support
* Latest ECMAScript support
* Web Assembly support
* Unicode support
* Thread safe
* Re-usable contexts
* Binary object is Python agnostic

PyMiniRacer can be easily used by Django or Flask projects to minify assets, run
MiniRacer can be easily used by Django or Flask projects to minify assets, run
babel or WASM modules.

Examples
--------

PyMiniRacer is straightforward to use:
MiniRacer is straightforward to use:

.. code-block:: python
Expand All @@ -51,8 +51,8 @@ Variables are kept inside of a context:
'Sqreen'
While `ctx.eval` only supports returning primitive data types such as
strings, `ctx.call` supports returning composite types such as objects:
While ``eval`` only supports returning primitive data types such as
strings, ``call`` supports returning composite types such as objects:

.. code-block:: python
Expand Down Expand Up @@ -85,7 +85,7 @@ Use a custom JSON encoder when sending non-JSON encodable parameters:
'2017-03-31T16:51:02.474118'
PyMiniRacer is ES6 capable:
MiniRacer is ES6 capable:

.. code-block:: python
Expand Down Expand Up @@ -209,10 +209,6 @@ PyMiniRacer is inspired by mini_racer_, built for the Ruby world by Sam Saffron.

.. _`mini_racer`: https://github.com/SamSaffron/mini_racer

Tools used in rendering this package:
`Cookiecutter-pypackage`_ was used as this package skeleton.

* Cookiecutter_
* `cookiecutter-pypackage`_

.. _Cookiecutter: https://github.com/audreyr/cookiecutter
.. _`cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage
.. _`Cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage
9 changes: 9 additions & 0 deletions tests/test_wasm.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,40 @@


class WASMTest(unittest.TestCase):
"""
Test executing a WASM module.
"""

def setUp(self):
self.mr = MiniRacer()

def test_add(self):
fn = os.path.join(test_dir, "add.wasm")

# 1. Allocate a buffer to hold the WASM module code
size = os.path.getsize(fn)
moduleRaw = self.mr.eval("""
const moduleRaw = new SharedArrayBuffer({});
moduleRaw
""".format(size))

# 2. Read the WASM module code
with open(fn, "rb") as f:
self.assertEqual(f.readinto(moduleRaw), size)

# 3. Instantiate the WASM module
self.mr.eval("""
var res = null;
WebAssembly.instantiate(new Uint8Array(moduleRaw)).then(result => {
res = result.instance;
}).catch(result => { res = result.message; });
""")

# 4. Wait for WASM module instantiation
while not self.mr.eval("res"):
pass

self.assertTrue(self.mr.eval("typeof res !== 'string'"))

# 5. Execute a WASM function
self.assertEqual(self.mr.eval("res.exports.addTwo(1, 2)"), 3)

0 comments on commit 23136cd

Please sign in to comment.