Пример #1
0
def test_ArcticTransaction_writes_no_data_found():
    vs = Mock(spec=VersionStore)
    ts1 = pd.DataFrame(index=[1, 2], data={'a': [1.0, 2.0]})
    vs.read.side_effect = NoDataFoundException('no data')
    vs.write.return_value = VersionedItem(symbol=sentinel.symbol,
                                          library=sentinel.library,
                                          version=1,
                                          metadata=None,
                                          data=None)
    vs.list_versions.side_effect = [
        [],
        [{
            'version': 1
        }],
    ]

    with ArcticTransaction(vs, sentinel.symbol, sentinel.user,
                           sentinel.log) as cwb:
        cwb.write(sentinel.symbol, ts1, metadata={1: 2})

    assert vs.write.call_args_list == [
        call(sentinel.symbol,
             ANY,
             prune_previous_version=True,
             metadata={1: 2})
    ]
    assert vs.list_versions.call_args_list == [
        call(sentinel.symbol, latest_only=True),
        call(sentinel.symbol)
    ]
Пример #2
0
def test_write_metadata_no_previous_data():
    vs = _create_mock_versionstore()
    vs._read_metadata.side_effect = NoDataFoundException("no data found")

    assert VersionStore.write_metadata(vs, symbol=TEST_SYMBOL, metadata=META_TO_WRITE, my_custom_arg='hello') == vs.write.return_value
    assert vs._read_metadata.call_args_list == [call(TEST_SYMBOL)]
    assert vs.write.call_args_list == [call(TEST_SYMBOL, data=None, metadata=META_TO_WRITE,
                                            prune_previous_version=True, my_custom_arg='hello')]
Пример #3
0
def test_restore_version_data_missing_symbol():
    vs = _create_mock_versionstore()
    vs._read_metadata.side_effect = NoDataFoundException("no data")
    with patch('arctic.store.version_store.mongo_retry') as mock_retry:
        mock_retry.side_effect = lambda f: f
        with pytest.raises(NoDataFoundException):
            VersionStore.restore_version(vs, symbol=TEST_SYMBOL,
                                         as_of=TPL_VERSION['version'], prune_previous_version=True)
    assert vs._read_metadata.call_args_list == [call(TEST_SYMBOL, as_of=TPL_VERSION['version'])]
    assert vs._versions.insert_one.called is False
    assert vs._publish_change.called is False