Skip to content

Commit

Permalink
Increase code-coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
nir0s committed Nov 1, 2016
1 parent f8b27eb commit 8054c8e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ source =
distro.py
.tox/*/lib/python*/site-packages/distro.py
.tox/pypy/site-packages/distro.py

[report]
exclude_lines =
if __name__ == .__main__.:
raise ImportError
raise subprocess.CalledProcessError
3 changes: 1 addition & 2 deletions distro.py
Original file line number Diff line number Diff line change
Expand Up @@ -951,8 +951,7 @@ def _parse_lsb_release_content(lines):
"""
props = {}
for line in lines:
if isinstance(line, bytes):
line = line.decode('utf-8')
line = line.decode('utf-8') if isinstance(line, bytes) else line
kv = line.strip('\n').split(':', 1)
if len(kv) != 2:
# Ignore lines without colon.
Expand Down
12 changes: 10 additions & 2 deletions tests/test_distro.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
import os
import sys
import ast
import testtools
import subprocess
try:
from StringIO import StringIO # Python 2.x
except ImportError:
from io import StringIO # Python 3.x

import testtools


BASE = os.path.abspath(os.path.dirname(__file__))
RESOURCES = os.path.join(BASE, 'resources')
Expand Down Expand Up @@ -57,6 +58,10 @@ class TestCli(testtools.TestCase):
def setUp(self):
super(TestCli, self).setUp()

def _parse(self, command):
sys.argv = command.split()
distro.main()

def _run(self, command):
stdout, _ = subprocess.Popen(
command,
Expand All @@ -65,6 +70,10 @@ def _run(self, command):
# Need to decode or we get bytes in Python 3.x
return stdout.decode('utf-8')

def test_cli_for_coverage_yuch(self):
self._parse('distro')
self._parse('distro -j')

def test_cli(self):
command = [sys.executable, '-m', 'distro']
desired_output = 'Name: ' + distro.name(pretty=True)
Expand Down Expand Up @@ -1475,7 +1484,6 @@ def test_all(self):
"""Test info() by comparing its results with the results of specific
consolidated accessor functions.
"""

def _test_all(info, best=False, pretty=False):
self.assertEqual(info['id'],
_distro.id(),
Expand Down

0 comments on commit 8054c8e

Please sign in to comment.