コード例 #1
0
def test_util_pkg_files(patches, files):
    packager = sign.PackageSigningRunner("x", "y", "z")
    maintainer = identity.GPGIdentity(packager)
    util = sign.DirectorySigningUtil("PATH", maintainer, "LOG")
    patched = patches(
        "os", ("DirectorySigningUtil.ext", dict(new_callable=PropertyMock)),
        prefix="tools.distribution.sign")
    with patched as (m_os, m_ext):
        m_ext.return_value = "EXT"
        m_os.listdir.return_value = files
        result = util.pkg_files

    expected = [fname for fname in files if fname.endswith(".EXT")]

    assert (list(m_os.listdir.call_args) == [("PATH", ), {}])
    if not expected:
        assert not m_os.path.join.called
        assert not result
    else:
        assert (result == tuple(m_os.path.join.return_value
                                for fname in expected))
        assert (list(list(c) for c in m_os.path.join.call_args_list) == [[
            ("PATH", fname), {}
        ] for fname in expected])

    assert "pkg_files" not in util.__dict__
コード例 #2
0
def test_util_package_type(ext, package_type):
    packager = sign.PackageSigningRunner("x", "y", "z")
    maintainer = identity.GPGIdentity(packager)
    util = sign.DirectorySigningUtil("PATH", maintainer, "LOG")
    util.ext = ext
    util._package_type = package_type
    assert util.package_type == package_type or ext
コード例 #3
0
ファイル: test_sign.py プロジェクト: su225/envoy
def test_util_pkg_files(patches, files):
    packager = sign.PackageSigningRunner("x", "y", "z")
    maintainer = identity.GPGIdentity(packager)
    util = sign.DirectorySigningUtil("PATH", maintainer, "LOG")
    patched = patches(
        ("DirectorySigningUtil.ext", dict(new_callable=PropertyMock)),
        ("DirectorySigningUtil.path", dict(new_callable=PropertyMock)),
        prefix="tools.distribution.sign")
    with patched as (m_ext, m_path):
        _glob = {}

        for _path in files:
            _mock = MagicMock()
            _mock.name = _path
            _glob[_path] = _mock
        m_path.return_value.glob.return_value = _glob.values()

        m_ext.return_value = "EXT"
        result = util.pkg_files

    expected = [fname for fname in files if fname.endswith(".EXT")]

    assert (
        list(m_path.return_value.glob.call_args)
        == [("*",), {}])
    assert "pkg_files" not in util.__dict__
    assert (
        result
        == tuple(_glob[k] for k in expected))
コード例 #4
0
def test_util_constructor(command):
    packager = sign.PackageSigningRunner("x", "y", "z")
    maintainer = identity.GPGIdentity(packager)
    args = ("PATH", maintainer, "LOG")
    if command is not None:
        args += (command, )
    util = sign.DirectorySigningUtil(*args)
    assert util.path == "PATH"
    assert util.maintainer == maintainer
    assert util.log == "LOG"
    assert util._command == (command or "")
    assert util.command_args == ()
コード例 #5
0
def test_util_sign_command(patches):
    packager = sign.PackageSigningRunner("x", "y", "z")
    maintainer = identity.GPGIdentity(packager)
    util = sign.DirectorySigningUtil("PATH", maintainer, "LOG")
    patched = patches(
        ("DirectorySigningUtil.command", dict(new_callable=PropertyMock)),
        ("DirectorySigningUtil.command_args", dict(new_callable=PropertyMock)),
        prefix="tools.distribution.sign")

    with patched as (m_command, m_args):
        m_args.return_value = ("ARG1", "ARG2", "ARG3")
        assert (util.sign_command("PACKAGE") == (m_command.return_value, ) +
                m_args.return_value + ("PACKAGE", ))
