This directory contains tests for calling Mojo from Python.
The tests can be run using Bazel:
bazel test //oss/modular/mojo/integration-test:litThe tests typically have the following structure:
<name>
├── main.py
└── mojo_module.mojo
where main.py is the test entrypoint, which compiles and loads
mojo_module.mojo as a
Python extension module.
mojo_module.mojo should contain Mojo code written to be called from Python,
and main.py should test that exposed Mojo code.
-
./basic-raw — a minimal low-level smoke test, calling a simple Mojo function from Python. Uses the low-level "raw" function bindings, which are more error prone.
-
./feature-overview — This test aims to include a basic test for each supported Mojo language feature that is usable across the Python <=> Mojo interop boundary.
Python extension modules are just dynamic libraries that expose a suitable
PyInit_<module_name>() function. To build a Mojo library into an extension
module, you can use the following command:
mojo build mojo_module.mojo --emit shared-lib -o mojo_module.soWhich will result in a mojo_module.so being built and placed alongside the
existing files:
<name>
├── mojo_module.mojo
├── mojo_module.so
└── main.py
Running the Python main.py code will load and run compiled Mojo code
from mojo_module.so:
% python main.py
Result from Mojo 🔥: 2