示例#1
0
 def test_incr_rel_q_special_chars_wc(self):
     testdb = DB(SQLiteRepo())
     init = (('a***', 10), ('b???', 20), ('R?*x', 'a***', 'b???', 80))
     testdb.import_data(init)
     expected = [('a***', 10), ('b???', 20), ('R?*x', 'a***', 'b???', 79)]
     testdb.incr_rel_q('R?*x', 'a***', 'b???', -1, wildcards=False)
     samp = list(testdb.export())
     self.assertEqual(samp, expected)
示例#2
0
 def test_put_a_special_chars(self):
     """Put anchor containing special reserved characters"""
     testdb = DB(SQLiteRepo())
     data = [(escape(x), None) for x in testdb.repo.special_chars["F"]]
     expected = [(x, None) for x in testdb.repo.special_chars["F"]]
     for d in data:
         testdb.put_a(*d)
     samp = list(testdb.export())
     self.assertEqual(samp, expected)
示例#3
0
 def test_put_a_special_chars_wildcards(self):
     """Put anchor containing wildcard characters"""
     testdb = DB(SQLiteRepo())
     chars = (CHAR_WC_ZP, CHAR_WC_1C, SQLiteRepo.CHAR_WC_ZP_SQL,
              SQLiteRepo.CHAR_WC_1C_SQL)
     data = [(x, -10) for x in chars]
     for d in data:
         testdb.put_a(*d)
     samp = list(testdb.export())
     self.assertEqual(samp, data)
示例#4
0
 def test_get_a_special_chars_mixed(self):
     """Put anchor containing all special and wildcard characters"""
     testdb = DB(SQLiteRepo())
     chardict = testdb.get_special_chars()
     suffix = "".join((chardict["E"], chardict["F"], chardict["WC"]))
     data = [("".join((x, suffix)), -10) for x in chardict["PX"]]
     testdb.import_data(data)
     for d in data:
         samp = list(testdb.export())
         self.assertEqual(samp, data)
示例#5
0
 def test_put_rel_special_chars_wc(self):
     """Put relations containing wildcard characters"""
     testdb = DB(SQLiteRepo())
     init = (
         ('a***', 10),
         ('b???', 20),
     )
     testdb.import_data(init)
     testdb.put_rel('R?*', 'a***', 'b???', None)
     final = [('a***', 10), ('b???', 20), ('R?*', 'a***', 'b???', None)]
     samp = list(testdb.export())
     self.assertEqual(samp, final)
示例#6
0
 def test_put_a_long_content(self):
     """Put anchors with long-form content"""
     testrepo = SQLiteRepo()
     testdb = DB(testrepo)
     contents = [
         "{}{}".format(x, "N" * testrepo.preface_length) for x in range(3)
     ]
     data = [(x, None) for x in contents]
     for d in data:
         testdb.put_a(*d)
     samp = list(testdb.export())
     self.assertEqual(samp, data)
示例#7
0
class SlrDbExportTests(TestCase):
    """
    Verify the operation of SQLiteRepo's export function.

    This test relies on the correctness of SQLiteRepo._reltext().
    Tests for _reltext() must pass for these tests to be valid.

    Unfortunately, tests for export() cannot be run under the
    generic DB class test suite as implementations for export()
    are repository class-specific.

    """
    def setUp(self):
        # Most direct SQLiteRepo insert humanly possible
        self.testdb = DB(SQLiteRepo())
        sc_insert = "INSERT INTO {} VALUES(?,?)".format(SQLiteRepo.TABLE_A)
        rt = self.testdb.repo._reltext
        cs = self.testdb.repo._db_conn.cursor()
        inp = (('a', None), ('j', None), ('t', 0.0001), ('z', -274),
               (rt('j', 'a', 'j'), None), (rt('t', 'a',
                                              't'), -274), (rt('a', 'z',
                                                               'a'), 37))
        cs.executemany(sc_insert, inp)

    def test_export_all_interchange(self):
        out = list(self.testdb.export())
        expected = [('a', None), ('j', None), ('t', 0.0001), ('z', -274),
                    ('j', 'a', 'j', None), ('t', 'a', 't', -274),
                    ('a', 'z', 'a', 37)]
        self.assertEqual(out, expected)

    def test_export_anchor_interchange(self):
        """Export just one anchor and its relations to the
        interchange format

        """
        out = list(self.testdb.export(a='a'))
        expected = [('a', None), ('j', 'a', 'j', None), ('t', 'a', 't', -274),
                    ('a', 'z', 'a', 37)]
        self.assertEqual(out, expected)
