Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# -------------------------------------------------------------------------------------------------- 

2# Copyright (c) Lukas Vik. All rights reserved. 

3# 

4# This file is part of the tsfpga project. 

5# https://tsfpga.com 

6# https://gitlab.com/tsfpga/tsfpga 

7# -------------------------------------------------------------------------------------------------- 

8 

9from pathlib import Path 

10 

11import unittest 

12import pytest 

13 

14from tsfpga.sby_writer import SbyWriter 

15 

16 

17@pytest.mark.usefixtures("fixture_tmp_path") 

18class TestSbyWriter(unittest.TestCase): 

19 

20 top = "dummy_top" 

21 formal_settings = dict( 

22 mode="dummy_mode", 

23 depth=20, 

24 engine_command="dummy_engine_command", 

25 solver_command="dummy_solver_command", 

26 ) 

27 

28 tmp_path = None 

29 compiled_libraries = ["library_1", "library_2"] 

30 src_files = ["file_1", "file_2.vhd"] 

31 generics = dict(dummy_generic="dummy_generic_val") 

32 

33 def setUp(self): 

34 self.output_path = self.tmp_path / Path("sby_writer_output.sby") 

35 

36 def test_sby_writer(self): 

37 sby_writer = SbyWriter() 

38 sby_writer.write_sby( 

39 output_path=self.output_path, 

40 top=self.top, 

41 formal_settings=self.formal_settings, 

42 compiled_libraries=self.compiled_libraries, 

43 src_files=self.src_files, 

44 generics=self.generics, 

45 ) 

46 

47 assert self.output_path.exists() 

48 

49 def test_should_work_with_empty_generics(self): 

50 sby_writer = SbyWriter() 

51 sby_writer.write_sby( 

52 output_path=self.output_path, 

53 top=self.top, 

54 formal_settings=self.formal_settings, 

55 compiled_libraries=self.compiled_libraries, 

56 src_files=self.src_files, 

57 ) 

58 

59 assert self.output_path.exists() 

60 

61 def test_fails_on_nonexisting_setting(self): 

62 sby_writer = SbyWriter() 

63 bad_formal_settings = self.formal_settings.copy() 

64 bad_formal_settings["dummy_key"] = "apa" 

65 with pytest.raises(ValueError) as exception_info: 

66 sby_writer.write_sby( 

67 output_path=self.output_path, 

68 top=self.top, 

69 formal_settings=bad_formal_settings, 

70 compiled_libraries=self.compiled_libraries, 

71 src_files=self.src_files, 

72 ) 

73 assert str(exception_info.value).startswith("Unexpected keys")