Beispiel #1
0
def test_kaldi_weight_passthrough():
    Breathe.add_commands(
        None,
        {
            "test weight": DoNothing(),
        },
        weight=10.0,
    )
    assert Breathe.core_commands[-1].weight == 10.0
def test_manual_context():
    Breathe.add_commands(CommandContext("test"), {
        "pizza": DoNothing(),
        "curry": DoNothing(),
    })
    # Fails because the rule isn't enabled yet
    with pytest.raises(MimicFailure):
        engine.mimic(["pizza", "pizza"])
    engine.mimic(["enable", "test"])
    engine.mimic(["pizza", "curry", "pizza"])
Beispiel #3
0
def test_context_commands():
    Breathe.add_commands(
        AppContext("notepad"),
        {"test [<num>]": lambda num: DoNothing().execute()},
        [Choice("num", {"four": "4", "five": "5", "six": "6"})],
        {"num": ""},
    )
    with pytest.raises(MimicFailure):
        engine.mimic(["test", "three", "test", "four"])
    engine.mimic(["test", "three", "test", "four"], executable="notepad")
Beispiel #4
0
def test_invalid():
    Breathe.add_commands(
        AppContext("code.exe"),
        {
            "test that <nonexistent_extra>": DoNothing(),
            1: DoNothing(),
        },
    )
    assert len(Breathe.contexts) == 1
    assert len(Breathe.context_commands) == 1
def test_negated_context():
    Breathe.add_commands(~(CommandContext("america") | AppContext("england")),
                         {
                             "steak": DoNothing(),
                         })
    engine.mimic(["steak"])
    with pytest.raises(MimicFailure):
        engine.mimic(["steak"], executable="england")
    engine.mimic(["enable", "america"])
    with pytest.raises(MimicFailure):
        engine.mimic(["steak"])
Beispiel #6
0
class Service(Daemon):
    def __init__(self):
        self.cls = super().__init__()
        self.breathe = Breathe()

    def run(self):
        self.breathe.start()

    def shutdown(self):
        self.breathe.stop()
        self.cls.stop()
Beispiel #7
0
def test_noccr_commands():
    Breathe.add_commands(
        AppContext("firefox"),
        {"dictation <text>": DoNothing(), "testing static": DoNothing()},
        ccr=False,
    )
    engine.mimic(["testing", "static"], executable="firefox")
    with pytest.raises(MimicFailure):
        engine.mimic(["dictation", "TESTING"])
        engine.mimic(["testing", "static", "testing", "static"], executable="firefox")
    engine.mimic(["dictation", "TESTING"], executable="firefox")
Beispiel #8
0
def test_global_top_level():
    Breathe.add_commands(
        None,
        {
            "<sequence1> are preferable to <sequence2>": DoNothing()
            + Exec("sequence1")
            + DoNothing()
            + Exec("sequence2")
        },
        extras=[CommandsRef("sequence1"), CommandsRef("sequence2", 3)],
        top_level=True,
    )
Beispiel #9
0
def test_core_commands():
    Breathe.add_commands(
        None,
        {
            "test one": DoNothing(),
            "test two": DoNothing(),
            "test three": DoNothing(),
            "banana [<n>]": DoNothing() * Repeat("n"),
        },
        [IntegerRef("n", 1, 10, 1)],
    )
    engine.mimic(["test", "three", "test", "two", "banana", "five"])
Beispiel #10
0
def test_top_level_command_failure():
    Breathe.add_commands(
        AppContext("china"),
        {
            "not marked top level <sequence1> and <sequence2> [<n>]": DoNothing()
            + Exec("sequence1")
            + DoNothing()
            + Exec("sequence2")* Repeat("n")
        },
        extras=[CommandsRef("sequence1"), CommandsRef("sequence2", 2), IntegerRef("n", 1, 10, 1)],
        top_level=False,
    )
    assert len(Breathe.top_level_commands) == 2
def test_manual_context_noccr():
    Breathe.add_commands(CommandContext("test") | AppContext("italy"),
                         {"spaghetti": DoNothing()},
                         ccr=False)
    # Loaded rule should be referencing the original
    # "test" context loaded above, which should already be
    # active
    engine.mimic(["spaghetti"])
    engine.mimic(["disable", "test"])
    with pytest.raises(MimicFailure):
        engine.mimic(["spaghetti"])
        engine.mimic(["pizza", "curry"])
    engine.mimic(["spaghetti"], executable="italy")
