def test__parse_data__too_short_error(mocker):
    """
    Test "_parse_data" method must exit with too short response error.
    """

    out = StringIO()
    mocker.patch("sys.argv",
                 ["check_hddtemp.py", "-s", "127.0.0.1", "-p", "7634"])
    checker = CheckHDDTemp()

    with pytest.raises(SystemExit):
        with contextlib2.redirect_stdout(out):
            checker._parse_data(data="")

    assert "ERROR: Server response too short" in out.getvalue().strip(
    )  # nosec: B101
def test__parse_data__parsing_error(mocker):
    """
    Test "_parse_data" method must exit with parsing error.
    """

    out = StringIO()
    mocker.patch("sys.argv",
                 ["check_hddtemp.py", "-s", "127.0.0.1", "-p", "7634"])
    checker = CheckHDDTemp()

    with pytest.raises(SystemExit):
        with contextlib2.redirect_stdout(out):
            checker._parse_data(data="|/dev/sda|HARD DRIVE|C|")  # noqa: E501

    assert "ERROR: Server response for device" in out.getvalue().strip(
    )  # nosec: B101
def test__parse_data(mocker):
    """
    Test "_parse_data" method must return structured data.
    """

    expected = {
        "/dev/sda": {
            "model": "HARD DRIVE",
            "temperature": "27",
            "scale": "C"
        },
    }
    mocker.patch("sys.argv",
                 ["check_hddtemp.py", "-s", "127.0.0.1", "-p", "7634"])
    checker = CheckHDDTemp()
    result = checker._parse_data(
        data="|/dev/sda|HARD DRIVE|27|C|")  # noqa: E501

    assert result == expected  # nosec: B101