Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/scapy/libs/test_pyx.py: 50%

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

22 statements  

1# SPDX-License-Identifier: GPL-2.0-only 

2# This file is part of Scapy 

3# See https://scapy.net/ for more information 

4 

5""" 

6External link to pyx 

7""" 

8 

9import os 

10import subprocess 

11from scapy.error import log_loading 

12 

13# Notice: this file must not be called before main.py, if started 

14# in interactive mode, because it needs to be called after the 

15# logger has been setup, to be able to print the warning messages 

16 

17__all__ = [ 

18 "PYX", 

19] 

20 

21# PYX 

22 

23 

24def _test_pyx(): 

25 # type: () -> bool 

26 """Returns if PyX is correctly installed or not""" 

27 try: 

28 with open(os.devnull, 'wb') as devnull: 

29 r = subprocess.check_call(["pdflatex", "--version"], 

30 stdout=devnull, stderr=subprocess.STDOUT) 

31 except (subprocess.CalledProcessError, OSError): 

32 return False 

33 else: 

34 return r == 0 

35 

36 

37try: 

38 import pyx # noqa: F401 

39 if _test_pyx(): 

40 PYX = 1 

41 else: 

42 log_loading.info("PyX dependencies are not installed ! Please install TexLive or MikTeX.") # noqa: E501 

43 PYX = 0 

44except ImportError: 

45 log_loading.info("Can't import PyX. Won't be able to use psdump() or pdfdump().") # noqa: E501 

46 PYX = 0