def test_merge_at_beginning_too_much_overlap(): """ trying to merge so much duplicate data we give up and return just the cached data """ mts = MTS(MockRedis()) mts.key_basis = lambda: 'some-key-goes-here' new_mts = MTS(MockRedis()) mts.result = {'values': copy.deepcopy(INITIAL_MTS_DATA)} new_mts.result = {'values': copy.deepcopy(INITIAL_MTS_DATA)} mts.merge_at_beginning(new_mts) assert mts.result['values'] == INITIAL_MTS_DATA
def test_merge_at_beginning_no_overlap(): """ common case, no overlap """ mts = MTS(MockRedis()) mts.key_basis = lambda: 'some-key-goes-here' new_mts = MTS(MockRedis()) mts.result = {'values': copy.deepcopy(INITIAL_MTS_DATA)} new_mts.result = {'values': [[788, 9]]} mts.merge_at_beginning(new_mts) assert mts.result['values'] == [[788, 9]] + INITIAL_MTS_DATA
def test_merge_at_beginning_replaces_when_existing_data_is_short(): """ if we can't iterate over the cached data, and it's out of order, we replace it. """ mts = MTS(MockRedis()) mts.key_basis = lambda: 'some-key-goes-here' new_mts = MTS(MockRedis()) new_mts.result = {'values': copy.deepcopy(INITIAL_MTS_DATA)} mts.result = {'values': [[795, 1000], [797, 1100]]} mts.merge_at_beginning(new_mts) assert mts.result['values'] == INITIAL_MTS_DATA
def test_merge_at_beginning_two_overlap(): """ single overlapping point - make sure the new_mts version is favored """ mts = MTS(MockRedis()) mts.key_basis = lambda: 'some-key-goes-here' new_mts = MTS(MockRedis()) mts.result = {'values': copy.deepcopy(INITIAL_MTS_DATA)} new_mts.result = {'values': [[788, 9], [789, 9001], [790, 10001]]} mts.merge_at_beginning(new_mts) assert mts.result['values'] == [[788, 9], [789, 9001], [790, 10001]] + INITIAL_MTS_DATA[2:]
def test_merge_at_beginning_two_overlap(): """ single overlapping point - make sure the new_mts version is favored """ mts = MTS(MockRedis()) mts.key_basis = lambda: 'some-key-goes-here' new_mts = MTS(MockRedis()) mts.result = {'values': copy.deepcopy(INITIAL_MTS_DATA)} new_mts.result = {'values': [[788, 9], [789, 9001], [790, 10001]]} mts.merge_at_beginning(new_mts) assert mts.result['values'] == [[788, 9], [789, 9001], [790, 10001] ] + INITIAL_MTS_DATA[2:]