Coverage for hdl_registers/parser/test/test_parser/test_parser_default_register.py: 100%
14 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
16from hdl_registers.register import Register
17from hdl_registers.register_modes import REGISTER_MODES
20def test_overriding_default_register(tmp_path):
21 toml_path = create_file(
22 file=tmp_path / "regs.toml",
23 contents="""
24[config]
26type = "register"
27description = "apa"
28""",
29 )
30 register_list = from_toml(
31 name="",
32 toml_file=toml_path,
33 default_registers=[
34 Register(name="config", index=0, mode=REGISTER_MODES["r_w"], description="")
35 ],
36 )
38 assert register_list.get_register("config").description == "apa"
41def test_changing_mode_of_default_register_should_raise_exception(tmp_path):
42 toml_path = create_file(
43 file=tmp_path / "regs.toml",
44 contents="""
45[config]
47mode = "w"
48""",
49 )
51 with pytest.raises(ValueError) as exception_info:
52 from_toml(
53 name="",
54 toml_file=toml_path,
55 default_registers=[
56 Register(name="config", index=0, mode=REGISTER_MODES["r_w"], description="")
57 ],
58 )
59 assert str(exception_info.value) == (
60 f'Error while parsing register "config" in {toml_path}: '
61 'A "mode" may not be specified for a default register.'
62 )