Coverage for hdl_registers/generator/test/test_register_code_generator_helpers.py: 100%
26 statements
« prev ^ index » next coverage.py v7.6.8, created at 2024-12-01 20:50 +0000
« prev ^ index » next coverage.py v7.6.8, created at 2024-12-01 20:50 +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
13# First party libraries
14from hdl_registers.generator.register_code_generator_helpers import RegisterCodeGeneratorHelpers
15from hdl_registers.register import Register
16from hdl_registers.register_modes import REGISTER_MODES
19def test_field_setter_should_read_modify_write():
20 register = Register(name="", index=0, mode=REGISTER_MODES["r_w"], description="")
22 register.append_bit(name="", description="", default_value="0")
23 assert not RegisterCodeGeneratorHelpers.field_setter_should_read_modify_write(register)
25 register.append_bit(name="", description="", default_value="0")
26 assert RegisterCodeGeneratorHelpers.field_setter_should_read_modify_write(register)
28 register.append_bit(name="", description="", default_value="0")
29 assert RegisterCodeGeneratorHelpers.field_setter_should_read_modify_write(register)
32def test_field_setter_should_read_modify_write_should_raise_exception_if_there_are_no_fields():
33 register = Register(name="", index=0, mode=REGISTER_MODES["r_w"], description="")
35 with pytest.raises(AssertionError) as exception_info:
36 RegisterCodeGeneratorHelpers.field_setter_should_read_modify_write(register)
37 assert str(exception_info.value) == "Should not end up here if the register has no fields."
40def test_field_setter_should_read_modify_write_raise_exception_if_the_register_is_not_writable():
41 register = Register(name="", index=0, mode=REGISTER_MODES["r"], description="")
42 register.append_bit(name="", description="", default_value="0")
44 with pytest.raises(ValueError) as exception_info:
45 RegisterCodeGeneratorHelpers.field_setter_should_read_modify_write(register)
46 assert str(exception_info.value).startswith("Got non-writeable register:")
49def test_to_pascal_case():
50 assert RegisterCodeGeneratorHelpers.to_pascal_case("test") == "Test"
51 assert RegisterCodeGeneratorHelpers.to_pascal_case("test_two") == "TestTwo"