def test_init_with_bloom_data(exists_mock, load_mock): # Setup test data and mocks exists_mock.return_value = True load_mock.return_value = sentinel.data capacity = 1000 error = 0.002 decay_time = 86400 data_path = '/does/not/exist' # Call init bloom = TimingBloomFilter( capacity=capacity, error=error, decay_time=decay_time, data_path=data_path, ) # Check that the bloom is setup as expected assert_bloom_values( bloom, { 'capacity': capacity, 'error': error, 'data_path': data_path, 'id': None, 'num_bytes': 12935, 'num_hashes': 9, 'ring_size': 15, 'dN': 7, 'seconds_per_tick': 12342.857142857143, '_optimize': True, 'data': sentinel.data, }) test_dp, test_mf, test_bf = bloom._get_paths(None) assert test_dp == '/does/not/exist' assert test_mf == '/does/not/exist/meta.json' assert test_bf == '/does/not/exist/bloom.npy' exists_mock.assert_called_once_with(test_bf) load_mock.assert_called_once_with(test_bf)
def test_init_with_bloom_data(exists_mock, load_mock): # Setup test data and mocks exists_mock.return_value = True load_mock.return_value = sentinel.data capacity = 1000 error = 0.002 decay_time = 86400 data_path = '/does/not/exist' # Call init bloom = TimingBloomFilter( capacity=capacity, error=error, decay_time=decay_time, data_path=data_path, ) # Check that the bloom is setup as expected assert_bloom_values(bloom, { 'capacity': capacity, 'error': error, 'data_path': data_path, 'id': None, 'num_bytes': 12935, 'num_hashes': 9, 'ring_size': 15, 'dN': 7, 'seconds_per_tick': 12342.857142857143, '_optimize': True, 'data': sentinel.data, }) test_dp, test_mf, test_bf = bloom._get_paths(None) assert test_dp == '/does/not/exist' assert test_mf == '/does/not/exist/meta.json' assert test_bf == '/does/not/exist/bloom.npy' exists_mock.assert_called_once_with(test_bf) load_mock.assert_called_once_with(test_bf)
def test_init_no_bloom_data(): # Setup test data capacity = 1000 error = 0.002 decay_time = 86400 data_path = '/does/not/exist' id = 5 # Call init and get back a bloom bloom = TimingBloomFilter( capacity=capacity, error=error, decay_time=decay_time, data_path=data_path, id=id, ) # Make sure the bloom is setup as expected assert_bloom_values( bloom, { 'capacity': capacity, 'error': error, 'data_path': data_path, 'id': id, 'num_bytes': 12935, 'num_hashes': 9, 'ring_size': 15, 'dN': 7, 'seconds_per_tick': 12342.857142857143, '_optimize': True, }) test_dp, test_mf, test_bf = bloom._get_paths(None) assert test_dp == '/does/not/exist' assert test_mf == '/does/not/exist/meta.json' assert test_bf == '/does/not/exist/bloom.npy' assert_empty_bloom(bloom)
def test_init_no_bloom_data(): # Setup test data capacity = 1000 error = 0.002 decay_time = 86400 data_path = '/does/not/exist' id = 5 # Call init and get back a bloom bloom = TimingBloomFilter( capacity=capacity, error=error, decay_time=decay_time, data_path=data_path, id=id, ) # Make sure the bloom is setup as expected assert_bloom_values(bloom, { 'capacity': capacity, 'error': error, 'data_path': data_path, 'id': id, 'num_bytes': 12935, 'num_hashes': 9, 'ring_size': 15, 'dN': 7, 'seconds_per_tick': 12342.857142857143, '_optimize': True, }) test_dp, test_mf, test_bf = bloom._get_paths(None) assert test_dp == '/does/not/exist' assert test_mf == '/does/not/exist/meta.json' assert test_bf == '/does/not/exist/bloom.npy' assert_empty_bloom(bloom)