示例#8
0
 def test_set_a_q_special_chars_wc(self):
     testdb = DB(SQLiteRepo())
     init = (
         ('a***', 10),
         ('b???', 20),
     )
     testdb.import_data(init)
     expected = [
         ('a***', 10),
         ('b???', 888),
     ]
     testdb.set_a_q('b???', 888, wildcards=False)
     samp = list(testdb.export())
     self.assertEqual(samp, expected)
示例#9
0
    def test_put_a_special_chars_mixed(self):
        """Put anchor containing all special characters.

        Characters must come out the same way they went in.

        """
        testdb = DB(SQLiteRepo())
        fi = lambda x, y: "".join((escape(x), y))
        chardict = testdb.get_special_chars()
        suffix = "".join((chardict["E"], chardict["F"], chardict["WC"]))
        data = [("".join((p, suffix)), -10) for p in chardict["PX"]]
        for d in data:
            testdb.put_a(*d)
        samp = list(testdb.export())
        self.assertEqual(samp, data)
示例#10
0
    def test_put_a_special_chars_prefix(self):
        """
        Put anchor containing special prefix characters

        Special prefix characters are allowed to be used as-is in
        anchors, except for the first character.

        """
        testdb = DB(SQLiteRepo())
        fi = lambda x: "{0}uuu{0}u".format(escape(x))  # format input
        fo = lambda x: "{0}uuu{0}u".format(x)  # format output
        data = [(fi(x), None) for x in testdb.repo.special_chars["PX"]]
        expected = [(fo(x), None) for x in testdb.repo.special_chars["PX"]]
        for d in data:
            testdb.put_a(*d)
        samp = list(testdb.export())
        self.assertEqual(samp, expected)
示例#11
0
    def test_put_a_long_content_same_preface(self):
        """Put anchors with long-form content with the same preface

        The preface of a long-form anchor identifies the anchor
        and cannot be reused.

        """
        testrepo = SQLiteRepo()
        testdb = DB(testrepo)
        contents = [
            "{}{}".format("N" * testrepo.preface_length, x) for x in range(3)
        ]
        data = [(x, None) for x in contents]
        with self.assertRaises(ValueError):
            for d in data:
                testdb.put_a(*d)
        samp = list(testdb.export())
        self.assertEqual(samp, data[:1])
示例#12
0
    def test_put_a_long_content_conflicting_preface(self):
        """Put long-form anchor in presence of conflicting anchor

        The preface of a long-form anchor identifies the anchor
        and cannot be identical to an existing anchor. Existing
        anchors must remain intact.

        """
        testrepo = SQLiteRepo()
        testdb = DB(testrepo)
        preface = "N" * testrepo.preface_length
        init = [
            ("{}".format(preface), None),
        ]  # anchor equiv. to preface
        data = ("".join((preface, "X")), None)  # regular long-form anchor
        testdb.import_data(init)
        with self.assertRaises(ValueError):
            testdb.put_a(*data)
        samp = list(testdb.export())
        self.assertEqual(samp, init)
示例#13
0
    def test_set_a_q_long_content(self):
        """Set Anchor q-value with long-form content

        The preface of the content must be able to set the Anchor's q-value

        """
        testrepo = SQLiteRepo()
        testdb = DB(testrepo)
        suffix = "N" * testrepo.preface_length
        init = [
            ("{}{}".format("Z", suffix), 0),
            ('Z', 0),
        ]
        expected = [
            ("{}{}".format("Z", suffix), 99),
            ('Z', 0),
        ]
        testdb.import_data(init)
        testdb.set_a_q("{}{}".format("Z", suffix[:-1]), 99)
        samp = list(testdb.export())
        self.assertEqual(samp, expected)