Skip to content

Commit

Permalink
Basic test runner for py.test. Compiles Mochi files to Python bytecode.
Browse files Browse the repository at this point in the history
  • Loading branch information
pya committed Apr 15, 2015
1 parent d065412 commit 8e47cbc
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 0 deletions.
Empty file added mochi/utils/__init__.py
Empty file.
19 changes: 19 additions & 0 deletions mochi/utils/pycloader.py
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)
14 changes: 14 additions & 0 deletions tasks.py
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)
4 changes: 4 additions & 0 deletions tests/factorial.mochi
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)
14 changes: 14 additions & 0 deletions tests/test_patternmatching.py
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



0 comments on commit 8e47cbc

Please sign in to comment.