示例#1
0
def test_rpmmacro_constructor(patches, overwrite, kwargs):
    rpmmacro = (sign.RPMMacro("HOME", overwrite=overwrite, **kwargs)
                if overwrite != [] else sign.RPMMacro("HOME", **kwargs))
    assert rpmmacro._macro_filename == ".rpmmacros"
    assert rpmmacro.home == "HOME"
    assert rpmmacro.overwrite == bool(overwrite or False)
    assert rpmmacro.kwargs == kwargs
    assert rpmmacro.template == sign.RPMMACRO_TEMPLATE
示例#2
0
def test_rpmmacro_write(patches, overwrite, exists):
    rpmmacro = sign.RPMMacro("HOME")
    patched = patches("open",
                      "os",
                      ("RPMMacro.macro", dict(new_callable=PropertyMock)),
                      ("RPMMacro.path", dict(new_callable=PropertyMock)),
                      prefix="tools.distribution.sign")
    rpmmacro.overwrite = overwrite

    with patched as (m_open, m_os, m_macro, m_path):
        m_os.path.exists.return_value = exists
        assert not rpmmacro.write()

    if not overwrite:
        assert (list(m_os.path.exists.call_args) == [(m_path.return_value, ),
                                                     {}])
    else:
        assert not m_os.path.join.called
        assert not m_os.exists.join.called

    if not overwrite and exists:
        assert not m_open.called
        return

    assert (list(m_open.call_args) == [(m_path.return_value, 'w'), {}])
    assert (list(
        m_open.return_value.__enter__.return_value.write.call_args) == [
            (m_macro.return_value, ), {}
        ])
示例#3
0
def test_rpmmacro_path(patches):
    rpmmacro = sign.RPMMacro("HOME")
    patched = patches("os", prefix="tools.distribution.sign")
    with patched as (m_os, ):
        assert rpmmacro.path == m_os.path.join.return_value

    assert (list(m_os.path.join.call_args) == [('HOME',
                                                rpmmacro._macro_filename), {}])
示例#4
0
文件: test_sign.py 项目: su225/envoy
def test_rpmmacro_path(patches):
    rpmmacro = sign.RPMMacro("HOME")
    patched = patches(
        ("RPMMacro.home", dict(new_callable=PropertyMock)),
        prefix="tools.distribution.sign")
    with patched as (m_home, ):
        assert rpmmacro.path == m_home.return_value.joinpath.return_value

    assert (
        list(m_home.return_value.joinpath.call_args)
        == [(rpmmacro._macro_filename, ), {}])
示例#5
0
文件: test_sign.py 项目: su225/envoy
def test_rpmmacro_home(patches):
    rpmmacro = sign.RPMMacro("HOME")
    patched = patches(
        "pathlib",
        prefix="tools.distribution.sign")
    with patched as (m_plib, ):
        assert rpmmacro.home == m_plib.Path.return_value

    assert (
        list(m_plib.Path.call_args)
        == [(rpmmacro._home,), {}])
示例#6
0
def test_rpmmacro_macro(patches, kwargs):
    rpmmacro = sign.RPMMacro("HOME", **kwargs)
    patched = patches(("RPMMacro.template", dict(new_callable=PropertyMock)),
                      prefix="tools.distribution.sign")
    with patched as (m_template, ):
        result = rpmmacro.macro

    expected = m_template.return_value
    for k, v in kwargs.items():
        assert (list(expected.replace.call_args) == [(f"__{k.upper()}__", v),
                                                     {}])
        expected = expected.replace.return_value

    assert result == expected
    assert "macro" not in rpmmacro.__dict__