Exemplo n.º 1
0
def test_examples(method):
    """Check whether all example methods are valid in CCL"""
    with open(f'examples/{method}') as f:
        data = f.read()
    try:
        CCLMethod(data)
    except CCLCodeError as e:
        line = data.split('\n')[e.line - 1]
        pytest.fail(f'{method}:{e.line}:{e.column}: {line}: {e.message}')
    except Exception as e:
        pytest.fail(f'{method}: {e}')
Exemplo n.º 2
0
    def ccl_changed(self) -> None:
        self.editor.blockSignals(True)
        self.clear_highlight()
        data = self.editor.toPlainText()
        if data:
            try:
                code = CCLMethod(data).translate(self.language)
                assert code is not None
                self.code.setPlainText(code)
                self.status.setText('OK')

            except CCLCodeError as e:
                self.status.setText(f'{e.line}: {e.message}')
                self.code.setPlainText('')
                self.highlight_error(e.line)
            except NotImplementedError as e:
                self.status.setText(str(e))
        else:
            self.status.setText('')
            self.code.setPlainText('')

        self.editor.blockSignals(False)
Exemplo n.º 3
0
def test_examples_latex(method):
    """Check whether LaTeX generated code compiles successfully"""
    tmpdir = tempfile.mkdtemp()
    with open(f'examples/{method}') as f:
        data = f.read()
    try:
        code = CCLMethod(data).translate('latex', full_output=True)
        assert code is not None
        with open(os.path.join(tmpdir, 'method.tex'), 'w') as f:
            f.write(code)
    except CCLCodeError as e:
        shutil.rmtree(tmpdir)
        line = data.split('\n')[e.line - 1]
        pytest.fail(f'{method}:{e.line}:{e.column}: {line}: {e.message}')
    except Exception as e:
        pytest.fail(f'{method}: {e}')

    args = ['xelatex', 'method.tex']
    p = subprocess.run(args, cwd=tmpdir, stderr=subprocess.PIPE)
    if p.returncode:
        pytest.fail(f'XeLaTeX failed ({tmpdir}): {p.stderr.decode("utf-8")}')

    shutil.rmtree(tmpdir)
Exemplo n.º 4
0
def test_examples_cpp(method):
    """Check whether C++ generated code compiles successfully"""
    tmpdir = tempfile.mkdtemp()
    with open(f'examples/{method}') as f:
        data = f.read()
    try:
        CCLMethod(data).translate('cpp', output_dir=tmpdir)
    except CCLCodeError as e:
        shutil.rmtree(tmpdir)
        line = data.split('\n')[e.line - 1]
        pytest.fail(f'{method}:{e.line}:{e.column}: {line}: {e.message}')
    except Exception as e:
        pytest.fail(f'{method}: {e}')

    args = ['cmake', '.', '-DCHARGEFW2_DIR=/opt/chargefw2']
    p = subprocess.run(args, cwd=tmpdir, stderr=subprocess.PIPE)
    if p.returncode:
        pytest.fail(f'Cmake failed: {p.stderr.decode("utf-8")}')
    p = subprocess.run(['make'], cwd=tmpdir, stderr=subprocess.PIPE)
    if p.returncode:
        pytest.fail(f'Make failed: {p.stderr.decode("utf-8")}')

    shutil.rmtree(tmpdir)
Exemplo n.º 5
0
def test_bad(example):
    """Test invalid constructs in CCL"""
    name, code = example
    with pytest.raises(CCLCodeError, match=re.escape(name)):
        CCLMethod(code)
Exemplo n.º 6
0
Arquivo: test.py Projeto: krab1k/CCL
import sys

from ccl.errors import CCLError
from ccl.method import CCLMethod

if len(sys.argv) != 3:
    print('Not enough arguments')
    sys.exit(1)

try:
    method = CCLMethod.from_file(sys.argv[1])
    print('\n*** CCL ****\n')
    print(method.source)
    print('\n*** Translated ****\n')
    print(method.translate('cpp', output_dir=sys.argv[2], full_output=True))
    print('Complexity: ', method.get_complexity(asymptotic=True))
except CCLError as e:
    print(e)
    sys.exit(1)