コード例 #1
0
ファイル: test_cli.py プロジェクト: omunroe-com/debmonitor
def test_parse_dpkg_hook_wrong_version():
    """Calling parse_dpkg_hook() with an unsupported version line should raise RuntimeError."""
    input_lines = [
        'VERSION 4\n',
        'APT::Architecture=amd64\n',
    ]
    with pytest.raises(RuntimeError, match='Unsupported version'):
        cli.parse_dpkg_hook(input_lines)
コード例 #2
0
ファイル: test_cli.py プロジェクト: omunroe-com/debmonitor
def test_parse_dpkg_hook_no_version():
    """Calling parse_dpkg_hook() with a wrongly formatted version line should raise RuntimeError."""
    with pytest.raises(RuntimeError,
                       match='Expected VERSION line to be the first one'):
        input_lines = [
            'VER 1\n',
            'APT::Architecture=amd64\n',
        ]
        cli.parse_dpkg_hook(input_lines)
コード例 #3
0
ファイル: test_cli.py プロジェクト: omunroe-com/debmonitor
def test_parse_dpkg_hook_no_separator():
    """Calling parse_dpkg_hook() with no empty separator should raise a RuntimeError."""
    input_lines = [
        'VERSION 3\n',
        'APT::Architecture=amd64\n',
    ]
    with pytest.raises(
            RuntimeError,
            match='Unable to find the empty line separator in input'):
        cli.parse_dpkg_hook(input_lines)
コード例 #4
0
ファイル: test_cli.py プロジェクト: omunroe-com/debmonitor
def test_parse_dpkg_hook_no_packages():
    """Calling parse_dpkg_hook() with no update lines should return an empty dictionary."""
    input_lines = [
        'VERSION 3\n',
        'APT::Architecture=amd64\n',
        '\n',
    ]
    assert cli.parse_dpkg_hook(input_lines) == {}
コード例 #5
0
ファイル: test_cli.py プロジェクト: omunroe-com/debmonitor
def test_parse_dpkg_hook(version, apt_line):
    """Calling parse_dpkg_hook() should parse the list of packages reported by a Dpkg::Pre-Install-Pkgs hook."""
    mocked_apt.cache.Cache().__getitem__.return_value = apt_line[2]
    input_lines = _get_dpkg_hook_preamble(
        version) + APT_HOOK_LINES[version][apt_line[0]:apt_line[1]]

    packages = cli.parse_dpkg_hook(input_lines)

    expected_packages = {'installed': [], 'upgradable': [], 'uninstalled': []}
    package = {'name': 'package-name', 'version': '', 'source': 'package-name'}
    if apt_line[0] == 2:
        pass  # Re-installed package, no changes
    elif apt_line[0] == 8:
        package['version'] = apt_line[2].installed.version
        expected_packages['uninstalled'].append(package)
    else:
        package['version'] = apt_line[2].candidate.version
        expected_packages['installed'].append(package)

    assert packages == expected_packages