diff --git a/.coveragerc b/.coveragerc index 28a86fc..d049606 100644 --- a/.coveragerc +++ b/.coveragerc @@ -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 \ No newline at end of file diff --git a/distro.py b/distro.py index 614cd3d..e33002a 100755 --- a/distro.py +++ b/distro.py @@ -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. diff --git a/tests/test_distro.py b/tests/test_distro.py index 8e9a981..f80c86f 100644 --- a/tests/test_distro.py +++ b/tests/test_distro.py @@ -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') @@ -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, @@ -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) @@ -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(),