Coverage for hdl_registers/constant/test/test_integer_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.integer_constant import IntegerConstant
20def test_constant():
21 for value in [123, -9]:
22 constant = IntegerConstant(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 IntegerConstant(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 = IntegerConstant(name="apa", value=3)
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 = IntegerConstant(name="hest", value=3)
47 assert repr(data) != repr(other)
49 # Different value
50 other = IntegerConstant(name="apa", value=4)
51 assert repr(data) != repr(other)
53 # Different description
54 data = IntegerConstant(name="apa", value=3, description="X")
55 assert repr(data) != repr(other)