Beispiel #12
0
def test_loading_failure():
    with open(file_path, "w") as f:
        f.write("""
from breathe import Breathe
from ..testutils import DoNothing

Breathe.add_commands(,,,
    None,
    {
        "apple": DoNothing(),
    }
)
""")
    modules = {
        "tests": {
            "my_grammar": ["fruit"],
        }
    }
    Breathe.load_modules(modules)
    assert len(Breathe.modules) == 1
    assert len(Breathe.core_commands) == 0
Beispiel #13
0
def test_global_extras():
    Breathe.add_global_extras(Dictation("text"))
    assert len(Breathe.global_extras) == 1
    assert "text" in Breathe.global_extras
    Breathe.add_global_extras([Choice("abc", {"def": "ghi"})])
    # Check that this is overridden
    Breathe.add_global_extras(IntegerRef("n", 1, 2, 1))
Beispiel #14
0
def test_loading():
    with open(file_path, "w") as f:
        f.write("""
from breathe import Breathe
from ..testutils import DoNothing

Breathe.add_commands(
    None,
    {
        "apple": DoNothing(),
    }
)
""")
    engine.mimic("rebuild everything test")
    engine.mimic("apple")
Beispiel #15
0
def test_reloading():
    with open(file_path, "w") as f:
        f.write("""
from breathe import Breathe
from ..testutils import DoNothing

Breathe.add_commands(
    None,
    {
        "parsnip": DoNothing(),
    }
)
""")
    # I have no idea why this is necessary, it's a total hack
    if PY2:
        os.remove(file_path + "c")
    engine.mimic("rebuild everything test")
    with pytest.raises(MimicFailure):
        engine.mimic("apple")
    engine.mimic("parsnip")
    assert len(Breathe.modules) == 1
Beispiel #16
0
def test_top_level_command():
    Breathe.add_commands(None, {"orange": DoNothing(), "grapefruit": DoNothing()})
    Breathe.add_commands(
        AppContext("notepad"), {"lemon": DoNothing(), "banana": DoNothing()}
    )
    Breathe.add_commands(
        AppContext("notepad"),
        {
            "fruit from <sequence1> and [<sequence2>] [<n>]": DoNothing()
            + Exec("sequence1")
            + DoNothing()
            + Exec("sequence2")* Repeat("n")
        },
        extras=[CommandsRef("sequence1"), CommandsRef("sequence2", 2), IntegerRef("n", 1, 10, 1)],
        top_level=True,
    )
Beispiel #17
0
    def loop(self, interval: int = 60):
        from breathe import Breathe
        sleep_indicator = Breathe()
        while True:
            pycom.rgbled(0x001100)
            data = self.prepare_data()

            print(json.dumps(data))
            # send data to Cumulocity
            try:
                print("** sending measurements ...")
                self.c8y.measurement(data)
            except Exception as e:
                pycom.rgbled(0x110000)
                print("!! error sending data to backend: " + repr(e))
                time.sleep(2)
            else:
                pycom.rgbled(0x001100)

            # send data certificate (UPP) to UBIRCH
            try:
                print("** sending measurement certificate ...")
                (response, r) = self.ubirch.send(data)
            except Exception as e:
                pycom.rgbled(0x440000)
                print("!! response: verification failed: {}".format(e))
                time.sleep(2)
            else:
                if r.status_code != 202:
                    pycom.rgbled(0x550000)
                    print("!! request failed with {}: {}".format(
                        r.status_code, r.content.decode()))
                    time.sleep(2)
                else:
                    print(response)
                    if isinstance(response, dict):
                        interval = response.get("i", interval)

            # everything okay
            pycom.rgbled(0x004400)
            print("** done")

            sleep_indicator.start()
            time.sleep(interval)
            sleep_indicator.stop()
Beispiel #18
0
from breathe import Breathe

breathe = Breathe()
breathe.start()
Beispiel #19
0
        lambda: math_commands.clear())


def end_math():
    math_commands.clear()


context = CommandContext("latex")
Breathe.add_commands(
    context=AppContext(title='.tex') | context,
    mapping={
        'new paragraph': Text('\n\n'),
        'emphasize <latex>': Text(r'\emph{}%(latex)s}\n'),
        'inline math': Text('$') + Function(start_inline),
        'begin align': Text('\\begin{align}\n') + Function(start_align),
        'begin math': Function(start_math),
        # 'stop math': Function(end_math),
        "<math_command>": Function(process_math_command),
    },
    extras=[
        DictListRef('math_command', math_commands),
        Dictation("latex", default="").lower().replace(" new paragraph ",
                                                       "\n\n"),
    ])

