Exemplo n.º 1
0
def test_handler_existing_file():
    handler = FakeHandler([])
    file_info = os.stat(__file__)
    with handler.parent_open(__file__) as f_obj:
        assert (os.fstat(f_obj.fileno()).st_ino ==
                file_info.st_ino)
        assert f_obj.name == __file__
Exemplo n.º 2
0
def test_include_preresolved():
    f_obj = FakeFile("header.h", ['#include <other.h>\n'])
    header = "other.h"
    path = posixpath.join("subdirectory", header)
    handler = FakeHandler({path: ["1\n"]})
    handler.resolved[header] = path
    ret = preprocess(f_obj, header_handler=handler)
    assert "".join(ret) == "1\n"
Exemplo n.º 3
0
def test_ifdef_file_guard():
    other_header = "somedirectory/other.h"
    f_obj = FakeFile("header.h",
                     ['#include "%s"\n' % other_header])
    handler = FakeHandler({other_header: ["1\n"]})
    ret = preprocess(f_obj, header_handler=handler)
    assert "".join(ret) == "1\n"
Exemplo n.º 4
0
def test_include_local_fallback():
    other_header = "other.h"
    path = "bogus"
    f_obj = FakeFile("header.h", ['#include "%s"\n' % other_header])
    handler = FakeHandler({"%s/%s" % (path, other_header): ["2\n"]},
                          include_paths=[path])
    ret = preprocess(f_obj, header_handler=handler)
    assert "".join(ret) == "2\n"
Exemplo n.º 5
0
def test_include_with_path_list():
    f_obj = FakeFile("header.h", ['#include <other.h>\n'])
    directory = "subdirectory"
    handler = FakeHandler({posixpath.join(directory,
                                          "other.h"): ["1\n"]})
    include_paths = [directory]
    ret = preprocess(f_obj, include_paths=include_paths,
                     header_handler=handler)
    assert "".join(ret) == "1\n"
Exemplo n.º 6
0
def test_ignore_include_path():
    f_obj = FakeFile("header.h", ['#include <other.h>\n'])
    handler = FakeHandler({posixpath.join("subdirectory",
                                          "other.h"): ["1\n"]})
    paths = ["subdirectory"]
    ignored = ["other.h"]
    ret = preprocess(f_obj, include_paths=paths,
                     header_handler=handler,
                     ignore_headers=ignored)
    assert "".join(ret) == ""
Exemplo n.º 7
0
def test_include_with_path_list_with_subdirectory():
    header_file = posixpath.join("nested", "other.h")
    include_path = "somedir"
    f_obj = FakeFile("header.h", ['#include <%s>\n' % header_file])
    handler = FakeHandler({posixpath.join(include_path,
                                          header_file): ["1\n"]})
    include_paths = [include_path]
    ret = preprocess(f_obj, include_paths=include_paths,
                     header_handler=handler)
    assert "".join(ret) == "1\n"
Exemplo n.º 8
0
def test_fullfile_guard_ifndef_noskip():
    f_obj = FakeFile("header.h", ["""#include "other.h"\n""",
                                  "done\n"])
    handler = FakeHandler({"other.h": [
        "#ifndef X\n",
        "#endif\n"]})
    preprocessor = Preprocessor(header_handler=handler)
    ret = preprocessor.preprocess(f_obj)
    assert "".join(ret) == "done\n"
    assert not preprocessor.skip_file("other.h"), (
        "%s -> %s" % (preprocessor.include_once,
                      preprocessor.defines))
Exemplo n.º 9
0
def test_pragma_once():
    f_obj = FakeFile("header.h", [
                     """#include "other.h"\n""",
                     """#include "other.h"\n""",
                     "X\n"])
    handler = FakeHandler({"other.h": [
        "#pragma once\n",
        "#ifdef X\n",
        "#define X 2\n",
        "#else\n",
        "#define X 1\n",
        "#endif\n"]})
    preprocessor = Preprocessor(header_handler=handler)
    ret = preprocessor.preprocess(f_obj)
    assert "".join(ret) == "1\n"
    assert preprocessor.skip_file("other.h")
Exemplo n.º 10
0
def test_handler_missing_file():
    handler = FakeHandler([])
    assert handler.parent_open("does_not_exist") is None
Exemplo n.º 11
0
def test_include_missing_local_file():
    other_header = posixpath.join("somedirectory", "other.h")
    f_obj = FakeFile("header.h", ['#include "%s"\n' % other_header])
    handler = FakeHandler({})
    with pytest.raises(ParseError):
        "".join(preprocess(f_obj, header_handler=handler))