Esempio n. 1
0
 def sandbox_patch(self, monkeypatch):
     info = version.DistributionInfo(
         id='org.kde.Platform',
         parsed=version.Distribution.kde_flatpak,
         version=utils.parse_version('5.12'),
         pretty='Unknown')
     monkeypatch.setattr(version, 'distribution', lambda: info)
Esempio n. 2
0
def test_version_info(params, stubs, monkeypatch, config_stub):
    """Test version.version_info()."""
    config.instance.config_py_loaded = params.config_py_loaded
    import_path = pathlib.Path('/IMPORTPATH').resolve()

    patches = {
        'qutebrowser.__file__': str(import_path / '__init__.py'),
        'qutebrowser.__version__': 'VERSION',
        '_git_str': lambda: ('GIT COMMIT' if params.git_commit else None),
        'platform.python_implementation': lambda: 'PYTHON IMPLEMENTATION',
        'platform.python_version': lambda: 'PYTHON VERSION',
        'sys.executable': 'EXECUTABLE PATH',
        'PYQT_VERSION_STR': 'PYQT VERSION',
        'earlyinit.qt_version': lambda: 'QT VERSION',
        '_module_versions': lambda: ['MODULE VERSION 1', 'MODULE VERSION 2'],
        '_pdfjs_version': lambda: 'PDFJS VERSION',
        'QSslSocket': FakeQSslSocket('SSL VERSION', params.ssl_support),
        'platform.platform': lambda: 'PLATFORM',
        'platform.architecture': lambda: ('ARCHITECTURE', ''),
        '_os_info': lambda: ['OS INFO 1', 'OS INFO 2'],
        '_path_info': lambda: {'PATH DESC': 'PATH NAME'},
        'objects.qapp': (stubs.FakeQApplication(style='STYLE', platform_name='PLATFORM')
                         if params.qapp else None),
        'QLibraryInfo.location': (lambda _loc: 'QT PATH'),
        'sql.version': lambda: 'SQLITE VERSION',
        '_uptime': lambda: datetime.timedelta(hours=1, minutes=23, seconds=45),
        'config.instance.yaml_loaded': params.autoconfig_loaded,
    }

    version.opengl_info.cache_clear()
    monkeypatch.setenv('QUTE_FAKE_OPENGL', 'VENDOR, 1.0 VERSION')

    substitutions = {
        'git_commit': '\nGit commit: GIT COMMIT' if params.git_commit else '',
        'style': '\nStyle: STYLE' if params.qapp else '',
        'platform_plugin': ('\nPlatform plugin: PLATFORM' if params.qapp
                            else ''),
        'opengl': '\nOpenGL: VENDOR, 1.0 VERSION' if params.qapp else '',
        'qt': 'QT VERSION',
        'frozen': str(params.frozen),
        'import_path': import_path,
        'python_path': 'EXECUTABLE PATH',
        'uptime': "1:23:45",
        'autoconfig_loaded': "yes" if params.autoconfig_loaded else "no",
    }

    patches['qtwebengine_versions'] = (
        lambda avoid_init: version.WebEngineVersions(
            webengine=utils.VersionNumber(1, 2, 3),
            chromium=None,
            source='faked',
        )
    )

    if params.config_py_loaded:
        substitutions["config_py_loaded"] = "{} has been loaded".format(
            standarddir.config_py())
    else:
        substitutions["config_py_loaded"] = "no config.py was loaded"

    if params.with_webkit:
        patches['qWebKitVersion'] = lambda: 'WEBKIT VERSION'
        patches['objects.backend'] = usertypes.Backend.QtWebKit
        substitutions['backend'] = 'new QtWebKit (WebKit WEBKIT VERSION)'
    else:
        monkeypatch.delattr(version, 'qtutils.qWebKitVersion', raising=False)
        patches['objects.backend'] = usertypes.Backend.QtWebEngine
        substitutions['backend'] = 'QtWebEngine 1.2.3 (from faked)'

    if params.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'

    substitutions['ssl'] = 'SSL VERSION' if params.ssl_support else 'no'

    for name, val in patches.items():
        monkeypatch.setattr(f'qutebrowser.utils.version.{name}', val)

    if params.frozen:
        monkeypatch.setattr(sys, 'frozen', True, raising=False)
    else:
        monkeypatch.delattr(sys, 'frozen', raising=False)

    template = version._LOGO.lstrip('\n') + textwrap.dedent("""
        qutebrowser vVERSION{git_commit}
        Backend: {backend}
        Qt: {qt}

        PYTHON IMPLEMENTATION: PYTHON VERSION
        PyQt: PYQT VERSION

        MODULE VERSION 1
        MODULE VERSION 2
        pdf.js: PDFJS VERSION
        sqlite: SQLITE VERSION
        QtNetwork SSL: {ssl}
        {style}{platform_plugin}{opengl}
        Platform: PLATFORM, ARCHITECTURE{linuxdist}
        Frozen: {frozen}
        Imported from {import_path}
        Using Python from {python_path}
        Qt library executable path: QT PATH, data path: QT PATH
        {osinfo}
        Paths:
        PATH DESC: PATH NAME

        Autoconfig loaded: {autoconfig_loaded}
        Config.py: {config_py_loaded}
        Uptime: {uptime}
    """.lstrip('\n'))

    expected = template.rstrip('\n').format(**substitutions)
    assert version.version_info() == expected
