示例#1
0
Functional tests for PyGObject.
"""

from PyInstaller.utils.tests import importorskip, parametrize

# Names of all "gi.repository" packages provided by PyGObject  to be
# tested below, typically corresponding to those packages hooked by PyInstaller.
gi_repositories = [('Gst', '1.0'), ('GLib', '2.0'), ('GModule', '2.0'),
                   ('GObject', '2.0'), ('GdkPixbuf', '2.0'), ('Gio', '2.0'),
                   ('Clutter', '1.0'), ('GtkClutter', '1.0'),
                   ('Champlain', '0.12'), ('GtkChamplain', '0.12')]
gi_repository_names = [x[0] for x in gi_repositories]

# Names of the same packages, decorated to be skipped if unimportable.
gi_repositories_skipped_if_unimportable = [
    importorskip('gi.repository.' + gi_repository_name)(
        (gi_repository_name, gi_repository_version))
    for gi_repository_name, gi_repository_version in gi_repositories
]


# Test the usability of "gi.repository" packages provided by PyGObject.
@importorskip('gi.repository')
@parametrize(
    ('repository_name', 'version'),
    gi_repositories_skipped_if_unimportable,
    # Ensure human-readable test parameter names.
    ids=gi_repository_names)
def test_gi_repository(pyi_builder, repository_name, version):
    '''
    Test the importability of the `gi.repository` subpackage with the passed
    name installed with PyGObject (e.g., `GLib`, corresponding to the
示例#2
0
#   this backend or "None" if no parameter is to be set.
# * "rcParams_value" is the value to set that parameter to if "rcParams_key" is
#   not "None" or ignored otherwise.
backend_rcParams_key_values = [
    # PySide.
    ('Qt4Agg', 'PySide', 'backend.qt4', 'PySide'),
    # PyQt4.
    ('Qt4Agg', 'PyQt4', 'backend.qt4', 'PyQt4'),
    # PyQt5.
    ('Qt5Agg', 'PyQt5', 'backend.qt5', 'PyQt5'),
]

# Same list, decorated to skip all backends whose packages are unimportable#.
backend_rcParams_key_values_skipped_if_unimportable = [
    pytest.param(*backend_rcParams_key_value,
                 marks=importorskip(backend_rcParams_key_value[1]))
    for backend_rcParams_key_value in backend_rcParams_key_values
]

print(backend_rcParams_key_values_skipped_if_unimportable)

# Names of all packages required by backends listed above.
package_names = [
    backend_rcParams_key_value[1]
    for backend_rcParams_key_value in backend_rcParams_key_values
]


# Test Matplotlib with access to only one backend at a time.
@importorskip('matplotlib')
@pytest.mark.parametrize(
        #     AttributeError: 'module' object has no attribute 'listenTCP'
        #
        # Ensure default reactor was loaded - it has method 'listenTCP' to start server.
        if not hasattr(reactor, 'listenTCP'):
            raise SystemExit('Twisted reactor not properly initialized.')
        """)


# matplotlib tries to import any of PyQt4, PyQt5 or PySide. But if we
# have more then one of these in the frozen app, the app's
# runtime-hooks will crash. Thus we need to exclude the other two.
all_qt_pkgs = ['PyQt4', 'PyQt5', 'PySide']
excludes = []
for pkg in all_qt_pkgs:
    p = [p for p in all_qt_pkgs]
    p = importorskip(pkg)(p)
    excludes.append(p)


