-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic test runner for py.test. Compiles Mochi files to Python bytecode.
- Loading branch information
Showing
5 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
"""Import a Python object made by compiling a Mochi file. | ||
""" | ||
|
||
import os | ||
|
||
from mochi.core import pyc_compile_monkeypatch | ||
|
||
|
||
def get_function(name, file_path): | ||
"""Python function from Mochi. | ||
Compiles a Mochi file to Python bytecode and returns the | ||
imported function. | ||
""" | ||
base_path = os.path.dirname(file_path) | ||
mochi_name = os.path.join(base_path, name + '.mochi') | ||
py_name = os.path.join(base_path, name + '_comp.pyc') | ||
pyc_compile_monkeypatch(mochi_name, py_name) | ||
return getattr(__import__(name), name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
"""Using `invoke` to start tests and and other commandline tools. | ||
""" | ||
|
||
from invoke import run, task | ||
|
||
|
||
@task | ||
def test(): | ||
"""Run standard tests. | ||
Usage (commandline): inv test | ||
""" | ||
run('py.test --assert=reinterp', pty=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
def factorial: | ||
n: factorial(n, 1) | ||
0, acc: acc | ||
n, acc: factorial(n - 1, acc * n) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import os | ||
|
||
from mochi.utils.pycloader import get_function | ||
|
||
factorial = get_function('factorial', __file__) | ||
|
||
def test_factorial_1(): | ||
assert factorial(1) == 1 | ||
|
||
def test_factorial_2(): | ||
assert factorial(2) == 2 | ||
|
||
|
||
|