Skip to content

Commit

Permalink
test: add is_sorted to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
karitra committed Aug 9, 2019
1 parent d238eba commit b985d9f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
7 changes: 1 addition & 6 deletions tests/test_blob_repairer.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,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 @@ -426,11 +426,6 @@ 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)

type(mocked_blob.return_value.data).path = mock.PropertyMock(return_value='data')

blob_repairer = BlobRepairer('.')

if callee == BlobRepairer.recover_index:
Expand Down
30 changes: 30 additions & 0 deletions tests/test_is_sortable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import eblob_kit

from collections import namedtuple


DummyRecord = namedtuple('DummyRecord', 'a b')


def test_sequence_is_sorted_default_key():
"""Test that sequence is sorted with default key selector."""
sorted_sequence = [-1, 1, 2, 3, 4, 5, 10, 100, 1000]
assert eblob_kit.is_sorted(sorted_sequence)


def test_sequence_not_sorted_default_key():
"""Test that sequence is not sorted with default key selector."""
non_sorted_sequence = [-1, 1, 2, 3, 4, 5, 10, 100, 99, 1000]
assert not eblob_kit.is_sorted(non_sorted_sequence)


def test_sequence_is_sorted_custom_key():
"""Test sequence is sorted with custom field selector."""
sequence_length = 5
sequence = [
DummyRecord(i, sequence_length - i) for i in xrange(sequence_length)
]

assert eblob_kit.is_sorted(sequence)
assert eblob_kit.is_sorted(sequence, lambda x: x.a)
assert not eblob_kit.is_sorted(sequence, lambda x: x.b)

0 comments on commit b985d9f

Please sign in to comment.