@importorskip('matplotlib')
@pytest.mark.parametrize("excludes", excludes, ids=all_qt_pkgs)
def test_matplotlib(pyi_builder, excludes):
    pyi_args = ['--exclude-module=%s' % e for e in excludes]
    pyi_builder.test_source("""
        import os
        import matplotlib
        import sys
        import tempfile
        # In frozen state rthook should force matplotlib to create config directory
        # in temp directory and not $HOME/.matplotlib.
        configdir = os.environ['MPLCONFIGDIR']
示例#4
0
Functional tests for PyGObject.
"""

from PyInstaller.utils.tests import importorskip, parametrize

# Names of all "gi.repository" packages provided by PyGObject  to be
# tested below, typically corresponding to those packages hooked by PyInstaller.
gi_repositories = [('Gst', '1.0'), ('GLib', '2.0'), ('GModule', '2.0'),
                   ('GObject', '2.0'), ('GdkPixbuf', '2.0'), ('Gio', '2.0'),
                   ('Clutter', '1.0'), ('GtkClutter', '1.0'),
                   ('Champlain', '0.12'), ('GtkChamplain', '0.12')]
gi_repository_names = [x[0] for x in gi_repositories]

# Names of the same packages, decorated to be skipped if unimportable.
gi_repositories_skipped_if_unimportable = [
    importorskip('gi.repository.' + gi_repository_name)
    ((gi_repository_name, gi_repository_version))
    for gi_repository_name, gi_repository_version in gi_repositories
]


# Test the usability of "gi.repository" packages provided by PyGObject.
@importorskip('gi.repository')
@parametrize(
    ('repository_name', 'version'),
    gi_repositories_skipped_if_unimportable,
    # Ensure human-readable test parameter names.
    ids=gi_repository_names)
def test_gi_repository(pyi_builder, repository_name, version):
    '''
    Test the importability of the `gi.repository` subpackage with the passed
    name installed with PyGObject (e.g., `GLib`, corresponding to the
示例#5
0
## For PyGObject >= 2.0

# Names of all "gi.repository" packages provided by PyGObject >= 2.0 to be
# tested below, typically corresponding to those packages hooked by PyInstaller.
gi2_repository_names = [
    'GLib',
    'GModule',
    'GObject',
    'GdkPixbuf',
    'Gio',
]

# Names of the same packages, decorated to be skipped if unimportable.
gi2_repository_names_skipped_if_unimportable = [
    importorskip('gi.repository.' + gi2_repository_name)(gi2_repository_name)
    for gi2_repository_name in gi2_repository_names
]


# Test the usability of "gi.repository" packages provided by PyGObject >= 2.0.
# For simplicity, these tests are parametrized as
# "test_gi2_repository[{one_type}-{repository_name}]" (e.g.,
# "test_gi2_repository[onedir-GdkPixbuf]").
@importorskip('gi.repository')
@parametrize(
    'repository_name',
    gi2_repository_names_skipped_if_unimportable,
    # Ensure human-readable test parameter names.
    ids=gi2_repository_names)
def test_gi2_repository(pyi_builder, repository_name):
示例#6
0
from PyInstaller.utils.tests import importorskip, parametrize

# Names of all "gi.repository" packages provided by PyGObject  to be
# tested below, typically corresponding to those packages hooked by PyInstaller.
gi_repositories = [('Gst', '1.0'), ('GLib', '2.0'), ('GModule', '2.0'),
                   ('GObject', '2.0'), ('GdkPixbuf', '2.0'), ('Gio', '2.0'),
                   ('Clutter', '1.0'), ('GtkClutter', '1.0'),
                   ('Champlain', '0.12'), ('GtkChamplain', '0.12')]
gi_repository_names = [x[0] for x in gi_repositories]

# Names of the same packages, decorated to be skipped if unimportable.
gi_repositories_skipped_if_unimportable = [
    pytest.param(gi_repository_name,
                 gi_repository_version,
                 marks=importorskip('gi.repository.' + gi_repository_name))
    for gi_repository_name, gi_repository_version in gi_repositories
]


# Test the usability of "gi.repository" packages provided by PyGObject.
@importorskip('gi.repository')
@parametrize(
    ('repository_name', 'version'),
    gi_repositories_skipped_if_unimportable,
    # Ensure human-readable test parameter names.
    ids=gi_repository_names)
def test_gi_repository(pyi_builder, repository_name, version):
    '''
    Test the importability of the `gi.repository` subpackage with the passed
    name installed with PyGObject (e.g., `GLib`, corresponding to the
# * "rcParams_key" is the name of a Matplotlib parameter to be set before testing
#   this backend or "None" if no parameter is to be set.
# * "rcParams_value" is the value to set that parameter to if "rcParams_key" is
#   not "None" or ignored otherwise.
backend_rcParams_key_values = [
    # PySide.
    ('Qt4Agg', 'PySide', 'backend.qt4', 'PySide'),
    # PyQt4.
    ('Qt4Agg', 'PyQt4', 'backend.qt4', 'PyQt4'),
    # PyQt5.
    ('Qt5Agg', 'PyQt5', 'backend.qt5', 'PyQt5'),
]

# Same list, decorated to skip all backends whose packages are unimportable.
backend_rcParams_key_values_skipped_if_unimportable = [
    importorskip(backend_rcParams_key_value[1])(backend_rcParams_key_value)
    for backend_rcParams_key_value in backend_rcParams_key_values
]

# Names of all packages required by backends listed above.
package_names = [
    backend_rcParams_key_value[1]
    for backend_rcParams_key_value in backend_rcParams_key_values
]

# Test Matplotlib with access to only one backend at a time.
@importorskip('matplotlib')
@pytest.mark.parametrize(
    'backend_name, package_name, rcParams_key, rcParams_value',
    backend_rcParams_key_values_skipped_if_unimportable,
    ids=package_names)
示例#8
0
        gi.require_version('Gst', '1.0')
        from gi.repository import Gst
        Gst.init(None)
        print(Gst)
    ''')


## For PyGObject >= 2.0

# Names of all "gi.repository" packages provided by PyGObject >= 2.0 to be
# tested below, typically corresponding to those packages hooked by PyInstaller.
gi2_repository_names = ['GLib', 'GModule', 'GObject', 'GdkPixbuf', 'Gio',]

# Names of the same packages, decorated to be skipped if unimportable.
gi2_repository_names_skipped_if_unimportable = [
    importorskip('gi.repository.' + gi2_repository_name)(gi2_repository_name)
    for gi2_repository_name in gi2_repository_names
]

# Test the usability of "gi.repository" packages provided by PyGObject >= 2.0.
# For simplicity, these tests are parametrized as
# "test_gi2_repository[{one_type}-{repository_name}]" (e.g.,
# "test_gi2_repository[onedir-GdkPixbuf]").
@importorskip('gi.repository')
@parametrize(
    'repository_name',
    gi2_repository_names_skipped_if_unimportable,
    # Ensure human-readable test parameter names.
    ids=gi2_repository_names)
def test_gi2_repository(pyi_builder, repository_name):
    '''
示例#9
0
        #
        # Ensure default reactor was loaded - it has method 'listenTCP' to start server.
        if not hasattr(reactor, 'listenTCP'):
            raise SystemExit('Twisted reactor not properly initialized.')
        """
    )


# matplotlib tries to import any of PyQt4, PyQt5 or PySide. But if we
# have more then one of these in the frozen app, the app's
# runtime-hooks will crash. Thus we need to exclude the other two.
all_qt_pkgs = ["PyQt4", "PyQt5", "PySide"]
excludes = []
for pkg in all_qt_pkgs:
    p = [p for p in all_qt_pkgs]
    p = importorskip(pkg)(p)
    excludes.append(p)


@importorskip("matplotlib")
@pytest.mark.parametrize("excludes", excludes, ids=all_qt_pkgs)
def test_matplotlib(pyi_builder, excludes):
    pyi_args = ["--exclude-module=%s" % e for e in excludes]
    pyi_builder.test_source(
        """
        import os
        import matplotlib
        import sys
        import tempfile
        # In frozen state rthook should force matplotlib to create config directory
        # in temp directory and not $HOME/.matplotlib.