Coverage for hdl_registers/constant/test/test_boolean_constant.py: 100%
23 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# Standard libraries
11from copy import copy
13# Third party libraries
14import pytest
16# First party libraries
17from hdl_registers.constant.boolean_constant import BooleanConstant
20def test_constant():
21 for value in [True, False]:
22 constant = BooleanConstant(name="apa", value=value, description=f"desc {value}")
24 assert constant.name == "apa"
25 assert constant.value == value
26 assert constant.description == f"desc {value}"
29def test_invalid_data_type():
30 with pytest.raises(ValueError) as exception_info:
31 BooleanConstant(name="apa", value=3.5)
32 assert (
33 str(exception_info.value)
34 == 'Constant "apa" has invalid data type "<class \'float\'>". Value: "3.5".'
35 )
38def test_repr():
39 data = BooleanConstant(name="apa", value=True)
41 # Check that repr is an actual representation, not just "X object at 0xABCDEF"
42 assert "apa" in repr(data)
43 assert repr(data) == repr(copy(data))
45 # Different name
46 other = BooleanConstant(name="hest", value=True)
47 assert repr(data) != repr(other)
49 # Different value
50 other = BooleanConstant(name="apa", value=False)
51 assert repr(data) != repr(other)
53 # Different description
54 data = BooleanConstant(name="apa", value=True, description="X")
55 assert repr(data) != repr(other)