Coverage for hdl_registers/test/unit/test_constant.py: 100%
29 statements
« prev ^ index » next coverage.py v6.5.0, created at 2023-01-29 22:03 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2023-01-29 22:03 +0000
1# --------------------------------------------------------------------------------------------------
2# Copyright (c) Lukas Vik. All rights reserved.
3#
4# This file is part of the hdl_registers project, a HDL register generator fast enough to be run
5# in real time.
6# https://hdl-registers.com
7# https://gitlab.com/hdl_registers/hdl_registers
8# --------------------------------------------------------------------------------------------------
10# Third party libraries
11import pytest
13# First party libraries
14from hdl_registers.constant import Constant
17def test_boolean():
18 for value in [True, False]:
19 constant = Constant(name="apa", value=value)
21 assert constant.is_boolean
22 assert not constant.is_integer
23 assert not constant.is_float
26def test_integer():
27 for value in [123, -9]:
28 constant = Constant(name="apa", value=value)
30 assert constant.is_integer
31 assert not constant.is_boolean
32 assert not constant.is_float
35def test_float():
36 for value in [3.14, -9.9]:
37 constant = Constant(name="apa", value=value)
39 assert constant.is_float
40 assert not constant.is_boolean
41 assert not constant.is_integer
44def test_invalid_data_type():
45 with pytest.raises(ValueError) as exception_info:
46 Constant(name="apa", value="hest")
47 assert (
48 str(exception_info.value)
49 == 'Constant "apa" has invalid data type "<class \'str\'>". Value: "hest"'
50 )
53def test_repr():
54 # Check that repr is an actual representation, not just "X object at 0xABCDEF"
55 assert "apa" in repr(Constant(name="apa", value=0))
57 # Different name
58 assert repr(Constant(name="apa", value=0)) != repr(Constant(name="hest", value=0))
60 # Different value
61 assert repr(Constant(name="apa", value=0)) != repr(Constant(name="apa", value=1))
63 # Different description
64 assert repr(Constant(name="apa", value=0, description="Blah")) != repr(
65 Constant(name="apa", value=0, description="Gaah")
66 )