def test_add_temporary_ngrams (self): store = tacl.DataStore(':memory:') store._conn = MagicMock(spec_set=sqlite3.Connection) store._add_temporary_ngrams([sentinel.ngram1, sentinel.ngram2]) self.assertEqual( store._conn.mock_calls, [call.execute(tacl.constants.DROP_TEMPORARY_NGRAMS_TABLE_SQL), call.execute(tacl.constants.CREATE_TEMPORARY_NGRAMS_TABLE_SQL), call.executemany(tacl.constants.INSERT_TEMPORARY_NGRAM_SQL, [(sentinel.ngram1,), (sentinel.ngram2,)])])
def test_add_temporary_ngrams(self): store = tacl.DataStore(':memory:') store._conn = MagicMock(spec_set=sqlite3.Connection) store._add_temporary_ngrams(['A', 'B']) self.assertEqual(store._conn.mock_calls, [ call.execute(tacl.constants.DROP_TEMPORARY_NGRAMS_TABLE_SQL), call.execute(tacl.constants.CREATE_TEMPORARY_NGRAMS_TABLE_SQL), call.executemany(tacl.constants.INSERT_TEMPORARY_NGRAM_SQL, [('A', ), ('B', )]) ])
def test_add_text_size_ngrams (self): store = tacl.DataStore(':memory:') store._conn = MagicMock(spec_set=sqlite3.Connection) size = 1 ngrams = collections.OrderedDict([('a', 2), ('b', 1)]) store._add_text_size_ngrams(sentinel.text_id, size, ngrams) self.assertEqual( store._conn.mock_calls, [call.execute(tacl.constants.INSERT_TEXT_HAS_NGRAM_SQL, [sentinel.text_id, size, len(ngrams)]), call.executemany(tacl.constants.INSERT_NGRAM_SQL, [[sentinel.text_id, 'a', size, 2], [sentinel.text_id, 'b', size, 1]]), call.commit()])
def test_add_text_size_ngrams(self): store = tacl.DataStore(':memory:') store._conn = MagicMock(spec_set=sqlite3.Connection) size = 1 ngrams = collections.OrderedDict([('a', 2), ('b', 1)]) store._add_text_size_ngrams(sentinel.text_id, size, ngrams) self.assertEqual(store._conn.mock_calls, [ call.execute( tacl.constants.INSERT_TEXT_HAS_NGRAM_SQL, [sentinel.text_id, size, len(ngrams)]), call.executemany(tacl.constants.INSERT_NGRAM_SQL, [[sentinel.text_id, 'a', size, 2], [sentinel.text_id, 'b', size, 1]]), call.commit() ])