def test_correctly_infers_code_size_16(self): Model = self._model(slice_size=128, settings=self._settings_with_event_log()) index = self._index(Model, Model.sliced) signal = SineSynthesizer(SR11025()) \ .synthesize(Seconds(5), [220, 440, 880]) Model.process(meta=signal.encode()) index._synchronously_process_events() self.assertEqual(16, index.hamming_db.code_size)
def test_listen_raises_if_model_class_has_no_event_log_configured(self): Model = self._model(slice_size=64, settings=self._settings_with_no_event_log()) index = self._index(Model, Model.sliced) signal = SineSynthesizer(SR11025()) \ .synthesize(Seconds(5), [220, 440, 880]) Model.process(meta=signal.encode()) self.assertRaises(ValueError, lambda: index._synchronously_process_events())
def correctly_infers_index_name(self): Model = self._model(slice_size=128, settings=self._settings_with_event_log()) index = self._index(Model, Model.sliced) signal = SineSynthesizer(SR11025()) \ .synthesize(Seconds(5), [220, 440, 880]) Model.process(meta=signal.encode()) index._synchronously_process_events() self.assertTrue('index.sliced' in index.hamming_db.path)
def test_correctly_infers_code_size_16(self): Model = self._model( slice_size=128, settings=self._settings_with_event_log()) index = self._index(Model, Model.sliced) signal = SineSynthesizer(SR11025()) \ .synthesize(Seconds(5), [220, 440, 880]) Model.process(meta=signal.encode()) index._synchronously_process_events() self.assertEqual(16, index.hamming_db.code_size)
def test_listen_raises_if_model_class_has_no_event_log_configured(self): Model = self._model( slice_size=64, settings=self._settings_with_no_event_log()) index = self._index(Model, Model.sliced) signal = SineSynthesizer(SR11025()) \ .synthesize(Seconds(5), [220, 440, 880]) Model.process(meta=signal.encode()) self.assertRaises( ValueError, lambda: index._synchronously_process_events())
def correctly_infers_index_name(self): Model = self._model( slice_size=128, settings=self._settings_with_event_log()) index = self._index(Model, Model.sliced) signal = SineSynthesizer(SR11025()) \ .synthesize(Seconds(5), [220, 440, 880]) Model.process(meta=signal.encode()) index._synchronously_process_events() self.assertTrue('index.sliced' in index.hamming_db.path)
def test_can_add_already_packed_feature(self): Model = self._model(slice_size=128, settings=self._settings_with_no_event_log()) index = self._index(Model, Model.packed) signal = SineSynthesizer(SR11025()) \ .synthesize(Seconds(5), [220, 440, 880]) _id = Model.process(meta=signal.encode()) model = Model(_id) index.add(_id) self.assertEqual(len(model.packed), len(index))
def test_can_add_already_packed_feature(self): Model = self._model( slice_size=128, settings=self._settings_with_no_event_log()) index = self._index(Model, Model.packed) signal = SineSynthesizer(SR11025()) \ .synthesize(Seconds(5), [220, 440, 880]) _id = Model.process(meta=signal.encode()) model = Model(_id) index.add(_id) self.assertEqual(len(model.packed), len(index))
def test_hamming_db_is_initialized_if_docs_exist(self): Model = self._model(slice_size=128, settings=self._settings_with_event_log()) index = self._index(Model, Model.sliced) signal = SineSynthesizer(SR11025()) \ .synthesize(Seconds(5), [220, 440, 880]) Model.process(meta=signal.encode()) index._synchronously_process_events() index2 = self._index(Model, Model.sliced) self.assertIsNotNone(index2.hamming_db) self.assertEqual(16, index2.hamming_db.code_size)
def test_hamming_db_is_initialized_if_docs_exist(self): Model = self._model( slice_size=128, settings=self._settings_with_event_log()) index = self._index(Model, Model.sliced) signal = SineSynthesizer(SR11025()) \ .synthesize(Seconds(5), [220, 440, 880]) Model.process(meta=signal.encode()) index._synchronously_process_events() index2 = self._index(Model, Model.sliced) self.assertIsNotNone(index2.hamming_db) self.assertEqual(16, index2.hamming_db.code_size)
def test_can_roundtrip_query(self): Model = self._model(slice_size=128, settings=self._settings_with_event_log()) index = self._index(Model, Model.sliced) signal = SineSynthesizer(SR11025()) \ .synthesize(Seconds(5), [220, 440, 880]) Model.process(meta=signal.encode()) index._synchronously_process_events() results = index.random_search(n_results=5) decoded = index.decode_query(results.query) encoded = index.encode_query(decoded) self.assertEqual(results.query, encoded)
def test_can_roundtrip_query(self): Model = self._model( slice_size=128, settings=self._settings_with_event_log()) index = self._index(Model, Model.sliced) signal = SineSynthesizer(SR11025()) \ .synthesize(Seconds(5), [220, 440, 880]) Model.process(meta=signal.encode()) index._synchronously_process_events() results = index.random_search(n_results=5) decoded = index.decode_query(results.query) encoded = index.encode_query(decoded) self.assertEqual(results.query, encoded)
def test_can_add_additional_data_to_index(self): Model = self._model(slice_size=128, settings=self._settings_with_event_log()) index = self._index(Model, Model.sliced, web_url=lambda doc, ts: doc.meta['web_url']) signal = SineSynthesizer(SR11025()) \ .synthesize(Seconds(5), [220, 440, 880]) meta = AudioMetaData(uri=signal.encode(), web_url='https://example.com') _id = Model.process(meta=meta) index._synchronously_process_events() results = list(index.random_search(n_results=5)) result_id, ts, extra_data = results[0] self.assertEqual(_id, result_id) self.assertEqual('https://example.com', extra_data['web_url'])
def test_can_add_additional_data_to_index(self): Model = self._model( slice_size=128, settings=self._settings_with_event_log()) index = self._index( Model, Model.sliced, web_url=lambda doc, ts: doc.meta['web_url']) signal = SineSynthesizer(SR11025()) \ .synthesize(Seconds(5), [220, 440, 880]) meta = AudioMetaData(uri=signal.encode(), web_url='https://example.com') _id = Model.process(meta=meta) index._synchronously_process_events() results = list(index.random_search(n_results=5)) result_id, ts, extra_data = results[0] self.assertEqual(_id, result_id) self.assertEqual('https://example.com', extra_data['web_url'])