From aa8e6c8d177daaa7227e2134f3ff9c3005559575 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sat, 20 May 2017 23:22:56 +0200 Subject: [PATCH] Add parsed distribution to version info Fixes #2369 --- qutebrowser/utils/version.py | 12 +++++++++- tests/unit/utils/test_version.py | 40 +++++++++++++++++++++----------- 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/qutebrowser/utils/version.py b/qutebrowser/utils/version.py index 14f9099dd..7b44fed7e 100644 --- a/qutebrowser/utils/version.py +++ b/qutebrowser/utils/version.py @@ -349,6 +349,14 @@ def version(): lines += [ 'Platform: {}, {}'.format(platform.platform(), platform.architecture()[0]), + ] + dist = distribution() + if dist is not None: + lines += [ + 'Linux distribution: {} ({})'.format(dist.pretty, dist.parsed.name) + ] + + lines += [ 'Frozen: {}'.format(hasattr(sys, 'frozen')), "Imported from {}".format(importpath), "Qt library executable path: {}, data path: {}".format( @@ -356,7 +364,9 @@ def version(): QLibraryInfo.location(QLibraryInfo.DataPath) ) ] - lines += _os_info() + + if not dist or dist.parsed == Distribution.unknown: + lines += _os_info() lines += [ '', diff --git a/tests/unit/utils/test_version.py b/tests/unit/utils/test_version.py index 70f3d1290..192ae92a7 100644 --- a/tests/unit/utils/test_version.py +++ b/tests/unit/utils/test_version.py @@ -809,16 +809,18 @@ def test_chromium_version_unpatched(qapp): assert version._chromium_version() not in ['', 'unknown', 'unavailable'] -@pytest.mark.parametrize(['git_commit', 'frozen', 'style', 'with_webkit'], [ - (True, False, True, True), # normal - (False, False, True, True), # no git commit - (True, True, True, True), # frozen - (True, True, False, True), # no style - (True, False, True, False), # no webkit - (True, False, True, 'ng'), # QtWebKit-NG +@pytest.mark.parametrize(['git_commit', 'frozen', 'style', 'with_webkit', + 'known_distribution'], [ + (True, False, True, True, True), # normal + (False, False, True, True, True), # no git commit + (True, True, True, True, True), # frozen + (True, True, False, True, True), # no style + (True, False, True, False, True), # no webkit + (True, False, True, 'ng', True), # QtWebKit-NG + (True, False, True, True, False), # unknown Linux distribution ]) -def test_version_output(git_commit, frozen, style, with_webkit, stubs, - monkeypatch): +def test_version_output(git_commit, frozen, style, with_webkit, + known_distribution, stubs, monkeypatch): """Test version.version().""" class FakeWebEngineProfile: def httpUserAgent(self): @@ -843,7 +845,7 @@ def test_version_output(git_commit, frozen, style, with_webkit, stubs, '_path_info': lambda: {'PATH DESC': 'PATH NAME'}, 'QApplication': (stubs.FakeQApplication(style='STYLE') if style else stubs.FakeQApplication(instance=None)), - 'QLibraryInfo.location': (lambda _loc: 'QT PATH') + 'QLibraryInfo.location': (lambda _loc: 'QT PATH'), } substitutions = { @@ -870,6 +872,18 @@ def test_version_output(git_commit, frozen, style, with_webkit, stubs, patches['QWebEngineProfile'] = FakeWebEngineProfile substitutions['backend'] = 'QtWebEngine (Chromium CHROMIUMVERSION)' + if known_distribution: + patches['distribution'] = lambda: version.DistributionInfo( + parsed=version.Distribution.arch, version=None, + pretty='LINUX DISTRIBUTION', id='arch') + substitutions['linuxdist'] = ('\nLinux distribution: ' + 'LINUX DISTRIBUTION (arch)') + substitutions['osinfo'] = '' + else: + patches['distribution'] = lambda: None + substitutions['linuxdist'] = '' + substitutions['osinfo'] = 'OS INFO 1\nOS INFO 2\n' + for attr, val in patches.items(): monkeypatch.setattr('qutebrowser.utils.version.' + attr, val) @@ -891,13 +905,11 @@ def test_version_output(git_commit, frozen, style, with_webkit, stubs, pdf.js: PDFJS VERSION SSL: SSL VERSION {style} - Platform: PLATFORM, ARCHITECTURE + Platform: PLATFORM, ARCHITECTURE{linuxdist} Frozen: {frozen} Imported from {import_path} Qt library executable path: QT PATH, data path: QT PATH - OS INFO 1 - OS INFO 2 - + {osinfo} Paths: PATH DESC: PATH NAME """.lstrip('\n'))