Пример #1
0
def test_load_by_environ():
    with path(Path(__file__).parent / 'dummy'):
        with environ_langs('langs'):
            # before load, does not work
            with pytest.raises(KeyError):
                by_name('compiledlang')

            # after load, does work
            load_from_environ()
            assert by_name('compiledlang').compiler.cmd.endswith('/echo')
            assert by_name('interpretedlang').interpreter.cmd.endswith('/echo')
Пример #2
0
def test_loader_multiple_modules(tmpdir):
    with pytest.raises(KeyError):
        assert by_name('lang1')
    with pytest.raises(KeyError):
        assert by_name('lang2')

    # create lang1 and lang2
    tmpdir.ensure('lang1.py').write(custom_lang('Lang1'))
    tmpdir.ensure('lang2.py').write(custom_lang('Lang2'))

    found_langs = loader.load_modules(['lang1', 'lang2'], str(tmpdir))
    assert found_langs == {by_name('lang1'), by_name('lang2')}
Пример #3
0
def test_load_by_environ_runtime_error(caplog):
    with caplog.at_level(logging.ERROR):
        with path(Path(__file__).parent / 'dummy'):
            with environ_langs('error'):
                load_from_environ()

        log = ''.join(r.msg + getattr(r, 'exc_text', '')
                      for r in caplog.records)
        assert 'could not load' in log
        assert 'ZeroDivisionError' in log

    with pytest.raises(KeyError):
        by_name('compiledlang')
Пример #4
0
def test_loader_sub_module(tmpdir):
    with pytest.raises(KeyError):
        by_name('otherlang')

    # create tux/bar/baz.py
    file = tmpdir.mkdir('tux').mkdir('bar').ensure('baz.py')
    file.write(custom_lang('OtherLang'))

    # wrong import path
    with pytest.raises(ModuleNotFoundError):
        loader.load_modules(['tux.bar.baz'], '')

    # good import path
    found_langs = loader.load_modules(['tux.bar.baz'], str(tmpdir))
    lang = by_name('otherlang')
    assert found_langs == {lang}
    assert lang.__name__ == 'OtherLang'
Пример #5
0
def test_loader_root_module(tmpdir):
    with pytest.raises(KeyError):
        by_name('mylang')

    # create foo.py
    file = tmpdir.ensure('foo.py')
    file.write(custom_lang('MyLang'))

    # wrong import path
    with pytest.raises(ModuleNotFoundError):
        loader.load_modules(['foo'], '')

    # good import path
    found_langs = loader.load_modules(['foo'], str(tmpdir))
    lang = by_name('mylang')
    assert found_langs == {lang}
    assert lang.__name__ == 'MyLang'
Пример #6
0
def list_paths():
    for lang in all():
        cls = by_name(lang)
        if cls in OVERWRITE:
            for path in OVERWRITE[cls]:
                yield cls, path
            continue
        for p in cls.required_binaries():
            yield cls, p.cmd
def test_overwrite_warning():
    class FooLang(Lang):
        pass

    assert by_name('foolang') is FooLang
    assert by_name('foolang').name == 'FooLang'

    with pytest.warns(UserWarning) as record:

        class BarLang(Lang, name='Foolang'):
            pass

        assert len(record) == 1
        message = str(record[0].message)
        assert "foolang" in message
        assert FooLang.__name__ in message
        assert "overwrites" in message
        assert BarLang.__name__ in message

    assert by_name('foolang') is BarLang
    assert by_name('foolang').name == 'Foolang'
Пример #8
0
def list_paths():
    for lang in all():
        cls = by_name(lang)
        if cls in OVERWRITE:
            for path in OVERWRITE[cls]:
                yield cls, path
            continue
        if cls.compiler:
            yield cls, cls.compiler
        if cls.interpreter:
            yield cls, cls.interpreter
        yield from cls.extra_binaries
Пример #9
0
 class BadCompLang(by_name('c')):
     reference_source = 'wtf bbq'
Пример #10
0
 class BadInterLang(by_name('python')):
     reference_source = 'print(43)'
def test_default_name():
    class MyFoo(Lang):
        pass

    assert by_name('myfoo') is MyFoo
    assert by_name('myfoo').name == MyFoo.__name__
def test_user_name():
    class MyFoo(Lang, name='Chiche'):
        pass

    assert by_name('chiche') is MyFoo
    assert by_name('chiche').name == 'Chiche'
Пример #13
0
from collections import defaultdict
import subprocess
import sys

from camisole.languages import all, by_name, _import_builtins
_import_builtins()

FROM_AUR = {'esotope-bfc-git': {by_name('brainfuck')},}

# java packages consist of symlinks to handle both Java 7 & 8, so we force
# the version (8) here
OVERWRITE = {by_name('java'): {'/usr/lib/jvm/java-8-openjdk/bin/java',
                               '/usr/lib/jvm/java-8-openjdk/bin/javac'}}


def list_paths():
    for lang in all():
        cls = by_name(lang)
        if cls in OVERWRITE:
            for path in OVERWRITE[cls]:
                yield cls, path
            continue
        if cls.compiler:
            yield cls, cls.compiler
        if cls.interpreter:
            yield cls, cls.interpreter
        yield from cls.extra_binaries


def get_package(binary):
    try:
Пример #14
0
from collections import defaultdict
import subprocess
import sys

from camisole.languages import all, by_name, _import_builtins

_import_builtins()

FROM_AUR = {
    'esotope-bfc-git': {by_name('brainfuck')},
}

# java packages consist of symlinks to handle both Java 7 & 8, so we force
# the version (8) here
OVERWRITE = {
    by_name('java'): {
        '/usr/lib/jvm/java-8-openjdk/bin/java',
        '/usr/lib/jvm/java-8-openjdk/bin/javac'
    }
}


def list_paths():
    for lang in all():
        cls = by_name(lang)
        if cls in OVERWRITE:
            for path in OVERWRITE[cls]:
                yield cls, path
            continue
        for p in cls.required_binaries():
            yield cls, p.cmd