Coverage for hdl_registers/constant/test/test_float_constant.py: 100%
23 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# --------------------------------------------------------------------------------------------------
10from copy import copy
12import pytest
14from hdl_registers.constant.float_constant import FloatConstant
17def test_constant():
18 for value in [3.14, -9.9]:
19 constant = FloatConstant(name="apa", value=value, description=f"desc {value}")
21 assert constant.name == "apa"
22 assert constant.value == value
23 assert constant.description == f"desc {value}"
26def test_invalid_data_type():
27 with pytest.raises(TypeError) as exception_info:
28 FloatConstant(name="apa", value=True)
29 assert (
30 str(exception_info.value)
31 == 'Constant "apa" has invalid data type "<class \'bool\'>". Value: "True".'
32 )
35def test_repr():
36 data = FloatConstant(name="apa", value=3.14)
38 # Check that repr is an actual representation, not just "X object at 0xABCDEF"
39 assert "apa" in repr(data)
40 assert repr(data) == repr(copy(data))
42 # Different name
43 other = FloatConstant(name="hest", value=3.14)
44 assert repr(data) != repr(other)
46 # Different value
47 other = FloatConstant(name="apa", value=4.2)
48 assert repr(data) != repr(other)
50 # Different description
51 data = FloatConstant(name="apa", value=3.14, description="X")
52 assert repr(data) != repr(other)