# fraction sin x ^2squared divided by 3 + x
#  \frac{\sin(x^2)}{3+x}
# Breathe.add_commands(
#     context=context,
#     mapping={
#        "<expr1> frac <expr2> over <expr3>":
#             Exec("expr1") + Text("\\frac{") + Exec("expr2") + Text("}{") + Exec("expr3") + Text("}"),
Beispiel #20
0
Breathe.add_commands(
    # Commands will be active either when we are editing a python file
    # or after we say "enable python". pass None for the commands to be global.
    # context = AppContext(title=".py") | CommandContext("python"),
    context=AppContext(executable='terminal')
    | AppContext(executable='konsole') | context,
    mapping={
        'window new':
        Key('cs-n'),
        'git diff':
        Text('git diff\n'),
        'git pull':
        Text('git pull\n'),
        'git log':
        Text('git log --graph\n'),
        'git push':
        Text('git push\n'),
        'git status':
        Text('git status\n'),
        'git add':
        Text('git add '),
        'git commit minus a m <text>':
        Text('git commit -am "%(text)s"') + Key('left'),
        'git commit minus m <text>':
        Text('git commit -m "%(text)s"') + Key('left'),
        'git <text>':
        Function(lambda text: notify('unrecognized git command:', str(text))),
        'cargo build':
        Text('cargo build\n'),
        'cargo build release':
        Text('cargo build --release\n'),
        'cargo test':
        Text('cargo test\n'),
        'cargo check':
        Text('cargo check\n'),
        'cargo bench':
        Text('cargo bench\n'),
        'cargo outdated':
        Text('cargo outdated -R\n'),
        'cargo tarpaulin':
        Text('cargo tarpaulin\n'),
        'r q':
        Text('rq\n'),
        'r q run':
        Text('rq run '),
        'r q cancel all':
        Text('rq cancel --all\n'),
        'codium here':
        Text('code -n --folder-uri `pwd` &\n'),
        'cd':
        Text('cd '),
        'control c':
        Key('c-c'),
        'complete me':
        Key('tab'),
        'repeat last command':
        Key('up') + Key('enter'),
    },
    extras=[
        IntegerRef("n", 1, 20, default=1),
        Dictation("text", default=""),
    ])
Beispiel #21
0
from dragonfly import Dictation, AppContext, Text, Key, IntegerRef
from breathe import Breathe, CommandContext

context = CommandContext("atom")

Breathe.add_commands(
    # Commands will be active either when we are editing a python file
    # or after we say "enable python". pass None for the commands to be global.
    # context = AppContext(title=".py") | CommandContext("python"),
    context=context,
    mapping={
        '<n> move up': Key('up:%(n)d'),
        '<n> move down': Key('down:%(n)d'),
        'edit undo': Key('c-z'),
        'edit redo': Key('cs-z'),
        '[<n>] edit indent': Key('c-]:%(n)d'),
        '[<n>] edit out dent': Key('c-[:%(n)d'),
        '[<n>] tab right': Key('c-pgdown:%(n)d'),
        '[<n>] tab left': Key('c-pgup:%(n)d'),
        'file save': Key('c-s'),
        'file open': Key('c-o'),
        'edit cut': Key('c-x'),
        'edit copy': Key('c-c'),
        'edit paste': Key('c-v'),
    },
    extras=[
        IntegerRef("n", 1, 20, default=1),
    ])
Beispiel #22
0
    'pass',
    'return',
]
functions = ['range', 'print']

mapping = {
    'colon': Text(':\n'),
    'comma': Text(', '),
    # '(ell if|else if)': Text('elif '),
    "snake case [<snaketext>]": Text("%(snaketext)s"),
    "screaming snake case [<screamingsnaketext>]":
    Text("%(screamingsnaketext)s"),
    "Camel Case [<CamelText>]": Text("%(CamelText)s"),
}
for k in keywords:
    mapping[k] = Text(k + ' ')
for k in functions:
    mapping[k] = Text(k + '()') + Key('left')

Breathe.add_commands(
    # Commands will be active either when we are editing a python file
    # or after we say "enable python". pass None for the commands to be global.
    # context = AppContext(title=".py") | CommandContext("python"),
    context=AppContext(title='.py') | context,
    mapping=mapping,
    extras=[
        Dictation("snaketext", default="").lower().replace(" ", "_"),
        Dictation("screamingsnaketext", default="").upper().replace(" ", "_"),
        Dictation("CamelText", default="").title().replace(" ", ""),
    ])