Esempio n. 3
0
from qutebrowser.utils import version, usertypes, utils, standarddir
from qutebrowser.misc import pastebin, objects, elf
from qutebrowser.browser import pdfjs

try:
    from qutebrowser.browser.webengine import webenginesettings
except ImportError:
    webenginesettings = None


@pytest.mark.parametrize('os_release, expected', [
    # No file
    (None, None),
    # Invalid file
    ("\n# foo\n foo=bar=baz",
     version.DistributionInfo(id=None, parsed=version.Distribution.unknown,
                              version=None, pretty='Unknown')),
    # Archlinux
    ("""
        NAME="Arch Linux"
        PRETTY_NAME="Arch Linux"
        ID=arch
        ID_LIKE=archlinux
        ANSI_COLOR="0;36"
        HOME_URL="https://www.archlinux.org/"
        SUPPORT_URL="https://bbs.archlinux.org/"
        BUG_REPORT_URL="https://bugs.archlinux.org/"
     """,
     version.DistributionInfo(
         id='arch', parsed=version.Distribution.arch, version=None,
         pretty='Arch Linux')),
    # Ubuntu 14.04
Esempio n. 4
0
def test_version_output(params, stubs, monkeypatch):
    """Test version.version()."""
    class FakeWebEngineProfile:
        def httpUserAgent(self):
            return 'Toaster/4.0.4 Chrome/CHROMIUMVERSION Teapot/4.1.8'

    import_path = os.path.abspath('/IMPORTPATH')
    patches = {
        'qutebrowser.__file__':
        os.path.join(import_path, '__init__.py'),
        'qutebrowser.__version__':
        'VERSION',
        '_git_str':
        lambda: ('GIT COMMIT' if params.git_commit else None),
        'platform.python_implementation':
        lambda: 'PYTHON IMPLEMENTATION',
        'platform.python_version':
        lambda: 'PYTHON VERSION',
        'sys.executable':
        'EXECUTABLE PATH',
        'PYQT_VERSION_STR':
        'PYQT VERSION',
        'earlyinit.qt_version':
        lambda: 'QT VERSION',
        '_module_versions':
        lambda: ['MODULE VERSION 1', 'MODULE VERSION 2'],
        '_pdfjs_version':
        lambda: 'PDFJS VERSION',
        'QSslSocket':
        FakeQSslSocket('SSL VERSION', params.ssl_support),
        'platform.platform':
        lambda: 'PLATFORM',
        'platform.architecture':
        lambda: ('ARCHITECTURE', ''),
        '_os_info':
        lambda: ['OS INFO 1', 'OS INFO 2'],
        '_path_info':
        lambda: {
            'PATH DESC': 'PATH NAME'
        },
        'QApplication': (stubs.FakeQApplication(style='STYLE') if params.style
                         else stubs.FakeQApplication(instance=None)),
        'QLibraryInfo.location': (lambda _loc: 'QT PATH'),
        'sql.version':
        lambda: 'SQLITE VERSION',
        '_uptime':
        lambda: datetime.timedelta(hours=1, minutes=23, seconds=45),
    }

    substitutions = {
        'git_commit': '\nGit commit: GIT COMMIT' if params.git_commit else '',
        'style': '\nStyle: STYLE' if params.style else '',
        'qt': 'QT VERSION',
        'frozen': str(params.frozen),
        'import_path': import_path,
        'python_path': 'EXECUTABLE PATH',
    }

    if params.with_webkit:
        patches['qWebKitVersion'] = lambda: 'WEBKIT VERSION'
        patches['objects.backend'] = usertypes.Backend.QtWebKit
        patches['QWebEngineProfile'] = None
        substitutions['backend'] = 'new QtWebKit (WebKit WEBKIT VERSION)'
    else:
        monkeypatch.delattr(version, 'qtutils.qWebKitVersion', raising=False)
        patches['objects.backend'] = usertypes.Backend.QtWebEngine
        patches['QWebEngineProfile'] = FakeWebEngineProfile
        substitutions['backend'] = 'QtWebEngine (Chromium CHROMIUMVERSION)'

    if params.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'

    substitutions['ssl'] = 'SSL VERSION' if params.ssl_support else 'no'

    for name, val in patches.items():
        monkeypatch.setattr('qutebrowser.utils.version.' + name, val)

    if params.frozen:
        monkeypatch.setattr(sys, 'frozen', True, raising=False)
    else:
        monkeypatch.delattr(sys, 'frozen', raising=False)

    substitutions['uptime'] = "1:23:45"

    template = textwrap.dedent("""
        qutebrowser vVERSION{git_commit}
        Backend: {backend}

        PYTHON IMPLEMENTATION: PYTHON VERSION
        Qt: {qt}
        PyQt: PYQT VERSION

        MODULE VERSION 1
        MODULE VERSION 2
        pdf.js: PDFJS VERSION
        sqlite: SQLITE VERSION
        QtNetwork SSL: {ssl}
        {style}
        Platform: PLATFORM, ARCHITECTURE{linuxdist}
        Frozen: {frozen}
        Imported from {import_path}
        Using Python from {python_path}
        Qt library executable path: QT PATH, data path: QT PATH
        {osinfo}
        Paths:
        PATH DESC: PATH NAME

        Uptime: {uptime}
    """.lstrip('\n'))

    expected = template.rstrip('\n').format(**substitutions)
    assert version.version() == expected
Esempio n. 5
0
import qutebrowser
from qutebrowser.utils import version, usertypes, utils
from qutebrowser.misc import pastebin
from qutebrowser.browser import pdfjs


@pytest.mark.parametrize(
    'os_release, expected',
    [
        # No file
        (None, None),
        # Invalid file
        ("\n# foo\n foo=bar=baz",
         version.DistributionInfo(id=None,
                                  parsed=version.Distribution.unknown,
                                  version=None,
                                  pretty='Unknown')),
        # Archlinux
        ("""
        NAME="Arch Linux"
        PRETTY_NAME="Arch Linux"
        ID=arch
        ID_LIKE=archlinux
        ANSI_COLOR="0;36"
        HOME_URL="https://www.archlinux.org/"
        SUPPORT_URL="https://bbs.archlinux.org/"
        BUG_REPORT_URL="https://bugs.archlinux.org/"
     """,
         version.DistributionInfo(id='arch',
                                  parsed=version.Distribution.arch,
                                  version=None,
Esempio n. 6
0
import qutebrowser
from qutebrowser.config import config
from qutebrowser.utils import version, usertypes, utils, standarddir
from qutebrowser.misc import pastebin, objects
from qutebrowser.browser import pdfjs


@pytest.mark.parametrize(
    'os_release, expected',
    [
        # No file
        (None, None),
        # Invalid file
        ("\n# foo\n foo=bar=baz",
         version.DistributionInfo(id=None,
                                  parsed=version.Distribution.unknown,
                                  version=None,
                                  pretty='Unknown')),
        # Archlinux
        ("""
        NAME="Arch Linux"
        PRETTY_NAME="Arch Linux"
        ID=arch
        ID_LIKE=archlinux
        ANSI_COLOR="0;36"
        HOME_URL="https://www.archlinux.org/"
        SUPPORT_URL="https://bbs.archlinux.org/"
        BUG_REPORT_URL="https://bugs.archlinux.org/"
     """,
         version.DistributionInfo(id='arch',
                                  parsed=version.Distribution.arch,
                                  version=None,