"""
open/DurusWorks/qpy/test/utest_translate.py

"""
from sancho.utest import UTest, raises
from qpy.translate import translate_tokens
from qpy.compile import get_parse_tree


class TestTranslate(UTest):

    def test_translate(self):
        src = (
            'def a:xml():\n'
            '    "ok"\n')
        translated = translate_tokens(src)
        assert 'def a__xml_template__(' in translated, translated

        src = ('def a [html] ():\n'
               '    "ok"\n')
        assert translated == translate_tokens(src)
        assert 'def a__xml_template__(' in translated

        src = (
            'def a:str():\n'
            '    "ok"\n')
        translated = translate_tokens(src)
        assert 'def a__str_template__(' in translated

        src = ('def a [plain] ():\n'
               '    "ok"\n')
        assert translated == translate_tokens(src)
        assert 'def a__str_template__(' in translated

    def test_tree_utils(self):
        src = ('def a():\n'
               '    "ok"\n')
        tree = get_parse_tree(src, 'fake')
        assert type(tree) is list
        raises(SyntaxError, get_parse_tree, 'bogus' + src)
        raises(SyntaxError, get_parse_tree, 'bogus' + src, 'fake')

if __name__ == '__main__':
    TestTranslate()
