Coverage for hdl_registers/parser/test/test_parser/test_parser_register_array.py: 100%

18 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-03-12 11:11 +0000

1# -------------------------------------------------------------------------------------------------- 

2# Copyright (c) Lukas Vik. All rights reserved. 

3# 

4# This file is part of the hdl-registers project, an HDL register generator fast enough to run 

5# in real time. 

6# https://hdl-registers.com 

7# https://github.com/hdl-registers/hdl-registers 

8# -------------------------------------------------------------------------------------------------- 

9 

10import pytest 

11from tsfpga.system_utils import create_file 

12 

13from hdl_registers.parser.toml import from_toml 

14 

15 

16def test_register_array_without_register_should_raise_exception(tmp_path): 

17 toml_path = create_file( 

18 file=tmp_path / "regs.toml", 

19 contents=""" 

20[dummy_array] 

21 

22type = "register_array" 

23array_length = 2 

24""", 

25 ) 

26 

27 with pytest.raises(ValueError) as exception_info: 

28 from_toml(name="", toml_file=toml_path) 

29 assert str(exception_info.value) == ( 

30 f'Error while parsing register array "dummy_array" in {toml_path}: ' 

31 "Array must contain at least one register." 

32 ) 

33 

34 

35def test_register_array_without_array_length_property_should_raise_exception(tmp_path): 

36 toml_path = create_file( 

37 file=tmp_path / "regs.toml", 

38 contents=""" 

39[apa] 

40 

41type = "register_array" 

42 

43[apa.hest] 

44 

45mode = "r_w" 

46""", 

47 ) 

48 

49 with pytest.raises(ValueError) as exception_info: 

50 from_toml(name="", toml_file=toml_path) 

51 assert str(exception_info.value) == ( 

52 f'Error while parsing register array "apa" in {toml_path}: ' 

53 'Missing required property "array_length".' 

54 ) 

55 

56 

57def test_unknown_register_array_property_should_raise_exception(tmp_path): 

58 toml_path = create_file( 

59 file=tmp_path / "regs.toml", 

60 contents=""" 

61[test_array] 

62 

63type = "register_array" 

64array_length = 2 

65dummy = 3 

66 

67[test_array.hest] 

68 

69mode = "r" 

70""", 

71 ) 

72 

73 with pytest.raises(ValueError) as exception_info: 

74 from_toml(name="", toml_file=toml_path) 

75 assert ( 

76 str(exception_info.value) 

77 == f'Error while parsing register array "test_array" in {toml_path}: ' 

78 'Got unknown property "dummy".' 

79 )