def test_get_a_alias(self): testdb = DB(SQLiteRepo()) data = ( ('a', 10), ('b', 11), ) testdb.import_data(data) expected = ('a', 10) # assuming ROWID strictly follows insertion order samp = next(testdb.get_a('@1', out_format='interchange')) self.assertEqual(samp, expected)
def test_get_a_exact_sql_wildcard_escape(self): """Get single anchor containing SQL wildcard characters""" testdb = DB(SQLiteRepo()) chars = (SQLiteRepo.CHAR_WC_ZP_SQL, SQLiteRepo.CHAR_WC_1C_SQL) data = [(x, 100) for x in chars] testdb.import_data(data) for c in chars: with self.subTest(char=c): sample = list( testdb.get_a("{}*".format(c), out_format='interchange')) self.assertEqual(sample, [(c, 100)])
def test_get_a_long_content(self): """Get Anchors with long-form content The preface of the content must be able to retrieve the Anchor """ testrepo = SQLiteRepo() testdb = DB(testrepo) contents = [ "{}{}".format(x, "N" * testrepo.preface_length) for x in range(3) ] init = [(x, 99) for x in contents] testdb.import_data(init) for c in contents: samp_preface = next(testdb.get_a(c[:-1], out_format='interchange')) expected_preface = (c[:-1], 99) samp_full = next( testdb.get_a(c[:-1], length=None, out_format='interchange')) expected_full = (c, 99) self.assertEqual(samp_preface, expected_preface) self.assertEqual(samp_full, expected_full)
def test_get_a_special_chars_prefix(self): """Get anchors containing escaped prefix special chars Only the first char needs to be escaped """ testdb = DB(SQLiteRepo()) px_chars = testdb.get_special_chars()["PX"] fi = lambda x: "{}uuu{}u".format(escape(x), x) # format input fo = lambda x: "{0}uuu{0}u".format(x) # format output data = [(fi(x), None) for x in px_chars] testdb.import_data(data) for c in px_chars: samp = next(testdb.get_a(fi(c), out_format='interchange')) expected = (fo(c), None) self.assertEqual(samp, expected)
def test_get_a_wildcard_escape(self): """Get multiple anchors containing TAGS wildcard characters using wildcards TAGS wildcards are allowed to be stored in DB """ testdb = DB(SQLiteRepo()) chars = (CHAR_WC_ZP, CHAR_WC_1C) for c in chars: data = [("{}{}".format(c, n), None) for n in range(3)] testdb.import_data(data) with self.subTest(char=c): term = "{}*".format(escape(c)) samp = list(testdb.get_a(term, out_format='interchange')) self.assertEqual(samp, data)
def test_get_a_wildcard_long_rel_in_db(self): """Get single anchor by wildcard, when long relation is in db""" testrepo = SQLiteRepo() testdb = DB(testrepo) plen = testrepo.preface_length suffix = "N" * plen long_content_a = "{}{}".format("A", suffix) long_content_z = "{}{}".format("Z", suffix) init = ((long_content_a, 0), (long_content_z, 0), ("R", long_content_a[:plen], long_content_z[:plen], None), ("RAnch", 99)) expected = [ ("RAnch", 99), ] testdb.import_data(init) samp = list(testdb.get_a("R*", out_format='interchange')) self.assertEqual(samp, expected)