Coverage for hdl_registers/generator/python/test/accessor/test_accessor_basic.py: 100%

18 statements  

« 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# -------------------------------------------------------------------------------------------------- 

9 

10# Third party libraries 

11import pytest 

12from tsfpga.system_utils import load_python_module 

13 

14# First party libraries 

15from hdl_registers.generator.python.accessor import PythonAccessorGenerator 

16from hdl_registers.generator.python.pickle import PythonPickleGenerator 

17from hdl_registers.register_list import RegisterList 

18 

19 

20def test_generate_with_no_registers(tmp_path): 

21 register_list = RegisterList(name="test") 

22 

23 PythonPickleGenerator(register_list=register_list, output_folder=tmp_path).create() 

24 PythonAccessorGenerator(register_list=register_list, output_folder=tmp_path).create() 

25 

26 python_module = load_python_module(tmp_path / "test_accessor.py") 

27 python_module.get_accessor(register_accessor=None) 

28 

29 

30def test_create_accessor_without_pickle_should_raise_exception(tmp_path): 

31 register_list = RegisterList(name="test") 

32 

33 PythonAccessorGenerator(register_list=register_list, output_folder=tmp_path).create() 

34 

35 python_module = load_python_module(tmp_path / "test_accessor.py") 

36 with pytest.raises(FileNotFoundError) as exception_info: 

37 python_module.get_accessor(register_accessor=None) 

38 assert str(exception_info.value) == ( 

39 f"Could not find the pickle file {tmp_path / 'test.pickle'}, " 

40 "make sure this artifact is generated." 

41 )