def test_context(): """Load a project and retrieve the context.""" with ProjectTree("p.gpr") as tree: assert len(tree.context) == 0, tree.context with ProjectTree("p.gpr", context={"VAR1": "valnico", "VAR2": ""}) as tree: assert len(tree.context) == 2, tree.context with ProjectTree("p.gpr", context={"VAR1": "valnico", "VAR3": ""}) as tree: assert len(tree.context) == 2, tree.context
def test_view(): with ProjectTree("p.gpr") as tree: with tree.root_view as view: assert view.name == "P" assert os.path.basename(view.path) == "p.gpr" assert view.id is not None assert len(view.sources()) == 1, json.dumps(view.sources(), indent=2) assert view.id is None, "view not deallocated"
def test_load_unexisting_project(): """Load a non existing project. A GPR2Error exception should be raised with a non-existing project message. """ with pytest.raises(GPR2Error) as exc_info: ProjectTree("non_existing.gpr") exc_info.match("non_existing.gpr: no such file")
def test_target(): """Target test.""" logging.info("Target set by external default value") with ProjectTree("p.gpr") as tree: assert tree.target == "dummy", "target not set" logging.info("Target set using target parameter should bypass external") with ProjectTree("p.gpr", target="x86_64-pc-linux-gnu") as tree: assert tree.target == "x86_64-pc-linux-gnu" with ProjectTree("p.gpr", target="dummy-target") as tree: assert tree.target == "dummy-target" logging.info("Target parameter should be used in priority") with ProjectTree( "p.gpr", target="real-target", context={"TARGET_NAME": "new-target"} ) as tree: assert tree.target == "real-target"
def test_messages(): """Fetch project messages.""" with ProjectTree("p.gpr") as tree: tree.fetch_messages() logging.info("\n".join([str(msg) for msg in tree.messages])) assert len(tree.messages) > 0 former_length = len(tree.messages) tree.fetch_messages() assert len(tree.messages) == former_length
def test_target2(): """Target test.""" logging.info("Target set using context.") with ProjectTree("p.gpr", context={"TARGET_NAME": "new-target"}) as tree: assert tree.target == "new-target" logging.info("Check that context change implies change in target") tree.context = {"TARGET_NAME": "new-target2"} assert tree.target == "new-target2" tree.context = {} assert tree.target == "dummy"
def test_load_simple_project(): """Load a simple project.""" tree = ProjectTree("p.gpr") tree.close() with ProjectTree("p.gpr") as tree: assert tree.id is not None assert tree.language_properties("ada").dependency_ext == ".ali" assert tree.id is None
def test_load_non_parsable_project(): """Load a project with syntax errors.""" with pytest.raises(GPR2Error) as exc_info: ProjectTree("invalid.gpr") exc_info.match("syntax error")
def test_root_view(): """Get the root view of a given project tree.""" tree = ProjectTree("p.gpr") view = tree.root_view assert isinstance(view, ProjectView)
def test_project_dir(): mkdir("working_dir") with ProjectTree("p.gpr", project_dir="working_dir") as tree: assert tree.project_dir == tree.root_view.dir assert tree.project_dir == os.path.abspath("working_dir")