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

18 statements  

« prev     ^ index     » next       coverage.py v7.6.9, created at 2024-12-19 20:51 +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 

10# Third party libraries 

11import pytest 

12from tsfpga.system_utils import create_file 

13 

14# First party libraries 

15from hdl_registers.parser.toml import from_toml 

16 

17 

18def test_register_array_without_register_should_raise_exception(tmp_path): 

19 toml_path = create_file( 

20 file=tmp_path / "regs.toml", 

21 contents=""" 

22[dummy_array] 

23 

24type = "register_array" 

25array_length = 2 

26""", 

27 ) 

28 

29 with pytest.raises(ValueError) as exception_info: 

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

31 assert str(exception_info.value) == ( 

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

33 "Array must contain at least one register." 

34 ) 

35 

36 

37def test_register_array_without_array_length_property_should_raise_exception(tmp_path): 

38 toml_path = create_file( 

39 file=tmp_path / "regs.toml", 

40 contents=""" 

41[apa] 

42 

43type = "register_array" 

44 

45[apa.hest] 

46 

47mode = "r_w" 

48""", 

49 ) 

50 

51 with pytest.raises(ValueError) as exception_info: 

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

53 assert str(exception_info.value) == ( 

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

55 'Missing required property "array_length".' 

56 ) 

57 

58 

59def test_unknown_register_array_property_should_raise_exception(tmp_path): 

60 toml_path = create_file( 

61 file=tmp_path / "regs.toml", 

62 contents=""" 

63[test_array] 

64 

65type = "register_array" 

66array_length = 2 

67dummy = 3 

68 

69[test_array.hest] 

70 

71mode = "r" 

72""", 

73 ) 

74 

75 with pytest.raises(ValueError) as exception_info: 

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

77 assert ( 

78 str(exception_info.value) 

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

80 'Got unknown property "dummy".' 

81 )