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
« 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# --------------------------------------------------------------------------------------------------
10# Third party libraries
11import pytest
12from tsfpga.system_utils import create_file
14# First party libraries
15from hdl_registers.parser.toml import from_toml
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]
24type = "register_array"
25array_length = 2
26""",
27 )
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 )
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]
43type = "register_array"
45[apa.hest]
47mode = "r_w"
48""",
49 )
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 )
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]
65type = "register_array"
66array_length = 2
67dummy = 3
69[test_array.hest]
71mode = "r"
72""",
73 )
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 )