コード例 #6
0
ファイル: test_sign.py プロジェクト: su225/envoy
def test_util_path(patches):
    packager = sign.PackageSigningRunner("x", "y", "z")
    maintainer = identity.GPGIdentity(packager)
    util = sign.DirectorySigningUtil("PATH", maintainer, "LOG")
    patched = patches(
        "pathlib",
        prefix="tools.distribution.sign")
    with patched as (m_plib, ):
        assert util.path == m_plib.Path.return_value

    assert (
        list(m_plib.Path.call_args)
        == [(util._path,), {}])
コード例 #7
0
def test_util_sign(patches):
    packager = sign.PackageSigningRunner("x", "y", "z")
    maintainer = identity.GPGIdentity(packager)
    util = sign.DirectorySigningUtil("PATH", maintainer, "LOG")
    patched = patches(
        "DirectorySigningUtil.sign_pkg",
        ("DirectorySigningUtil.pkg_files", dict(new_callable=PropertyMock)),
        prefix="tools.distribution.sign")

    with patched as (m_sign, m_pkgs):
        m_pkgs.return_value = ("PKG1", "PKG2", "PKG3")
        assert not util.sign()

    assert (list(list(c) for c in m_sign.call_args_list) == [[('PKG1', ), {}],
                                                             [('PKG2', ), {}],
                                                             [('PKG3', ), {}]])
コード例 #8
0
def test_util_command(patches, command_name, command, which):
    packager = sign.PackageSigningRunner("x", "y", "z")
    maintainer = identity.GPGIdentity(packager)
    util = sign.DirectorySigningUtil("PATH",
                                     maintainer,
                                     "LOG",
                                     command=command)
    patched = patches(
        "shutil",
        ("DirectorySigningUtil.package_type", dict(new_callable=PropertyMock)),
        prefix="tools.distribution.sign")
    if command_name is not None:
        util.command_name = command_name

    with patched as (m_shutil, m_type):
        m_shutil.which.return_value = which

        if not which and not command:
            with pytest.raises(sign.SigningError) as e:
                util.command

            assert (list(m_shutil.which.call_args) == [(command_name, ), {}])
            assert (
                e.value.args[0] ==
                f"Signing software missing ({m_type.return_value}): {command_name}"
            )
            return

        result = util.command

    assert "command" in util.__dict__
    assert not m_type.called

    if command:
        assert not m_shutil.which.called
        assert result == command
        return

    assert (list(m_shutil.which.call_args) == [(command_name, ), {}])
    assert result == m_shutil.which.return_value
コード例 #9
0
def test_util_sign_pkg(patches, returncode):
    packager = sign.PackageSigningRunner("x", "y", "z")
    maintainer = identity.GPGIdentity(packager)
    util = sign.DirectorySigningUtil("PATH", maintainer, "LOG")
    patched = patches(
        "os",
        "subprocess",
        "DirectorySigningUtil.sign_command",
        ("PackageSigningRunner.log", dict(new_callable=PropertyMock)),
        ("DirectorySigningUtil.package_type", dict(new_callable=PropertyMock)),
        prefix="tools.distribution.sign")

    util.log = MagicMock()

    with patched as (m_os, m_subproc, m_command, m_log, m_type):
        m_subproc.run.return_value.returncode = returncode
        if returncode:
            with pytest.raises(sign.SigningError) as e:
                util.sign_pkg("PACKAGE")
        else:
            assert not util.sign_pkg("PACKAGE")

    assert (list(m_os.path.basename.call_args) == [('PACKAGE', ), {}])
    assert (list(util.log.notice.call_args) == [(
        f"Sign package ({m_type.return_value}): {m_os.path.basename.return_value}",
    ), {}])
    assert (list(m_command.call_args) == [('PACKAGE', ), {}])
    assert (list(m_subproc.run.call_args) == [(m_command.return_value, ), {
        'capture_output': True,
        'encoding': 'utf-8'
    }])

    if not returncode:
        assert (list(util.log.success.call_args) == [(
            f"Signed package ({m_type.return_value}): {m_os.path.basename.return_value}",
        ), {}])
        return
    assert e.value.args[
        0] == m_subproc.run.return_value.stdout + m_subproc.run.return_value.stderr