Пример #1
0
def test_create_dir_link(mocker, tmp_path):
    """Should create a symlink or directory junction if needed"""
    targ_path = tmp_path / "target_dir"
    targ_path.mkdir()
    link_path = tmp_path / "link_path"
    mock_sys = mocker.patch.object(utils.helpers, "sys")
    mock_platform = type(mock_sys).platform = mocker.PropertyMock()
    mock_subproc = mocker.patch.object(utils.helpers, "subproc")
    mock_path = mocker.patch.object(utils.helpers, "Path").return_value
    mock_path.symlink_to.side_effect = [mocker.ANY, OSError, OSError, OSError]

    mock_platform.return_value = "linux"
    # Test POSIX (should not raise exception)
    utils.create_dir_link(link_path, targ_path)
    mock_path.symlink_to.assert_called_once()
    assert mock_subproc.call_count == 0
    # Test POSIX failed for unknown reason
    with pytest.raises(OSError):
        utils.create_dir_link(link_path, targ_path)
    # Test Windows (should try to make symlink, fallback on DJ)
    mock_platform.return_value = "win32"
    mock_subproc.call.return_value = 0
    utils.create_dir_link(link_path, targ_path)
    assert mock_subproc.call.call_count == 1
    # Test Windows fails for some reason
    mock_subproc.call.return_value = 1
    with pytest.raises(OSError):
        utils.create_dir_link(link_path, targ_path)
Пример #2
0
    def resolve_link(cls, stub, link_path):
        """Resolve or Create Stub Symlink

        Args:
            stub (Stub): stub to resolve
            link_path (str): path to link

        Returns:
            Stub: Stub from symlink
        """
        fware = stub.firmware
        if utils.is_dir_link(link_path):
            return cls(link_path, firmware=fware)
        utils.create_dir_link(link_path, stub.path)
        return cls(link_path, firmware=fware)