Coverage for tsfpga/test/unit/test_constraint.py: 100%

23 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2023-01-31 20:01 +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://gitlab.com/tsfpga/tsfpga 

7# -------------------------------------------------------------------------------------------------- 

8 

9# Standard libraries 

10from pathlib import Path 

11 

12# Third party libraries 

13import pytest 

14 

15# First party libraries 

16from tsfpga.constraint import Constraint 

17from tsfpga.hdl_file import HdlFile 

18 

19 

20def test_constraint(): 

21 constraint = Constraint(Path("dummy.tcl")) 

22 constraint.validate_scoped_entity([]) 

23 

24 assert constraint.ref is None 

25 assert constraint.used_in == "all" 

26 

27 constraint = Constraint(Path("dummy.tcl"), used_in="impl") 

28 assert constraint.used_in == "impl" 

29 

30 

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" 

36 

37 source_files = [HdlFile(tmp_path / "a" / "apa.vhd")] 

38 constraint.validate_scoped_entity(source_files) 

39 

40 

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") 

48 

49 

50def test_can_cast_to_string_without_error(): 

51 str(Constraint(Path("dummy.tcl"), used_in="impl"))