Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/graphviz/_compat.py: 100%

11 statements  

« prev     ^ index     » next       coverage.py v7.2.2, created at 2023-03-26 06:43 +0000

1"""Python 3.7 to 3.8 compatibility and platform compatibility.""" 

2 

3import os 

4import platform 

5import sys 

6import typing 

7 

8PY38 = (sys.version_info < (3, 9)) 

9 

10 

11Literal: typing.Any 

12 

13 

14if PY38: # pragma: no cover 

15 # pytype not supported 

16 import unittest.mock 

17 

18 Literal = unittest.mock.MagicMock(name='Literal') 

19else: # pragma: no cover 

20 from typing import Literal 

21 

22 Literal = Literal # CAVEAT: use None instead of Literal[None] 

23 

24 

25def get_startupinfo() -> None: 

26 """Return None for startupinfo argument of ``subprocess.Popen``.""" 

27 return None 

28 

29 

30assert get_startupinfo() is None, 'get_startupinfo() defaults to a no-op' 

31 

32 

33if platform.system() == 'Windows': # pragma: no cover 

34 import subprocess 

35 

36 def get_startupinfo() -> subprocess.STARTUPINFO: # pytype: disable=module-attr 

37 """Return subprocess.STARTUPINFO instance hiding the console window.""" 

38 startupinfo = subprocess.STARTUPINFO() # pytype: disable=module-attr 

39 startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW # pytype: disable=module-attr 

40 startupinfo.wShowWindow = subprocess.SW_HIDE # pytype: disable=module-attr 

41 return startupinfo 

42 

43 

44def make_subprocess_arg(arg: typing.Union[str, os.PathLike]) -> typing.Union[str, os.PathLike]: 

45 """Return subprocess argument as is (default no-op).""" 

46 return arg 

47 

48 

49if platform.system() == 'Windows' and sys.version_info < (3, 8): # pragma: no cover 

50 def make_subprocess_arg(arg: typing.Union[str, os.PathLike]) -> str: # noqa: F811 

51 """Workaround https://bugs.python.org/issue41649 (not backported).""" 

52 return os.fspath(arg)