Skip to content

Commit

Permalink
test: move_back option support
Browse files Browse the repository at this point in the history
  • Loading branch information
karitra committed Jul 2, 2019
1 parent 3c80cbb commit 0adbb7e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
10 changes: 10 additions & 0 deletions tests/test_blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,13 @@ def test_create_valid(mocked_open, mocked_exists):
def test_create_incorrect_path():
"""Test Blob.create static method with incorrect path."""
eblob_kit.Blob.create('')


@mock.patch('eblob_kit.Blob', autospec=True)
def test_blob_managed_close(mocked_blob):
"""Test blob context manager."""
mocked_blob.create.return_value = mocked_blob
with eblob_kit.managed_blob(''):
pass

assert mocked_blob.close.call_count == 1
14 changes: 10 additions & 4 deletions tests/test_blob_repairer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"""
import mock
import pytest
import sys

from eblob_kit import BlobRepairer
from eblob_kit import EllipticsHeader
Expand Down Expand Up @@ -418,7 +417,7 @@ def test_check_index_non_valid(_mocked_exists,
@mock.patch('eblob_kit.is_destination_writable', return_value=True)
@mock.patch(OPEN_TO_PATCH, new_callable=mock.mock_open)
@mock.patch('eblob_kit.Blob', autospec=True)
def test_fix_destination_writable(_mocked_blob,
def test_fix_destination_writable(mocked_blob,
_mocked_open,
_mocked_is_writable,
callee):
Expand All @@ -427,6 +426,9 @@ def test_fix_destination_writable(_mocked_blob,
Checks for `copy_valid_records`, `recover_index` and `recover_blob`.
"""
mocked_blob.create.return_value = mocked_blob
mocked_blob.get_index_data_path_tuple.return_value = (None, None)

blob_repairer = BlobRepairer('.')

if callee == BlobRepairer.recover_index:
Expand Down Expand Up @@ -477,10 +479,14 @@ def test_fix(mocker):
type(index_file_class.return_value).sorted = mocker.PropertyMock(return_value=False)

# DataFile mock
data_file_class = mocker.patch('eblob_kit.DataFile', autospec=True)
mocker.patch('eblob_kit.DataFile', autospec=True)

# Blob mock
mocker.patch('eblob_kit.Blob.create', )
mocked_blob = mock.Mock()
mocked_blob.create.return_value = mocked_blob
mocked_blob.get_index_data_path_tuple.return_value = (None, None)

mocker.patch('eblob_kit.Blob.create', return_value=mocked_blob)
mocker.patch('eblob_kit.is_destination_writable', return_value=True)

mocker.patch('os.path.exists', return_value=True)
Expand Down
10 changes: 10 additions & 0 deletions tests/test_index_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,13 @@ def test_create_invalid_path():
def test_create_incorrect_path():
"""Test IndexFile.create static method with incorrect path."""
eblob_kit.IndexFile.create('some/path/to/index')


@mock.patch('eblob_kit.IndexFile', autospec=True)
def test_index_managed_close(mocked_index):
"""Test index context manager."""
mocked_index.create.return_value = mocked_index
with eblob_kit.managed_index(''):
pass

mocked_index.create.return_value = mocked_index

0 comments on commit 0adbb7e

Please sign in to comment.