Beispiel #23
0
def test_clear():
    Breathe.clear()
    Breathe.modules = []
Beispiel #24
0
def test_nomapping_commands():
    Breathe.add_commands(AppContext("code.exe"), {})
Beispiel #25
0
from breathe import Breathe, CommandContext

context = CommandContext("chrome")

Breathe.add_commands(
    # Commands will be active either when we are editing a python file
    # or after we say "enable python". pass None for the commands to be global.
    # context = AppContext(title=".py") | CommandContext("python"),
    context=AppContext('chrome') | context,
    mapping={
        'page back': Key('a-left'),
        'page forward': Key('a-right'),
        'page reload': Key('cs-r'),
        'search for <text>': Key('a-d/20') + Text('%(text)s'),
        'edit cut': Key('c-x'),
        'edit copy': Key('c-c'),
        'edit paste': Key('c-v'),
        'edit undo': Key('c-z'),
        'tab new': Key('c-t'),
        'tab close': Key('c-w'),
        '[<n>] link next': Key('tab:%(n)d'),
        '[<n>] link previous': Key('s-tab:%(n)d'),
        'link follow': Key('enter'),
        '[<n>] tab right': Key('c-pgdown:%(n)d'),
        '[<n>] tab left': Key('c-pgup:%(n)d'),
    },
    extras=[
        IntegerRef("n", 1, 20, default=1),
        Dictation("text", default=""),
    ])
Beispiel #26
0
def test_clear():
    Breathe.clear()
from dragonfly import Dictation, AppContext, Text, Key, IntegerRef
from breathe import Breathe, CommandContext

context = CommandContext("firefox")

Breathe.add_commands(
    # Commands will be active either when we are editing a python file
    # or after we say "enable python". pass None for the commands to be global.
    # context = AppContext(title=".py") | CommandContext("python"),
    context=context,
    mapping={
        'page back': Key('a-left'),
        'page forward': Key('a-right'),
        'page reload': Key('c-r'),
        '[<n>] link next': Key('tab:%(n)d'),
        '[<n>] link previous': Key('s-tab:%(n)d'),
        'link follow': Key('enter'),
        '[<n>] tab right': Key('c-pgdown:%(n)d'),
        '[<n>] tab left': Key('c-pgup:%(n)d'),
        'tab new': Key('c-t'),
    },
    extras=[
        IntegerRef("n", 1, 20, default=1),
        Dictation("text", default=""),
    ])
Beispiel #28
0
    for c in commands:
        Key(c).execute()

Breathe.add_commands(
    # Commands will be active either when we are editing a python file
    # or after we say "enable python". pass None for the commands to be global.
    # context = AppContext(title=".py") | CommandContext("python"),
    context = AppContext(title='Gmail') | AppContext(title='Mail -') | context,
    mapping = {
        'message <commands>': Function(do_commands),
        '[<n>] message next': Key('j:%(n)d'),
        '[<n>] message previous': Key('k:%(n)d'),
    },
    extras = [
        Repetition(Choice('message', {
            'select': 'x',
            'next': 'j',
            'previous': 'k',
            'archive': 'e',
            'delete': '#',
            'reply': 'r',
            'reply all': 'a',
            'send': 'c-enter',
            'view': 'enter',
            'compose': 'c',
        }), name='commands', max=20),
        IntegerRef("n", 1, 20, default=1),
        Dictation("text", default=""),
    ]
)
Beispiel #29
0
from dragonfly import Dictation, AppContext, Text, Key, IntegerRef
from breathe import Breathe, CommandContext

context = CommandContext("emacs")

Breathe.add_commands(
    # Commands will be active either when we are editing a python file
    # or after we say "enable python". pass None for the commands to be global.
    # context = AppContext(title=".py") | CommandContext("python"),
    context=context,
    mapping={
        'edit undo': Key('cs-_'),
        '[<n>] edit indent': Key('tab:%(n)d'),
        'edit cut': Key('c-w'),
        'edit copy': Key('a-w'),
        'edit paste': Key('c-y'),
    },
    extras=[
        IntegerRef("n", 1, 20, default=1),
    ])
Beispiel #30
0
def test_top_level_command2():
    Breathe.add_commands(
        AppContext(title="chrome"), {"pear": DoNothing(), "grape": DoNothing()}
    )