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
« 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# --------------------------------------------------------------------------------------------------
10import pytest
11from tsfpga.system_utils import create_file
13from hdl_registers.parser.toml import from_toml
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]
22type = "register_array"
23array_length = 2
24""",
25 )
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 )
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]
41type = "register_array"
43[apa.hest]
45mode = "r_w"
46""",
47 )
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 )
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]
63type = "register_array"
64array_length = 2
65dummy = 3
67[test_array.hest]
69mode = "r"
70""",
71 )
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 )