Esempio n. 1
0
    def test_help_command_should_print_provided_help(self):
        # given
        test_help = "Some test help"
        routines = Helper.with_help(create_routines(
            Routine("thing", lambda x: print(x), help=test_help)
        ))

        # when
        self.run_until_not_callable(routines["help"].subroutines["thing"].body())
        result = self.new_stdout.getvalue().strip().split("\n")

        # then
        self.assertIn(test_help, result)
Esempio n. 2
0
    def test_help_should_list_all_commands_with(self):
        # given
        routines = create_routines(
            Routine("thing", lambda x: print(x)),
            Routine("test", lambda x: print(x))
        )

        # when
        helped_routines = Helper.with_help(routines)

        # then
        self.assertIn("help", helped_routines.keys())

        # when
        self.run_until_not_callable(helped_routines["help"].body)
        result = self.new_stdout.getvalue().strip().split("\n")

        # then
        assert "thing" in result
        assert "test" in result
Esempio n. 3
0
    def test_help_command_should_print_help_from_method_comments(self):
        # given
        test_help = "Some test help"

        def some_method(*args):
            """
            Some test help
            :param args:
            :return:
            """
            print(*args)
            return
        routines = Helper.with_help(create_routines(
            Routine("test_method", some_method)
        ))

        # when
        self.run_until_not_callable(routines["help"].subroutines["test_method"].body())
        result = self.new_stdout.getvalue().strip()

        # then
        self.assertIn(test_help, result)
Esempio n. 4
0

def print_open(*args):
    p("open", args)


def print_shutdown(*args):
    p("shutdown", args)


routines = create_routines(
    Routine(
        "computer", print_computer,
        create_routines(Routine("start", print_start),
                        Routine("open", print_open),
                        Routine("shutdown", print_shutdown))),
    Routine(
        "laptop", print_laptop,
        create_routines(Routine("start", print_start),
                        Routine("open", print_open),
                        Routine("shutdown", print_shutdown))))

invoke_tests = [
    ([
        routines["computer"].body,
        routines["computer"].subroutines["start"].body
    ], ["computer ()", "start ()"]),
    ([
        routines["computer"].body, "Macbook",
        routines["computer"].subroutines["start"].body
    ], ["computer ('Macbook',)", "start ()"]),
Esempio n. 5
0
import unittest
from moxom.compiler.astparser import FunctionNode, AtomNode, BinaryNode, DeclarationNode, OperatorToken, IdentifierToken
from moxom.compiler.interpreter import Interpreter, RuntimeScope, Routine, Then, And
from moxom.runtime_context import create_routines
from typing import List


routines=create_routines(
    Routine("computer", lambda: print("computer"), create_routines(
        Routine("start", lambda: print("start")),
        Routine("open", lambda: print("open")),
        Routine("shutdown", lambda: print("shutdown"))
    )),
    Routine("laptop", lambda: print("laptop"), create_routines(
        Routine("start", lambda: print("start")),
        Routine("open", lambda: print("open")),
        Routine("shutdown", lambda: print("shutdown"))
    ))
)


invoke_tests = (
    (
        FunctionNode(
            IdentifierToken(value='computer'),
            chain=FunctionNode(IdentifierToken(value='start'))
        ),
        [routines["computer"].body,
         routines["computer"].subroutines["start"].body]
    ),
    (