示例#1
0
def test_get_language_bad_source(source):
    code = "#!/usr/bin/python\n"
    code += FOO_FUNCTION
    assert p.get_language(source, code) == PYTHON
    with pytest.raises(ValueError) as e:
        assert p.get_language(source, "badlang")

    msg = "Can't figure out the language!"
    try:
        assert e.value.message == msg
    except AttributeError:
        assert e.value.args[0] == msg
示例#2
0
def test_get_language_bad_source(source):
    code = "#!/usr/bin/python\n"
    code += FOO_FUNCTION
    assert p.get_language(source, code) == PYTHON
    with pytest.raises(ValueError) as e:
        assert p.get_language(source, "badlang")

    msg = "Can't figure out the language!"
    try:
        assert e.value.message == msg
    except AttributeError:
        assert e.value.args[0] == msg
示例#3
0
def pycco(file_name):
    code = open(file_name, 'rb').read().decode('utf-8')
    language = pyccoLib.get_language(file_name, code)
    sections = pyccoLib.parse(code, language)
    pyccoLib.highlight(sections, language, outdir="docs")

    data = {'file_path': trim_repo_path(file_name), 'sections': sections}
    print('[COUT] CO_JSON_CONTENT {}'.format(json.dumps(data)))

    return True
示例#4
0
def pycco(file_name, use_yaml):
    code = open(file_name, 'rb').read().decode('utf-8')
    language = pyccoLib.get_language(file_name, code)
    sections = pyccoLib.parse(code, language)
    pyccoLib.highlight(sections, language, outdir="docs")

    data = { 'file_path': trim_repo_path(file_name), 'sections': sections }
    if use_yaml:
        data = anymarkup.serialize(data, 'yaml')
        print('[COUT] CO_YAML_CONTENT {}'.format(str(data)[1:]))
    else:
        print('[COUT] CO_JSON_CONTENT {}'.format(json.dumps(data)))


    return True
示例#5
0
def test_get_language_bad_code(code):
    source = "test.py"
    assert p.get_language(source, code) == PYTHON
示例#6
0
def test_get_language_specify_language(source, code):
    assert p.get_language(source, code, language="python") == p.languages['.py']

    with pytest.raises(ValueError):
        p.get_language(source, code, language="non-existent")
示例#7
0
def test_get_language_bad_code(code):
    source = "test.py"
    assert p.get_language(source, code) == PYTHON
示例#8
0
def test_get_language_specify_language(source, code):
    assert p.get_language(source, code,
                          language="python") == p.languages['.py']

    with pytest.raises(ValueError):
        p.get_language(source, code, language="non-existent")