# Path: pyipmi/helper.py
# def clear_repository_helper(reserve_fn, clear_fn, retry=5, reservation=None):
#     """Helper function to start repository erasure and wait until finish.
# 
#     This helper is used by clear_sel and clear_sdr_repository.
#     """
#     if reservation is None:
#         reservation = reserve_fn()
# 
#     # start erasure
#     reservation = _clear_repository(reserve_fn, clear_fn,
#                                     constants.REPOSITORY_INITIATE_ERASE,
#                                     retry, reservation)
# 
#     # give some time to clear
#     time.sleep(0.5)
# 
#     # wait until finish
#     reservation = _clear_repository(reserve_fn, clear_fn,
#                                     constants.REPOSITORY_GET_ERASE_STATUS,
#                                     retry, reservation)
# 
# Path: pyipmi/msgs/constants.py
# REPOSITORY_ERASURE_COMPLETED = 0x1
# 
# REPOSITORY_ERASURE_IN_PROGRESS = 0x0
# 
# REPOSITORY_INITIATE_ERASE = 0xaa
# 
# REPOSITORY_GET_ERASE_STATUS = 0x00


from mock import MagicMock, call
from nose.tools import eq_
from pyipmi.helper import clear_repository_helper
from pyipmi.msgs.constants import (REPOSITORY_ERASURE_COMPLETED,
                                   REPOSITORY_ERASURE_IN_PROGRESS,
                                   REPOSITORY_INITIATE_ERASE,
                                   REPOSITORY_GET_ERASE_STATUS)
#!/usr/bin/env python
# -*- coding: utf-8 -*-




def test_clear_repository_helper():
    reserve_fn = MagicMock()
    reserve_fn.return_value = (0x1234)

    clear_fn = MagicMock()
    clear_fn.side_effect = [
        REPOSITORY_ERASURE_COMPLETED,
        REPOSITORY_ERASURE_IN_PROGRESS,
        REPOSITORY_ERASURE_COMPLETED,
    ]

    clear_repository_helper(reserve_fn, clear_fn)

    clear_calls = [
        call(REPOSITORY_INITIATE_ERASE, 0x1234),
        call(REPOSITORY_GET_ERASE_STATUS, 0x1234),

# Path: pyipmi/helper.py
# def clear_repository_helper(reserve_fn, clear_fn, retry=5, reservation=None):
#     """Helper function to start repository erasure and wait until finish.
# 
#     This helper is used by clear_sel and clear_sdr_repository.
#     """
#     if reservation is None:
#         reservation = reserve_fn()
# 
#     # start erasure
#     reservation = _clear_repository(reserve_fn, clear_fn,
#                                     constants.REPOSITORY_INITIATE_ERASE,
#                                     retry, reservation)
# 
#     # give some time to clear
#     time.sleep(0.5)
# 
#     # wait until finish
#     reservation = _clear_repository(reserve_fn, clear_fn,
#                                     constants.REPOSITORY_GET_ERASE_STATUS,
#                                     retry, reservation)
# 
# Path: pyipmi/msgs/constants.py
# REPOSITORY_ERASURE_COMPLETED = 0x1
# 
# REPOSITORY_ERASURE_IN_PROGRESS = 0x0
# 
# REPOSITORY_INITIATE_ERASE = 0xaa
# 
# REPOSITORY_GET_ERASE_STATUS = 0x00


# Path: tests/test_helper.py
from mock import MagicMock, call
from nose.tools import eq_
from pyipmi.helper import clear_repository_helper
from pyipmi.msgs.constants import (REPOSITORY_ERASURE_COMPLETED,
                                   REPOSITORY_ERASURE_IN_PROGRESS,
                                   REPOSITORY_INITIATE_ERASE,
                                   REPOSITORY_GET_ERASE_STATUS)

#!/usr/bin/env python
# -*- coding: utf-8 -*-




def test_clear_repository_helper():
    reserve_fn = MagicMock()
    reserve_fn.return_value = (0x1234)

    clear_fn = MagicMock()
    clear_fn.side_effect = [
        REPOSITORY_ERASURE_COMPLETED,
        REPOSITORY_ERASURE_IN_PROGRESS,
        REPOSITORY_ERASURE_COMPLETED,
    ]

    clear_repository_helper(reserve_fn, clear_fn)

    clear_calls = [
        call(REPOSITORY_INITIATE_ERASE, 0x1234),
        call(REPOSITORY_GET_ERASE_STATUS, 0x1234),

        call(REPOSITORY_GET_ERASE_STATUS, 0x1234),