Coverage for /home/delusionalinsanity/bbrepos/matyan/src/matyan/tests/base.py: 0%

# Coverage for /home/delusionalinsanity/bbrepos/matyan/src/matyan/tests/base.py : 0%

## 53 statements 0 run 53 missing 0 excluded

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 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | # -*- coding: utf-8 -*- import logging import socket __author__ = 'Artur Barseghyan' __copyright__ = '2019 Artur Barseghyan' __license__ = 'GPL-2.0-only OR LGPL-2.0-or-later' __all__ = ( 'internet_available_only', 'log_info', ) LOG_INFO = True TRACK_TIME = False LOGGER = logging.getLogger(__name__) def log_info(func): """Log some useful info.""" if not LOG_INFO: return func def inner(self, *args, **kwargs): """Inner.""" if TRACK_TIME: import simple_timer timer = simple_timer.Timer() # Start timer result = func(self, *args, **kwargs) if TRACK_TIME: timer.stop() # Stop timer LOGGER.debug('\n\n%s', func.__name__) LOGGER.debug('============================') if func.__doc__: LOGGER.debug('""" %s """', func.__doc__.strip()) LOGGER.debug('----------------------------') if result is not None: LOGGER.debug(result) if TRACK_TIME: LOGGER.debug('done in %s seconds', timer.duration) LOGGER.debug('\n++++++++++++++++++++++++++++') return result return inner def is_internet_available(host="8.8.8.8", port=53, timeout=3): """Check if internet is available. Host: 8.8.8.8 (google-public-dns-a.google.com) OpenPort: 53/tcp Service: domain (DNS/TCP) """ try: socket.setdefaulttimeout(timeout) socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect((host, port)) return True except socket.error as ex: print(ex) return False def internet_available_only(func): def inner(self, *args, **kwargs): """Inner.""" if not is_internet_available(): LOGGER.debug('\n\n%s', func.__name__) LOGGER.debug('============================') if func.__doc__: LOGGER.debug('""" %s """', func.__doc__.strip()) LOGGER.debug('----------------------------') LOGGER.debug("Skipping because no Internet connection available.") LOGGER.debug('\n++++++++++++++++++++++++++++') return None result = func(self, *args, **kwargs) return result return inner