def sqlite_reader(request): write_sqlite3() def _(): os.remove(SQLITE_FILENAME) request.addfinalizer(_) samples_config = sqlite_format.SamplesConfig(table_name='traces', pk_column_name='trace_id', dtype='uint8', samples_column_name='samples') metadata_config = sqlite_format.MetadataConfig(table_name='traces', pk_column_name='trace_id', metadata_defs={ 'plaintext': 'uint8', 'plain_t': 'uint8', 'ciphertext': 'uint8', 'indices': 'U2', }) headers_config = sqlite_format.HeadersConfig(table_name='headers', tag_column_name='tag', value_column_name='value', dtype_column_name='dtype') return sqlite_format.SQLiteFormatReader(filename=SQLITE_FILENAME, samples_config=samples_config, metadata_config=metadata_config, headers_config=headers_config)
def test_ths_without_metadata(filename): ths = estraces.read_ths_from_sqlite( filename, samples_config=sqlite_format.SamplesConfig() ) assert isinstance(ths, estraces.TraceHeaderSet) assert len(ths) == 10 assert [] == list(ths.metadatas.keys()) assert not ths._reader.fetch_metadatas('plain')
def test_ths_without_headers(filename): ths = estraces.read_ths_from_sqlite( filename, samples_config=sqlite_format.SamplesConfig(), metadata_config=sqlite_format.MetadataConfig(metadata_defs={'plaintext': 'uint8'}) ) assert isinstance(ths, estraces.TraceHeaderSet) assert len(ths) == 10 assert [] == list(ths.headers.keys()) assert not ths._reader.fetch_header('tag')
def test_raises_exception_configuring_non_existing_samples_col(filename): samples_config = sqlite_format.SamplesConfig( table_name='traces', pk_column_name='trace_id', dtype='uint8', samples_column_name='sampless' ) metadata_config = sqlite_format.MetadataConfig() headers_config = sqlite_format.HeadersConfig() ths = estraces.read_ths_from_sqlite( filename, samples_config=samples_config, metadata_config=metadata_config, headers_config=headers_config ) with pytest.raises(sqlite_format.SQLiteError): ths[0].samples[:] with pytest.raises(sqlite_format.SQLiteError): ths.samples[:] with pytest.raises(sqlite_format.SQLiteError): ths._reader.get_trace_size(0) samples_config = sqlite_format.SamplesConfig( table_name='tracess', pk_column_name='trace_id', dtype='uint8', samples_column_name='samples' ) ths = estraces.read_ths_from_sqlite( filename, samples_config=samples_config, metadata_config=metadata_config, headers_config=headers_config ) with pytest.raises(sqlite_format.SQLiteError): ths[0].samples[:] with pytest.raises(sqlite_format.SQLiteError): ths.samples[:] with pytest.raises(sqlite_format.SQLiteError): ths._reader.get_trace_size(0)
def test_samples_shape_is_not_too_slow(lots_of_traces): ths = estraces.read_ths_from_sqlite( lots_of_traces, samples_config=sqlite_format.SamplesConfig(), metadata_config=sqlite_format.MetadataConfig(metadata_defs={'plaintext': 'uint8'}) ) assert isinstance(ths, estraces.TraceHeaderSet) stm = 's_ths.samples.shape' s_ths = ths[:100] t1 = timeit.timeit(stm, globals={'s_ths': s_ths}, number=10) s_ths = ths[:10] t2 = timeit.timeit(stm, globals={'s_ths': s_ths}, number=10) assert t1 / t2 < 10
def test_raises_exception_with_wrong_header_config(filename): samples_config = sqlite_format.SamplesConfig(table_name='traces', pk_column_name='trace_id', dtype='uint8', samples_column_name='samples') metadata_config = sqlite_format.MetadataConfig() headers_config = sqlite_format.HeadersConfig(table_name='headers', tag_column_name='tags', value_column_name='value', dtype_column_name='dtype') ths = estraces.read_ths_from_sqlite( filename, samples_config=samples_config, metadata_config=metadata_config, headers_config=headers_config ) with pytest.raises(sqlite_format.SQLiteError): ths.headers['key'] with pytest.raises(sqlite_format.SQLiteError): ths._reader.fetch_header('key')
def test_raises_exception_fetching_non_existing_header(filename): samples_config = sqlite_format.SamplesConfig(table_name='traces', pk_column_name='trace_id', dtype='uint8', samples_column_name='samples') metadata_config = sqlite_format.MetadataConfig( table_name='traces', pk_column_name='trace_id', metadata_defs={ 'plaintext': 'uint8', 'ciphertext': 'uint8', } ) headers_config = sqlite_format.HeadersConfig(table_name='headers', tag_column_name='tag', value_column_name='value', dtype_column_name='dtype') ths = estraces.read_ths_from_sqlite( filename, samples_config=samples_config, metadata_config=metadata_config, headers_config=headers_config ) with pytest.raises(KeyError): ths.headers['woop']
def test_raises_exception_configuring_non_existing_metadata(filename): samples_config = sqlite_format.SamplesConfig(table_name='traces', pk_column_name='trace_id', dtype='uint8', samples_column_name='samples') metadata_config = sqlite_format.MetadataConfig( table_name='traces', pk_column_name='trace_id', metadata_defs={ 'plaintext': 'uint8', 'ciphertext': 'uint8', 'woop': 'uint8' } ) headers_config = sqlite_format.HeadersConfig() ths = estraces.read_ths_from_sqlite( filename, samples_config=samples_config, metadata_config=metadata_config, headers_config=headers_config ) with pytest.raises(sqlite_format.SQLiteError): ths[0].metadatas['woop'] with pytest.raises(sqlite_format.SQLiteError): ths.metadatas['woop']
def test_raises_exception_if_file_is_not_a_sqlite_db(): with pytest.raises(ValueError): estraces.read_ths_from_sqlite('tests/samples/test.ets', samples_config=sqlite_format.SamplesConfig())
def test_raises_exception_if_file_does_not_exist(): with pytest.raises(ValueError): estraces.read_ths_from_sqlite('ouch', samples_config=sqlite_format.SamplesConfig())