File: test_query.py

package info (click to toggle)
tinysparql 3.10.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 24,468 kB
  • sloc: ansic: 118,310; python: 6,139; javascript: 719; sh: 121; perl: 106; xml: 67; makefile: 31; sql: 1
file content (75 lines) | stat: -rw-r--r-- 2,209 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Copyright (C) 2020, Sam Thursfield <sam@afuera.me.uk>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
#

"""
Test queries using libtracker-sparql.
"""

import gi

gi.require_version("Tracker", "3.0")
from gi.repository import Tracker

import unittest as ut

import fixtures

# We must import configuration to enable the default logging behaviour.
import configuration


class TrackerQueryTests:
    """
    Query test cases for TrackerSparqlConnection.

    To allow testing with both local and D-Bus connections, this test suite is
    a mixin, which is combined with different fixtures below.
    """

    def test_row_types(self):
        """Check the value types returned by TrackerSparqlCursor."""

        CONTACT = """
        INSERT {
        <test://test1> a nfo:Document, nfo:FileDataObject ;
             nie:url <file://test.test> ;
             nfo:fileSize 1234 .
        }
        """
        self.tracker.update(CONTACT)

        cursor = self.conn.query(
            "SELECT ?url ?filesize { ?url a nfo:FileDataObject ; nfo:fileSize ?filesize }"
        )

        cursor.next()
        assert cursor.get_n_columns() == 2
        self.assertEqual(cursor.get_value_type(0), Tracker.SparqlValueType.URI)
        self.assertEqual(cursor.get_value_type(1), Tracker.SparqlValueType.INTEGER)


class TrackerLocalQueryTest(fixtures.TrackerSparqlDirectTest, TrackerQueryTests):
    pass


class TrackerBusQueryTest(fixtures.TrackerSparqlBusTest, TrackerQueryTests):
    pass


if __name__ == "__main__":
    fixtures.tracker_test_main()