Coverage for tsfpga/test/test_constraint.py: 100%
23 statements
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-07 20:51 +0000
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-07 20:51 +0000
1# --------------------------------------------------------------------------------------------------
2# Copyright (c) Lukas Vik. All rights reserved.
3#
4# This file is part of the tsfpga project, a project platform for modern FPGA development.
5# https://tsfpga.com
6# https://github.com/tsfpga/tsfpga
7# --------------------------------------------------------------------------------------------------
9# Standard libraries
10from pathlib import Path
12# Third party libraries
13import pytest
15# First party libraries
16from tsfpga.constraint import Constraint
17from tsfpga.hdl_file import HdlFile
20def test_constraint():
21 constraint = Constraint(Path("dummy.tcl"))
22 constraint.validate_scoped_entity([])
24 assert constraint.ref is None
25 assert constraint.used_in == "all"
27 constraint = Constraint(Path("dummy.tcl"), used_in="impl")
28 assert constraint.used_in == "impl"
31def test_scoped_constraint(tmp_path):
32 constraint = Constraint(
33 tmp_path / "a" / "scoped_constraints" / "apa.tcl", scoped_constraint=True
34 )
35 assert constraint.ref == "apa"
37 source_files = [HdlFile(tmp_path / "a" / "apa.vhd")]
38 constraint.validate_scoped_entity(source_files)
41def test_matching_entity_not_existing_should_raise_exception(tmp_path):
42 constraint = Constraint(
43 tmp_path / "a" / "scoped_constraints" / "dummy.tcl", scoped_constraint=True
44 )
45 with pytest.raises(FileNotFoundError) as exception_info:
46 constraint.validate_scoped_entity([])
47 assert str(exception_info.value).startswith("Could not find a matching entity file")
50def test_can_cast_to_string_without_error():
51 str(Constraint(Path("dummy.tcl"), used_in="impl"))