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