Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/graphviz/backend/mixins.py: 87%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

38 statements  

1"""Mixin classes used by Base subclasses to inherit backend functionality.""" 

2 

3import os 

4import typing 

5 

6from .. import parameters 

7 

8from . import piping 

9from . import rendering 

10from . import unflattening 

11from . import viewing 

12 

13__all__ = ['Render', 'Pipe', 'Unflatten', 'View'] 

14 

15 

16class Render(parameters.Parameters): 

17 """Parameters for calling and calling ``graphviz.render()``.""" 

18 

19 def _get_render_parameters(self, 

20 outfile: typing.Union[os.PathLike, str, None] = None, 

21 raise_if_result_exists: bool = False, 

22 overwrite_source: bool = False, 

23 **kwargs): 

24 kwargs = self._get_parameters(**kwargs) 

25 kwargs.update(outfile=outfile, 

26 raise_if_result_exists=raise_if_result_exists, 

27 overwrite_filepath=overwrite_source) 

28 return [kwargs.pop('engine'), kwargs.pop('format')], kwargs 

29 

30 @property 

31 def _render(_): # noqa: N805 

32 """Simplify ``._render()`` mocking.""" 

33 return rendering.render 

34 

35 

36class Pipe(parameters.Parameters): 

37 """Parameters for calling and calling ``graphviz.pipe()``.""" 

38 

39 _get_format = staticmethod(rendering.get_format) 

40 

41 _get_filepath = staticmethod(rendering.get_filepath) 

42 

43 def _get_pipe_parameters(self, **kwargs): 

44 kwargs = self._get_parameters(**kwargs) 

45 return [kwargs.pop('engine'), kwargs.pop('format')], kwargs 

46 

47 @property 

48 def _pipe_lines(_): # noqa: N805 

49 """Simplify ``._pipe_lines()`` mocking.""" 

50 return piping.pipe_lines 

51 

52 @property 

53 def _pipe_lines_string(_): # noqa: N805 

54 """Simplify ``._pipe_lines_string()`` mocking.""" 

55 return piping.pipe_lines_string 

56 

57 

58class Unflatten: 

59 

60 @property 

61 def _unflatten(_): # noqa: N805 

62 """Simplify ``._unflatten mocking.""" 

63 return unflattening.unflatten 

64 

65 

66class View: 

67 """Open filepath with its default viewing application 

68 (platform-specific).""" 

69 

70 _view_darwin = staticmethod(viewing.view_darwin) 

71 

72 _view_freebsd = staticmethod(viewing.view_unixoid) 

73 

74 _view_linux = staticmethod(viewing.view_unixoid) 

75 

76 _view_windows = staticmethod(viewing.view_windows)