Coverage for hdl_registers/constant/test/test_float_constant.py: 100%
23 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# Standard libraries
11from copy import copy
13# Third party libraries
14import pytest
16# First party libraries
17from hdl_registers.constant.float_constant import FloatConstant
20def test_constant():
21 for value in [3.14, -9.9]:
22 constant = FloatConstant(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 FloatConstant(name="apa", value=True)
32 assert (
33 str(exception_info.value)
34 == 'Constant "apa" has invalid data type "<class \'bool\'>". Value: "True".'
35 )
38def test_repr():
39 data = FloatConstant(name="apa", value=3.14)
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 = FloatConstant(name="hest", value=3.14)
47 assert repr(data) != repr(other)
49 # Different value
50 other = FloatConstant(name="apa", value=4.2)
51 assert repr(data) != repr(other)
53 # Different description
54 data = FloatConstant(name="apa", value=3.14, description="X")
55 assert repr(data) != repr(other)