Skip to content

Commit

Permalink
Attempt to increase coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
barseghyanartur committed Nov 18, 2019
1 parent 2285357 commit 552ef86
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 6 deletions.
72 changes: 71 additions & 1 deletion src/matyan/tests/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-

import os
import logging
import socket

Expand All @@ -8,7 +9,11 @@
__license__ = 'GPL-2.0-only OR LGPL-2.0-or-later'
__all__ = (
'internet_available_only',
'internet_available_or_is_travis_only',
'is_internet_available',
'is_travis',
'log_info',
'travis_only',
)

LOG_INFO = True
Expand Down Expand Up @@ -48,7 +53,9 @@ def inner(self, *args, **kwargs):
return inner


def is_internet_available(host="8.8.8.8", port=53, timeout=3):
def is_internet_available(host: str = "8.8.8.8",
port: int = 53,
timeout: int = 3) -> bool:
"""Check if internet is available.
Host: 8.8.8.8 (google-public-dns-a.google.com)
Expand All @@ -65,7 +72,11 @@ def is_internet_available(host="8.8.8.8", port=53, timeout=3):


def internet_available_only(func):
"""Is internet available decorator.
:param func:
:return:
"""
def inner(self, *args, **kwargs):
"""Inner."""
if not is_internet_available():
Expand All @@ -82,3 +93,62 @@ def inner(self, *args, **kwargs):
return result

return inner


def is_travis() -> bool:
"""Is travis.
:return:
"""
return os.environ.get('TRAVIS') == 'true'


def travis_only(func):
"""Is on Travis CI decorator.
:param func:
:return:
"""
def inner(self, *args, **kwargs):
"""Inner."""
if not is_travis():
LOGGER.debug('\n\n%s', func.__name__)
LOGGER.debug('============================')
if func.__doc__:
LOGGER.debug('""" %s """', func.__doc__.strip())
LOGGER.debug('----------------------------')
LOGGER.debug("Skipping because this test is Travis CI only.")
LOGGER.debug('\n++++++++++++++++++++++++++++')
return None

result = func(self, *args, **kwargs)
return result

return inner


def internet_available_or_is_travis_only(func):
"""Is internet available or is Travis only decorator.
:param func:
:return:
"""
def inner(self, *args, **kwargs):
"""Inner."""
if not is_internet_available() and not is_travis():
LOGGER.debug('\n\n%s', func.__name__)
LOGGER.debug('============================')
if func.__doc__:
LOGGER.debug('""" %s """', func.__doc__.strip())
LOGGER.debug('----------------------------')
LOGGER.debug(
"Skipping because nor Internet connection available, "
"neither the test is being executed on Travis CI."
)
LOGGER.debug('\n++++++++++++++++++++++++++++')
return None

result = func(self, *args, **kwargs)
return result

return inner
14 changes: 10 additions & 4 deletions src/matyan/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
import git

from ..helpers import project_dir
from .base import log_info, internet_available_only, is_internet_available
from .base import (
log_info,
internet_available_only,
is_internet_available,
internet_available_or_is_travis_only,
is_travis,
)

__author__ = 'Artur Barseghyan'
__copyright__ = '2019 Artur Barseghyan'
Expand All @@ -23,7 +29,7 @@ class TestCommands(unittest.TestCase):
def setUpClass(cls):
"""Set up."""
super(TestCommands, cls).setUpClass()
if is_internet_available():
if is_internet_available() or is_travis():
# Test directory for cloning the repo
test_dir = project_dir("tests/matyan-testing")
if not os.path.exists(test_dir):
Expand Down Expand Up @@ -51,7 +57,7 @@ def setUpClass(cls):
with open(changelog_releases_output, 'r') as file:
cls.changelog_releases_output = file.read().strip()

@internet_available_only
@internet_available_or_is_travis_only
@log_info
def test_01_generate_changelog_command(self):
"""Test generate changelog command."""
Expand All @@ -61,7 +67,7 @@ def test_01_generate_changelog_command(self):
self.assertEqual(res, self.changelog_output)
return res

@internet_available_only
@internet_available_or_is_travis_only
@log_info
def test_02_generate_changelog_command_show_releases(self):
"""Test generate changelog command."""
Expand Down
6 changes: 5 additions & 1 deletion src/matyan/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
REGEX_PATTERN_MERGED_BRANCH_NAME,
)

from .base import internet_available_only, log_info
from .base import (
internet_available_only,
log_info,
internet_available_or_is_travis_only,
)

__author__ = 'Artur Barseghyan'
__copyright__ = '2019 Artur Barseghyan'
Expand Down

0 comments on commit 552ef86

Please sign in to comment.