[tracker/sam/autopep8] functional-tests: Reformat in line with Python standards
- From: Sam Thursfield <sthursfield src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/sam/autopep8] functional-tests: Reformat in line with Python standards
- Date: Sat, 2 Mar 2019 14:55:06 +0000 (UTC)
commit fda451efccf07607f4edbbc5be9329fdf7c48b97
Author: Sam Thursfield <sam afuera me uk>
Date: Sat Mar 2 15:50:55 2019 +0100
functional-tests: Reformat in line with Python standards
Python has a recommended code style, known as PEP-8. The functional tests
now follow this style.
This commit was created using `autopep8` version 1.2.4, run with this
command:
autopep8-3 -r --in-place $(find -name '*.py')
tests/functional-tests/01-insertion.py | 908 +++++++++++----------
tests/functional-tests/02-sparql-bugs.py | 211 +++--
tests/functional-tests/03-fts-functions.py | 35 +-
tests/functional-tests/04-group-concat.py | 35 +-
tests/functional-tests/05-coalesce.py | 39 +-
tests/functional-tests/06-distance.py | 71 +-
tests/functional-tests/07-graph.py | 26 +-
tests/functional-tests/08-unique-insertions.py | 21 +-
tests/functional-tests/09-concurrent-query.py | 64 +-
tests/functional-tests/10-sqlite-misused.py | 38 +-
tests/functional-tests/11-sqlite-batch-misused.py | 44 +-
tests/functional-tests/12-transactions.py | 41 +-
tests/functional-tests/13-threaded-store.py | 66 +-
tests/functional-tests/14-signals.py | 126 +--
tests/functional-tests/15-statistics.py | 95 +--
tests/functional-tests/16-collation.py | 60 +-
tests/functional-tests/17-ontology-changes.py | 733 +++++++++--------
.../functional-tests/common/utils/configuration.py | 13 +-
tests/functional-tests/common/utils/dconf.py | 17 +-
.../common/utils/expectedFailure.py | 38 +-
tests/functional-tests/common/utils/helpers.py | 162 ++--
tests/functional-tests/common/utils/html.py | 64 --
tests/functional-tests/common/utils/options.py | 3 +
tests/functional-tests/common/utils/storetest.py | 24 +-
24 files changed, 1486 insertions(+), 1448 deletions(-)
---
diff --git a/tests/functional-tests/01-insertion.py b/tests/functional-tests/01-insertion.py
index d9839fc08..d8f8e2188 100755
--- a/tests/functional-tests/01-insertion.py
+++ b/tests/functional-tests/01-insertion.py
@@ -30,52 +30,52 @@ import datetime
import unittest as ut
from common.utils.storetest import CommonTrackerStoreTest as CommonTrackerStoreTest
+
class TrackerStoreInsertionTests (CommonTrackerStoreTest):
- """
- Insert single and multiple-valued properties, dates (ok and broken)
- and check the results
- """
+ """
+ Insert single and multiple-valued properties, dates (ok and broken)
+ and check the results
+ """
- def test_insert_01 (self):
- """
- Simple insert of two triplets.
+ def test_insert_01(self):
+ """
+ Simple insert of two triplets.
- 1. Insert a InformationElement with title.
- 2. TEST: Query the title of that information element
- 3. Remove the InformationElement to keep everything as it was before
- """
+ 1. Insert a InformationElement with title.
+ 2. TEST: Query the title of that information element
+ 3. Remove the InformationElement to keep everything as it was before
+ """
- uri = "tracker://test_insert_01/" + str(random.randint (0, 100))
- insert = """
+ uri = "tracker://test_insert_01/" + str(random.randint(0, 100))
+ insert = """
INSERT { <%s> a nie:InformationElement;
nie:title \"test_insert_01\". }
""" % (uri)
- self.tracker.update (insert)
+ self.tracker.update(insert)
- """ verify the inserted item """
- query = """
+ """ verify the inserted item """
+ query = """
SELECT ?t WHERE {
<%s> a nie:InformationElement ;
nie:title ?t .
}
""" % (uri)
- results = self.tracker.query (query)
+ results = self.tracker.query(query)
- self.assertEqual (str(results[0][0]), "test_insert_01")
+ self.assertEqual(str(results[0][0]), "test_insert_01")
- """ delete the inserted item """
- delete = """
+ """ delete the inserted item """
+ delete = """
DELETE { <%s> a rdfs:Resource. }
""" % (uri)
- self.tracker.update (delete)
+ self.tracker.update(delete)
+ def test_insert_02(self):
+ """
+ Insert of a bigger set of triplets (linking two objects)
+ """
- def test_insert_02(self):
- """
- Insert of a bigger set of triplets (linking two objects)
- """
-
- self.tracker.update("""
+ self.tracker.update("""
INSERT {
<urn:uuid:bob-dylan> a nmm:Artist;
nmm:artistName 'Bob Dylan'.
@@ -91,7 +91,7 @@ class TrackerStoreInsertionTests (CommonTrackerStoreTest):
}
""")
- QUERY = """
+ QUERY = """
SELECT ?uri ?title ?length WHERE {
?uri a nmm:MusicPiece ;
nmm:performer <urn:uuid:bob-dylan> ;
@@ -100,27 +100,26 @@ class TrackerStoreInsertionTests (CommonTrackerStoreTest):
}
"""
- result = self.tracker.query (QUERY)
- self.assertEqual (len (result), 1)
- self.assertEqual (len (result[0]), 3) # uri, title, length
- self.assertEqual (result[0][0], "file:///a/b/c/10_song3.mp3")
- self.assertEqual (result[0][1], "Subterranean homesick blues")
- self.assertEqual (result[0][2], "219252")
+ result = self.tracker.query(QUERY)
+ self.assertEqual(len(result), 1)
+ self.assertEqual(len(result[0]), 3) # uri, title, length
+ self.assertEqual(result[0][0], "file:///a/b/c/10_song3.mp3")
+ self.assertEqual(result[0][1], "Subterranean homesick blues")
+ self.assertEqual(result[0][2], "219252")
- self.tracker.update ("""
+ self.tracker.update ("""
DELETE {
<urn:uuid:bob-dylan> a rdfs:Resource.
<file:///a/b/c/10_song3.mp3> a rdfs:Resource.
}
""")
+ def test_insert_03(self):
+ """
+ Checking all the values are inserted
+ """
- def test_insert_03(self):
- """
- Checking all the values are inserted
- """
-
- self.tracker.update("""
+ self.tracker.update("""
INSERT {
<urn:uuid:7646004> a nmm:Artist;
nmm:artistName 'John Lennon' .
@@ -141,7 +140,7 @@ class TrackerStoreInsertionTests (CommonTrackerStoreTest):
""")
- QUERY = """
+ QUERY = """
SELECT ?artist ?length ?trackN ?album ?size ?flm ?fc ?filename WHERE {
<file:///a/b/c/imagine.mp3> a nmm:MusicPiece ;
nmm:performer ?x ;
@@ -157,21 +156,21 @@ class TrackerStoreInsertionTests (CommonTrackerStoreTest):
?y nie:title ?album.
}
"""
- result = self.tracker.query(QUERY)
-
- self.assertEqual (len (result), 1)
- self.assertEqual (len (result[0]), 8)
- self.assertEqual (result[0][0], "John Lennon")
- self.assertEqual (result[0][1], "219252")
- self.assertEqual (result[0][2], "11")
- self.assertEqual (result[0][3], "Imagine")
- self.assertEqual (result[0][4], "17630")
- # FIXME Tracker returns this translated to the current timezone
- #self.assertEquals (result[0][5], "2008-12-23T11:47:02Z")
- #self.assertEquals (result[0][6], "2008-12-16T10:41:20Z")
- self.assertEqual (result[0][7], "imagine.mp3")
-
- self.tracker.update ("""
+ result = self.tracker.query(QUERY)
+
+ self.assertEqual(len(result), 1)
+ self.assertEqual(len(result[0]), 8)
+ self.assertEqual(result[0][0], "John Lennon")
+ self.assertEqual(result[0][1], "219252")
+ self.assertEqual(result[0][2], "11")
+ self.assertEqual(result[0][3], "Imagine")
+ self.assertEqual(result[0][4], "17630")
+ # FIXME Tracker returns this translated to the current timezone
+ #self.assertEquals (result[0][5], "2008-12-23T11:47:02Z")
+ #self.assertEquals (result[0][6], "2008-12-16T10:41:20Z")
+ self.assertEqual(result[0][7], "imagine.mp3")
+
+ self.tracker.update ("""
DELETE {
<urn:uuid:123123123> a rdfs:Resource .
}
@@ -181,16 +180,13 @@ class TrackerStoreInsertionTests (CommonTrackerStoreTest):
}
""")
-
-
-
- def test_insert_04(self):
- """
- Insert, delete same single valued properties multiple times.
- """
- for i in range (0, 3):
- # Delete single valued properties of music file.
- self.tracker.update("""
+ def test_insert_04(self):
+ """
+ Insert, delete same single valued properties multiple times.
+ """
+ for i in range(0, 3):
+ # Delete single valued properties of music file.
+ self.tracker.update("""
DELETE {
<test://instance-1> nie:usageCounter ?v
} WHERE {
@@ -203,194 +199,196 @@ class TrackerStoreInsertionTests (CommonTrackerStoreTest):
}
""")
- # Insert the same single valued properties of music file.
- self.tracker.update("""
+ # Insert the same single valued properties of music file.
+ self.tracker.update("""
INSERT {
<test://instance-1> a nmm:MusicPiece, nfo:FileDataObject;
nie:usageCounter '%d';
nie:contentAccessed '2000-01-01T00:4%d:47Z' .
}""" % (i, i))
- # Query for the property values and verify whether the last change is applied.
- result = self.tracker.query ("""
+ # Query for the property values and verify whether the last change
+ # is applied.
+ result = self.tracker.query ("""
SELECT ?playcount ?date WHERE {
<test://instance-1> a nmm:MusicPiece ;
nie:usageCounter ?playcount ;
nie:contentAccessed ?date.
}""")
- self.assertEqual (len (result), 1)
- self.assertEqual (len (result[0]), 2)
- self.assertEqual (int (result[0][0]), i)
- self.assertEqual (result[0][1], "2000-01-01T00:4%d:47Z" % (i))
+ self.assertEqual(len(result), 1)
+ self.assertEqual(len(result[0]), 2)
+ self.assertEqual(int(result[0][0]), i)
+ self.assertEqual(result[0][1], "2000-01-01T00:4%d:47Z" % (i))
- self.tracker.update ("""
+ self.tracker.update ("""
DELETE { <test://instance-1> a rdfs:Resource. }
""")
-
- def test_insert_05(self):
- """
- Insert or replace, single valued properties multiple times.
- """
- for i in range (0, 3):
- # Insert the same single valued properties of music file.
- self.tracker.update("""
+ def test_insert_05(self):
+ """
+ Insert or replace, single valued properties multiple times.
+ """
+ for i in range(0, 3):
+ # Insert the same single valued properties of music file.
+ self.tracker.update("""
INSERT OR REPLACE {
<test://instance-1> a nmm:MusicPiece, nfo:FileDataObject;
nie:usageCounter '%d';
nie:contentAccessed '2000-01-01T00:4%d:47Z' .
}""" % (i, i))
- # Query for the property values and verify whether the last change is applied.
- result = self.tracker.query ("""
+ # Query for the property values and verify whether the last change
+ # is applied.
+ result = self.tracker.query ("""
SELECT ?playcount ?date WHERE {
<test://instance-1> a nmm:MusicPiece ;
nie:usageCounter ?playcount ;
nie:contentAccessed ?date.
}""")
- self.assertEqual (len (result), 1)
- self.assertEqual (len (result[0]), 2)
- self.assertEqual (int (result[0][0]), i)
- self.assertEqual (result[0][1], "2000-01-01T00:4%d:47Z" % (i))
+ self.assertEqual(len(result), 1)
+ self.assertEqual(len(result[0]), 2)
+ self.assertEqual(int(result[0][0]), i)
+ self.assertEqual(result[0][1], "2000-01-01T00:4%d:47Z" % (i))
- self.tracker.update ("""
+ self.tracker.update ("""
DELETE { <test://instance-1> a rdfs:Resource. }
""")
- def test_insert_06(self):
- """
- Insert or replace, single and multi valued properties multiple times.
- """
- for i in range (0, 3):
- # Insert the same single valued properties and insert multi valued properties at the
same time
- self.tracker.update("""
+ def test_insert_06(self):
+ """
+ Insert or replace, single and multi valued properties multiple times.
+ """
+ for i in range(0, 3):
+ # Insert the same single valued properties and insert multi valued
+ # properties at the same time
+ self.tracker.update("""
INSERT OR REPLACE {
<test://instance-2> a nie:InformationElement;
nie:title '%d';
nie:keyword '%d'
}""" % (i, i))
- # Query for the property values and verify whether the last change is applied.
- result = self.tracker.query ("""
+ # Query for the property values and verify whether the last change
+ # is applied.
+ result = self.tracker.query ("""
SELECT ?t ?k WHERE {
<test://instance-2> nie:title ?t ;
nie:keyword ?k
}""")
- self.assertEqual (len (result), 3)
- self.assertEqual (len (result[0]), 2)
- self.assertEqual (result[0][0], "%d" % i)
- self.assertEqual (result[0][1], "0")
+ self.assertEqual(len(result), 3)
+ self.assertEqual(len(result[0]), 2)
+ self.assertEqual(result[0][0], "%d" % i)
+ self.assertEqual(result[0][1], "0")
- self.assertEqual (result[1][0], "%d" % i)
- self.assertEqual (result[1][1], "1")
+ self.assertEqual(result[1][0], "%d" % i)
+ self.assertEqual(result[1][1], "1")
- self.assertEqual (result[2][0], "%d" % i)
- self.assertEqual (result[2][1], "2")
+ self.assertEqual(result[2][0], "%d" % i)
+ self.assertEqual(result[2][1], "2")
- self.tracker.update ("""
+ self.tracker.update ("""
DELETE { <test://instance-2> a rdfs:Resource. }
""")
- def test_insert_07(self):
- """
- Insert or replace, single and multi valued properties with domain errors.
- """
+ def test_insert_07(self):
+ """
+ Insert or replace, single and multi valued properties with domain errors.
+ """
- try:
- INSERT_SPARQL = """INSERT OR REPLACE { <test://instance-3> nie:title 'test' }"""
- self.tracker.update (INSERT_SPARQL)
- except:
- pass
+ try:
+ INSERT_SPARQL = """INSERT OR REPLACE { <test://instance-3> nie:title 'test' }"""
+ self.tracker.update(INSERT_SPARQL)
+ except:
+ pass
- INSERT_SPARQL = """INSERT OR REPLACE { <test://instance-4> a nie:DataSource }"""
- self.tracker.update (INSERT_SPARQL)
+ INSERT_SPARQL = """INSERT OR REPLACE { <test://instance-4> a nie:DataSource }"""
+ self.tracker.update(INSERT_SPARQL)
- try:
- INSERT_SPARQL = """INSERT OR REPLACE { <test://instance-5> nie:rootElementOf
<test://instance-4> }"""
- self.tracker.update (INSERT_SPARQL)
- except:
- pass
+ try:
+ INSERT_SPARQL = """INSERT OR REPLACE { <test://instance-5> nie:rootElementOf <test://instance-4>
}"""
+ self.tracker.update(INSERT_SPARQL)
+ except:
+ pass
- INSERT_SPARQL = """INSERT OR REPLACE { <test://instance-5> a nie:InformationElement ;
nie:rootElementOf <test://instance-4> }"""
- self.tracker.update (INSERT_SPARQL)
+ INSERT_SPARQL = """INSERT OR REPLACE { <test://instance-5> a nie:InformationElement ;
nie:rootElementOf <test://instance-4> }"""
+ self.tracker.update(INSERT_SPARQL)
- self.tracker.update ("""
+ self.tracker.update ("""
DELETE { <test://instance-4> a rdfs:Resource. }
""")
- self.tracker.update ("""
+ self.tracker.update ("""
DELETE { <test://instance-5> a rdfs:Resource. }
""")
- def test_insert_08(self):
- """
- Insert or replace, single and multi valued properties with graphs
- """
+ def test_insert_08(self):
+ """
+ Insert or replace, single and multi valued properties with graphs
+ """
- INSERT_SPARQL = """INSERT { GRAPH <test://graph-1> { <test://instance-6> a
nie:InformationElement ; nie:title 'title 1' } }"""
- self.tracker.update (INSERT_SPARQL)
+ INSERT_SPARQL = """INSERT { GRAPH <test://graph-1> { <test://instance-6> a nie:InformationElement ;
nie:title 'title 1' } }"""
+ self.tracker.update(INSERT_SPARQL)
- INSERT_SPARQL = """INSERT { GRAPH <test://graph-2> { <test://instance-6> nie:title 'title 1'
} }"""
- self.tracker.update (INSERT_SPARQL)
+ INSERT_SPARQL = """INSERT { GRAPH <test://graph-2> { <test://instance-6> nie:title 'title 1' } }"""
+ self.tracker.update(INSERT_SPARQL)
- result = self.tracker.query ("""
+ result = self.tracker.query ("""
SELECT ?g ?t WHERE { GRAPH ?g {
<test://instance-6> nie:title ?t
} }""")
- self.assertEqual (len (result), 1)
- self.assertEqual (len (result[0]), 2)
- self.assertEqual (result[0][0], "test://graph-1") # Yes, indeed
- self.assertEqual (result[0][1], "title 1")
+ self.assertEqual(len(result), 1)
+ self.assertEqual(len(result[0]), 2)
+ self.assertEqual(result[0][0], "test://graph-1") # Yes, indeed
+ self.assertEqual(result[0][1], "title 1")
- INSERT_SPARQL = """INSERT OR REPLACE { GRAPH <test://graph-2> { <test://instance-6>
nie:title 'title 1' } }"""
- self.tracker.update (INSERT_SPARQL)
+ INSERT_SPARQL = """INSERT OR REPLACE { GRAPH <test://graph-2> { <test://instance-6> nie:title 'title
1' } }"""
+ self.tracker.update(INSERT_SPARQL)
- result = self.tracker.query ("""
+ result = self.tracker.query ("""
SELECT ?g ?t WHERE { GRAPH ?g {
<test://instance-6> nie:title ?t
} }""")
- self.assertEqual (len (result), 1)
- self.assertEqual (len (result[0]), 2)
- self.assertEqual (result[0][0], "test://graph-2") # Yup, that's right
- self.assertEqual (result[0][1], "title 1")
+ self.assertEqual(len(result), 1)
+ self.assertEqual(len(result[0]), 2)
+ self.assertEqual(result[0][0], "test://graph-2") # Yup, that's right
+ self.assertEqual(result[0][1], "title 1")
+ INSERT_SPARQL = """INSERT OR REPLACE { GRAPH <test://graph-3> { <test://instance-6> nie:title 'title
2' } }"""
+ self.tracker.update(INSERT_SPARQL)
- INSERT_SPARQL = """INSERT OR REPLACE { GRAPH <test://graph-3> { <test://instance-6>
nie:title 'title 2' } }"""
- self.tracker.update (INSERT_SPARQL)
-
- result = self.tracker.query ("""
+ result = self.tracker.query ("""
SELECT ?g ?t WHERE { GRAPH ?g {
<test://instance-6> nie:title ?t
} }""")
- self.assertEqual (len (result), 1)
- self.assertEqual (len (result[0]), 2)
- self.assertEqual (result[0][0], "test://graph-3")
- self.assertEqual (result[0][1], "title 2")
+ self.assertEqual(len(result), 1)
+ self.assertEqual(len(result[0]), 2)
+ self.assertEqual(result[0][0], "test://graph-3")
+ self.assertEqual(result[0][1], "title 2")
- self.tracker.update ("""
+ self.tracker.update ("""
DELETE { <test://instance-6> a rdfs:Resource. }
""")
- def __insert_valid_date_test (self, datestring, year, month, day, hours, minutes, seconds, timezone):
- """
- Insert a property with datestring value, retrieve its components and validate against
- the expected results (all the other parameters)
- """
- testId = random.randint (10, 1000)
- self.tracker.update ("""
+ def __insert_valid_date_test(self, datestring, year, month, day, hours, minutes, seconds, timezone):
+ """
+ Insert a property with datestring value, retrieve its components and validate against
+ the expected results (all the other parameters)
+ """
+ testId = random.randint(10, 1000)
+ self.tracker.update ("""
INSERT {
<test://instance-insert-date-%d> a nie:InformationElement;
nie:informationElementDate '%s'.
}
""" % (testId, datestring))
- result = self.tracker.query ("""
+ result = self.tracker.query ("""
SELECT fn:year-from-dateTime (?v)
fn:month-from-dateTime (?v)
fn:day-from-dateTime (?v)
@@ -403,80 +401,76 @@ class TrackerStoreInsertionTests (CommonTrackerStoreTest):
nie:informationElementDate ?v .
}
""" % (testId))
- try:
- self.assertEqual (len (result), 1)
- self.assertEqual (len (result[0]), 7)
- self.assertEqual (result[0][0], year)
- self.assertEqual (result[0][1], month)
- self.assertEqual (result[0][2], day)
- self.assertEqual (result[0][3], hours)
- self.assertEqual (result[0][4], minutes)
- self.assertEqual (result[0][5], seconds)
- # FIXME To validate this we need to take into account the locale
- # self.assertEquals (result[0][7], timezone)
- finally:
- self.tracker.update ("""
+ try:
+ self.assertEqual(len(result), 1)
+ self.assertEqual(len(result[0]), 7)
+ self.assertEqual(result[0][0], year)
+ self.assertEqual(result[0][1], month)
+ self.assertEqual(result[0][2], day)
+ self.assertEqual(result[0][3], hours)
+ self.assertEqual(result[0][4], minutes)
+ self.assertEqual(result[0][5], seconds)
+ # FIXME To validate this we need to take into account the locale
+ # self.assertEquals (result[0][7], timezone)
+ finally:
+ self.tracker.update ("""
DELETE { <test://instance-insert-date-%d> a rdfs:Resource. }
""" % (testId))
+ """Date-Time storage testing """
- """Date-Time storage testing """
- def test_insert_date_01 (self):
- """
- 1. Insert a InformationElement with date having local timezone info.
- 2. TEST: Query and verify the various componentes of date
- """
- self.__insert_valid_date_test ("2004-05-06T13:14:15+0400",
- "2004", "05", "06", "13", "14", "15", "14400")
-
-
- def test_insert_date_02 (self):
- """
- 1. Insert a InformationElement with date ending with "Z" in TZD.
- 2. TEST: Query and verify the various componentes of date
- """
- self.__insert_valid_date_test ("2004-05-06T13:14:15Z",
- "2004", "05", "06", "13", "14", "15", "0")
-
- def test_insert_date_03 (self):
- """
- 1. Insert a InformationElement with date ending with no TZD.
- 2. TEST: Query and verify the various componentes of date
- """
- self.__insert_valid_date_test ("2004-05-06T13:14:15",
- "2004", "05", "06", "13", "14", "15", "10800") # HEL timezone?
-
-
- #@ut.skipIf (1, "It times out in the daemon. Investigate")
- def test_insert_date_04 (self):
- """
- 1. Insert a InformationElement with date having local timezone info
- with some minutes in it.
- 2. TEST: Query and verify the various componentes of date
- """
- self.__insert_valid_date_test ("2004-05-06T13:14:15+0230",
- "2004", "05", "06", "13", "14", "15", "9000")
+ def test_insert_date_01(self):
+ """
+ 1. Insert a InformationElement with date having local timezone info.
+ 2. TEST: Query and verify the various componentes of date
+ """
+ self.__insert_valid_date_test("2004-05-06T13:14:15+0400",
+ "2004", "05", "06", "13", "14", "15", "14400")
+ def test_insert_date_02(self):
+ """
+ 1. Insert a InformationElement with date ending with "Z" in TZD.
+ 2. TEST: Query and verify the various componentes of date
+ """
+ self.__insert_valid_date_test("2004-05-06T13:14:15Z",
+ "2004", "05", "06", "13", "14", "15", "0")
- #@ut.skipIf (1, "It times out in the daemon. Investigate")
- def __test_insert_date_05 (self):
- """
- 1. Insert a InformationElement with date having local timezone info in negative.
- 2. TEST: Query and verify the various componentes of date
- """
- self.__insert_valid_date_test ("2004-05-06T13:14:15-0230",
- "2004", "05", "06", "13", "14", "15", "-9000")
+ def test_insert_date_03(self):
+ """
+ 1. Insert a InformationElement with date ending with no TZD.
+ 2. TEST: Query and verify the various componentes of date
+ """
+ self.__insert_valid_date_test("2004-05-06T13:14:15",
+ "2004", "05", "06", "13", "14", "15", "10800") # HEL timezone?
+ #@ut.skipIf (1, "It times out in the daemon. Investigate")
+ def test_insert_date_04(self):
+ """
+ 1. Insert a InformationElement with date having local timezone info
+ with some minutes in it.
+ 2. TEST: Query and verify the various componentes of date
+ """
+ self.__insert_valid_date_test("2004-05-06T13:14:15+0230",
+ "2004", "05", "06", "13", "14", "15", "9000")
- def __insert_invalid_date_test (self, datestring):
- self.assertRaises (Exception, self.tracker.update, """
+ #@ut.skipIf (1, "It times out in the daemon. Investigate")
+ def __test_insert_date_05(self):
+ """
+ 1. Insert a InformationElement with date having local timezone info in negative.
+ 2. TEST: Query and verify the various componentes of date
+ """
+ self.__insert_valid_date_test("2004-05-06T13:14:15-0230",
+ "2004", "05", "06", "13", "14", "15", "-9000")
+
+ def __insert_invalid_date_test(self, datestring):
+ self.assertRaises (Exception, self.tracker.update, """
INSERT {
<test://instance-insert-invalid-date-01> a nie:InformationElement;
nie:informationElementDate '204-05-06T13:14:15+0400'.
}
""")
- result = self.tracker.query ("""
+ result = self.tracker.query ("""
SELECT fn:year-from-dateTime (?v)
fn:month-from-dateTime (?v)
fn:day-from-dateTime (?v)
@@ -489,145 +483,162 @@ class TrackerStoreInsertionTests (CommonTrackerStoreTest):
nie:informationElementDate ?v .
}
""")
- self.assertEqual (len (result), 0)
-
- #@ut.skipIf (1, "It times out in the daemon. Investigate")
- def test_insert_invalid_date_01 (self):
- """
- 1. Insert a InformationElement with invalid year in date.
- 2. TEST: Query and verify the various componentes of date
- """
- self.__insert_invalid_date_test ("204-05-06T13:14:15+0400")
-
-
- #@ut.skipIf (1, "It times out in the daemon. Investigate")
- def test_insert_invalid_date_02 (self):
- """
- 1. Insert a InformationElement with date without time.
- 2. TEST: Query and verify the various componentes of date
- """
- self.__insert_invalid_date_test ("2004-05-06")
+ self.assertEqual(len(result), 0)
+ #@ut.skipIf (1, "It times out in the daemon. Investigate")
+ def test_insert_invalid_date_01(self):
+ """
+ 1. Insert a InformationElement with invalid year in date.
+ 2. TEST: Query and verify the various componentes of date
+ """
+ self.__insert_invalid_date_test("204-05-06T13:14:15+0400")
+ #@ut.skipIf (1, "It times out in the daemon. Investigate")
+ def test_insert_invalid_date_02(self):
+ """
+ 1. Insert a InformationElement with date without time.
+ 2. TEST: Query and verify the various componentes of date
+ """
+ self.__insert_invalid_date_test("2004-05-06")
- #@ut.skipIf (1, "It times out in the daemon. Investigate")
- def test_insert_invalid_date_03 (self):
- """
- 1. Insert a InformationElement with date without time but only the "T" separator.
- """
- self.__insert_invalid_date_test ("2004-05-06T")
+ #@ut.skipIf (1, "It times out in the daemon. Investigate")
+ def test_insert_invalid_date_03(self):
+ """
+ 1. Insert a InformationElement with date without time but only the "T" separator.
+ """
+ self.__insert_invalid_date_test("2004-05-06T")
- #@ut.skipIf (1, "It times out in the daemon. Investigate")
- def test_insert_invalid_date_04 (self):
- """
- 1. Insert a InformationElement with date without time but only the "T" separator.
- """
- self.__insert_invalid_date_test ("2004-05-06T1g:14:15-0200")
+ #@ut.skipIf (1, "It times out in the daemon. Investigate")
+ def test_insert_invalid_date_04(self):
+ """
+ 1. Insert a InformationElement with date without time but only the "T" separator.
+ """
+ self.__insert_invalid_date_test("2004-05-06T1g:14:15-0200")
- def test_insert_duplicated_url_01 (self):
- """
- 1. Insert a FileDataObject with a known nie:url, twice
- """
+ def test_insert_duplicated_url_01(self):
+ """
+ 1. Insert a FileDataObject with a known nie:url, twice
+ """
- url = "file:///some/magic/path/here"
+ url = "file:///some/magic/path/here"
- insert = """
+ insert = """
INSERT {
_:tag a nfo:FileDataObject;
nie:url '%s'.
}
""" % (url)
- # First insert should go ok
- self.tracker.update (insert)
- # Second insert should not be ok
- try:
- self.tracker.update (insert)
- except Exception:
- pass
+ # First insert should go ok
+ self.tracker.update(insert)
+ # Second insert should not be ok
+ try:
+ self.tracker.update(insert)
+ except Exception:
+ pass
- # Only 1 element must be available with the given nie:url
- select = """
+ # Only 1 element must be available with the given nie:url
+ select = """
SELECT ?u WHERE { ?u nie:url \"%s\" }
""" % (url)
- self.assertEqual (len (self.tracker.query (select)), 1)
+ self.assertEqual(len(self.tracker.query(select)), 1)
- # Cleanup
- self.tracker.update ("""
+ # Cleanup
+ self.tracker.update ("""
DELETE { ?u a rdfs:Resource } WHERE { ?u a rdfs:Resource ; nie:url '%s' }
""" % (url))
+ def test_insert_replace_null(self):
+ """
+ Insert or replace, with null
+ """
- def test_insert_replace_null(self):
- """
- Insert or replace, with null
- """
+ self.tracker.update(
+ """INSERT { <test://instance-null> a nie:DataObject, nie:InformationElement }""")
+ self.tracker.update(
+ """INSERT { <test://instance-ds1> a nie:DataSource }""")
+ self.tracker.update(
+ """INSERT { <test://instance-ds2> a nie:DataSource }""")
+ self.tracker.update(
+ """INSERT { <test://instance-ds3> a nie:DataSource }""")
+ self.tracker.update(
+ """INSERT { <test://instance-null> nie:dataSource <test://instance-ds1>, <test://instance-ds2>,
<test://instance-ds3> }""")
+
+ # null upfront, reset of list, rewrite of new list
+ self.tracker.update(
+ """INSERT OR REPLACE { <test://instance-null> nie:dataSource null, <test://instance-ds1>,
<test://instance-ds2> }""")
+ result = self.tracker.query(
+ """SELECT ?ds WHERE { <test://instance-null> nie:dataSource ?ds }""")
+ self.assertEqual(len(result), 2)
+ self.assertEqual(len(result[0]), 1)
+ self.assertEqual(len(result[1]), 1)
+ self.assertEqual(result[0][0], "test://instance-ds1")
+ self.assertEqual(result[1][0], "test://instance-ds2")
+
+ # null upfront, reset of list, rewrite of new list, second test
+ self.tracker.update(
+ """INSERT OR REPLACE { <test://instance-null> nie:dataSource null, <test://instance-ds1>,
<test://instance-ds2>, <test://instance-ds3> }""")
+ result = self.tracker.query(
+ """SELECT ?ds WHERE { <test://instance-null> nie:dataSource ?ds }""")
+ self.assertEqual(len(result), 3)
+ self.assertEqual(len(result[0]), 1)
+ self.assertEqual(len(result[1]), 1)
+ self.assertEqual(len(result[2]), 1)
+ self.assertEqual(result[0][0], "test://instance-ds1")
+ self.assertEqual(result[1][0], "test://instance-ds2")
+ self.assertEqual(result[2][0], "test://instance-ds3")
+
+ # null in the middle, rewrite of new list
+ self.tracker.update(
+ """INSERT OR REPLACE { <test://instance-null> nie:dataSource <test://instance-ds1>, null,
<test://instance-ds2>, <test://instance-ds3> }""")
+ result = self.tracker.query(
+ """SELECT ?ds WHERE { <test://instance-null> nie:dataSource ?ds }""")
+ self.assertEqual(len(result), 2)
+ self.assertEqual(len(result[0]), 1)
+ self.assertEqual(len(result[1]), 1)
+ self.assertEqual(result[0][0], "test://instance-ds2")
+ self.assertEqual(result[1][0], "test://instance-ds3")
+
+ # null at the end
+ self.tracker.update(
+ """INSERT OR REPLACE { <test://instance-null> nie:dataSource <test://instance-ds1>,
<test://instance-ds2>, <test://instance-ds3>, null }""")
+ result = self.tracker.query(
+ """SELECT ?ds WHERE { <test://instance-null> nie:dataSource ?ds }""")
+ self.assertEqual(len(result), 0)
+
+ # Multiple nulls
+ self.tracker.update(
+ """INSERT OR REPLACE { <test://instance-null> nie:dataSource null, <test://instance-ds1>, null,
<test://instance-ds2>, <test://instance-ds3> }""")
+ result = self.tracker.query(
+ """SELECT ?ds WHERE { <test://instance-null> nie:dataSource ?ds }""")
+ self.assertEqual(len(result), 2)
+ self.assertEqual(len(result[0]), 1)
+ self.assertEqual(len(result[1]), 1)
+ self.assertEqual(result[0][0], "test://instance-ds2")
+ self.assertEqual(result[1][0], "test://instance-ds3")
+
+ self.tracker.update(
+ """DELETE { <test://instance-null> a rdfs:Resource. }""")
+ self.tracker.update(
+ """DELETE { <test://instance-ds1> a rdfs:Resource. }""")
+ self.tracker.update(
+ """DELETE { <test://instance-ds2> a rdfs:Resource. }""")
+ self.tracker.update(
+ """DELETE { <test://instance-ds3> a rdfs:Resource. }""")
- self.tracker.update("""INSERT { <test://instance-null> a nie:DataObject,
nie:InformationElement }""")
- self.tracker.update("""INSERT { <test://instance-ds1> a nie:DataSource }""")
- self.tracker.update("""INSERT { <test://instance-ds2> a nie:DataSource }""")
- self.tracker.update("""INSERT { <test://instance-ds3> a nie:DataSource }""")
- self.tracker.update("""INSERT { <test://instance-null> nie:dataSource <test://instance-ds1>,
<test://instance-ds2>, <test://instance-ds3> }""")
-
- # null upfront, reset of list, rewrite of new list
- self.tracker.update("""INSERT OR REPLACE { <test://instance-null> nie:dataSource null,
<test://instance-ds1>, <test://instance-ds2> }""")
- result = self.tracker.query ("""SELECT ?ds WHERE { <test://instance-null> nie:dataSource ?ds
}""")
- self.assertEqual (len (result), 2)
- self.assertEqual (len (result[0]), 1)
- self.assertEqual (len (result[1]), 1)
- self.assertEqual (result[0][0], "test://instance-ds1")
- self.assertEqual (result[1][0], "test://instance-ds2")
-
- # null upfront, reset of list, rewrite of new list, second test
- self.tracker.update("""INSERT OR REPLACE { <test://instance-null> nie:dataSource null,
<test://instance-ds1>, <test://instance-ds2>, <test://instance-ds3> }""")
- result = self.tracker.query ("""SELECT ?ds WHERE { <test://instance-null> nie:dataSource ?ds
}""")
- self.assertEqual (len (result), 3)
- self.assertEqual (len (result[0]), 1)
- self.assertEqual (len (result[1]), 1)
- self.assertEqual (len (result[2]), 1)
- self.assertEqual (result[0][0], "test://instance-ds1")
- self.assertEqual (result[1][0], "test://instance-ds2")
- self.assertEqual (result[2][0], "test://instance-ds3")
-
- # null in the middle, rewrite of new list
- self.tracker.update("""INSERT OR REPLACE { <test://instance-null> nie:dataSource
<test://instance-ds1>, null, <test://instance-ds2>, <test://instance-ds3> }""")
- result = self.tracker.query ("""SELECT ?ds WHERE { <test://instance-null> nie:dataSource ?ds
}""")
- self.assertEqual (len (result), 2)
- self.assertEqual (len (result[0]), 1)
- self.assertEqual (len (result[1]), 1)
- self.assertEqual (result[0][0], "test://instance-ds2")
- self.assertEqual (result[1][0], "test://instance-ds3")
-
- # null at the end
- self.tracker.update("""INSERT OR REPLACE { <test://instance-null> nie:dataSource
<test://instance-ds1>, <test://instance-ds2>, <test://instance-ds3>, null }""")
- result = self.tracker.query ("""SELECT ?ds WHERE { <test://instance-null> nie:dataSource ?ds
}""")
- self.assertEqual (len (result), 0)
-
- # Multiple nulls
- self.tracker.update("""INSERT OR REPLACE { <test://instance-null> nie:dataSource null,
<test://instance-ds1>, null, <test://instance-ds2>, <test://instance-ds3> }""")
- result = self.tracker.query ("""SELECT ?ds WHERE { <test://instance-null> nie:dataSource ?ds
}""")
- self.assertEqual (len (result), 2)
- self.assertEqual (len (result[0]), 1)
- self.assertEqual (len (result[1]), 1)
- self.assertEqual (result[0][0], "test://instance-ds2")
- self.assertEqual (result[1][0], "test://instance-ds3")
-
- self.tracker.update ("""DELETE { <test://instance-null> a rdfs:Resource. }""")
- self.tracker.update ("""DELETE { <test://instance-ds1> a rdfs:Resource. }""")
- self.tracker.update ("""DELETE { <test://instance-ds2> a rdfs:Resource. }""")
- self.tracker.update ("""DELETE { <test://instance-ds3> a rdfs:Resource. }""")
class TrackerStoreDeleteTests (CommonTrackerStoreTest):
+ """
+ Use DELETE in Sparql and check the information is actually removed
+ """
+
+ def test_delete_01(self):
"""
- Use DELETE in Sparql and check the information is actually removed
+ Insert triples and Delete a triple. Verify the deletion with a query
"""
- def test_delete_01 (self):
- """
- Insert triples and Delete a triple. Verify the deletion with a query
- """
- # first insert
- self.tracker.update ("""
+ # first insert
+ self.tracker.update ("""
INSERT {
<urn:uuid:7646001> a nco:Contact;
nco:fullname 'Artist_1_delete'.
@@ -639,88 +650,87 @@ class TrackerStoreDeleteTests (CommonTrackerStoreTest):
}
""")
- # verify the insertion
- result = self.tracker.query ("""
+ # verify the insertion
+ result = self.tracker.query ("""
SELECT ?u WHERE {
?u a nmm:MusicPiece ;
nfo:genre 'Classic delete' .
}
""")
- self.assertEqual (len (result), 1)
- self.assertEqual (len (result[0]), 1)
- self.assertEqual (result[0][0], "test://instance-test-delete-01")
+ self.assertEqual(len(result), 1)
+ self.assertEqual(len(result[0]), 1)
+ self.assertEqual(result[0][0], "test://instance-test-delete-01")
- # now delete
- self.tracker.update("""
+ # now delete
+ self.tracker.update("""
DELETE {
<test://instance-test-delete-01> a rdfs:Resource.
}
""")
- # Check the instance is not there
- result = self.tracker.query ("""
+ # Check the instance is not there
+ result = self.tracker.query ("""
SELECT ?u WHERE {
?u a nmm:MusicPiece ;
nfo:genre 'Classic delete' .
}
""")
- self.assertEqual (len (result), 0)
-
+ self.assertEqual(len(result), 0)
- def test_delete_02 (self):
- """
- Delete a MusicAlbum and count the album
+ def test_delete_02(self):
+ """
+ Delete a MusicAlbum and count the album
- 1. add a music album.
- 2. count the number of albums
- 3. delete an album
- 2. count the number of albums
- """
+ 1. add a music album.
+ 2. count the number of albums
+ 3. delete an album
+ 2. count the number of albums
+ """
- initial = self.tracker.count_instances ("nmm:MusicAlbum")
+ initial = self.tracker.count_instances("nmm:MusicAlbum")
- """Add a music album """
- self.tracker.update ("""
+ """Add a music album """
+ self.tracker.update ("""
INSERT {
<test://instance-delete-02> a nmm:MusicAlbum;
nie:title '06_Album_delete'.
}
""")
- after_insert = self.tracker.count_instances ("nmm:MusicAlbum")
- self.assertEqual (initial+1, after_insert)
+ after_insert = self.tracker.count_instances("nmm:MusicAlbum")
+ self.assertEqual(initial + 1, after_insert)
- """Delete the added music album """
- self.tracker.update("""
+ """Delete the added music album """
+ self.tracker.update("""
DELETE {
<test://instance-delete-02> a nmm:MusicAlbum.
}
""")
- """get the count of music albums"""
- after_removal = self.tracker.count_instances ("nmm:MusicAlbum")
+ """get the count of music albums"""
+ after_removal = self.tracker.count_instances("nmm:MusicAlbum")
- self.assertEqual (after_removal, initial)
+ self.assertEqual(after_removal, initial)
class TrackerStoreBatchUpdateTest (CommonTrackerStoreTest):
+ """
+ Insert data using the BatchSparqlUpdate method in the store
+ """
+
+ def test_batch_insert_01(self):
"""
- Insert data using the BatchSparqlUpdate method in the store
+ batch insertion of 100 contacts:
+ 1. insert 100 contacts.
+ 2. delete the inserted contacts.
"""
+ NUMBER_OF_TEST_CONTACTS = 3
- def test_batch_insert_01(self):
- """
- batch insertion of 100 contacts:
- 1. insert 100 contacts.
- 2. delete the inserted contacts.
- """
- NUMBER_OF_TEST_CONTACTS = 3
-
- # query no. of existing contacts. (predefined instances in the DB)
- count_before_insert = self.tracker.count_instances ("nco:PersonContact")
+ # query no. of existing contacts. (predefined instances in the DB)
+ count_before_insert = self.tracker.count_instances("nco:PersonContact")
- # insert contacts.
- CONTACT_TEMPLATE = """
+ # insert contacts.
+ CONTACT_TEMPLATE = """
<test://instance-contact-%d> a nco:PersonContact ;
nco:nameGiven 'Contact-name %d';
nco:nameFamily 'Contact-family %d';
@@ -729,33 +739,37 @@ class TrackerStoreBatchUpdateTest (CommonTrackerStoreTest):
nco:hasPhoneNumber <tel:%s> .
"""
- global contact_list
- contact_list = []
- def complete_contact (contact_template):
- random_phone = "".join ([str(random.randint (0, 9)) for i in range (0, 9)])
- contact_counter = random.randint (0, 10000)
-
- # Avoid duplicates
- while contact_counter in contact_list:
- contact_counter = random.randint (0, 10000)
- contact_list.append (contact_counter)
-
- return contact_template % (contact_counter,
- contact_counter,
- contact_counter,
- contact_counter,
- random_phone)
-
- contacts = list(map (complete_contact, [CONTACT_TEMPLATE] * NUMBER_OF_TEST_CONTACTS))
- INSERT_SPARQL = "\n".join (["INSERT {"] + contacts +["}"])
- self.tracker.batch_update (INSERT_SPARQL)
-
- # Check all instances are in
- count_after_insert = self.tracker.count_instances ("nco:PersonContact")
- self.assertEqual (count_before_insert + NUMBER_OF_TEST_CONTACTS, count_after_insert)
-
- """ Delete the inserted contacts """
- DELETE_SPARQL = """
+ global contact_list
+ contact_list = []
+
+ def complete_contact(contact_template):
+ random_phone = "".join([str(random.randint(0, 9))
+ for i in range(0, 9)])
+ contact_counter = random.randint(0, 10000)
+
+ # Avoid duplicates
+ while contact_counter in contact_list:
+ contact_counter = random.randint(0, 10000)
+ contact_list.append(contact_counter)
+
+ return contact_template % (contact_counter,
+ contact_counter,
+ contact_counter,
+ contact_counter,
+ random_phone)
+
+ contacts = list(
+ map(complete_contact, [CONTACT_TEMPLATE] * NUMBER_OF_TEST_CONTACTS))
+ INSERT_SPARQL = "\n".join(["INSERT {"] + contacts + ["}"])
+ self.tracker.batch_update(INSERT_SPARQL)
+
+ # Check all instances are in
+ count_after_insert = self.tracker.count_instances("nco:PersonContact")
+ self.assertEqual(count_before_insert +
+ NUMBER_OF_TEST_CONTACTS, count_after_insert)
+
+ """ Delete the inserted contacts """
+ DELETE_SPARQL = """
DELETE {
?x a rdfs:Resource .
} WHERE {
@@ -763,34 +777,35 @@ class TrackerStoreBatchUpdateTest (CommonTrackerStoreTest):
nie:generator 'test-instance-to-remove' .
}
"""
- self.tracker.update (DELETE_SPARQL)
- count_final = self.tracker.count_instances ("nco:PersonContact")
- self.assertEqual (count_before_insert, count_final)
+ self.tracker.update(DELETE_SPARQL)
+ count_final = self.tracker.count_instances("nco:PersonContact")
+ self.assertEqual(count_before_insert, count_final)
+
class TrackerStorePhoneNumberTest (CommonTrackerStoreTest):
+ """
+ Tests around phone numbers (maemo specific). Inserting correct/incorrect ones
+ and running query to get the contact from the number.
+ """
+
+ def test_phone_01(self):
"""
- Tests around phone numbers (maemo specific). Inserting correct/incorrect ones
- and running query to get the contact from the number.
+ 1. Setting the maemo:localPhoneNumber property to last 7 digits of phone number.
+ 2. Receiving a message from a contact whose localPhoneNumber is saved.
+ 3. Query messages from the local phone number
"""
-
- def test_phone_01 (self):
- """
- 1. Setting the maemo:localPhoneNumber property to last 7 digits of phone number.
- 2. Receiving a message from a contact whose localPhoneNumber is saved.
- 3. Query messages from the local phone number
- """
- PhoneNumber = str(random.randint (0, sys.maxsize))
- UUID = str(time.time())
- UUID1 = str(random.randint (0, sys.maxsize))
- UUID2 = str(random.randint (0, sys.maxsize))
- localNumber = PhoneNumber[-7:]
- d=datetime.datetime.now()
- Received=d.isoformat()
- ID = int(time.time())%1000
- Given_Name = 'test_GN_' + repr(ID)
- Family_Name = 'test_FN_' + repr(ID)
-
- INSERT_CONTACT_PHONE = """
+ PhoneNumber = str(random.randint(0, sys.maxsize))
+ UUID = str(time.time())
+ UUID1 = str(random.randint(0, sys.maxsize))
+ UUID2 = str(random.randint(0, sys.maxsize))
+ localNumber = PhoneNumber[-7:]
+ d = datetime.datetime.now()
+ Received = d.isoformat()
+ ID = int(time.time()) % 1000
+ Given_Name = 'test_GN_' + repr(ID)
+ Family_Name = 'test_FN_' + repr(ID)
+
+ INSERT_CONTACT_PHONE = """
INSERT {
<tel:123456789> a nco:PhoneNumber ;
nco:phoneNumber '00358555444333' ;
@@ -803,9 +818,9 @@ class TrackerStorePhoneNumberTest (CommonTrackerStoreTest):
<test://test_phone_1/contact> nco:hasPhoneNumber <tel:123456789>.
}
"""
- self.tracker.update (INSERT_CONTACT_PHONE)
+ self.tracker.update(INSERT_CONTACT_PHONE)
- INSERT_MESSAGE = """
+ INSERT_MESSAGE = """
INSERT {
<test://test_phone_1/message> a nmo:Message ;
nmo:from [a nco:Contact ; nco:hasPhoneNumber <tel:123456789>];
@@ -813,26 +828,25 @@ class TrackerStorePhoneNumberTest (CommonTrackerStoreTest):
nie:plainTextContent 'hello'
}
"""
- self.tracker.update (INSERT_MESSAGE)
+ self.tracker.update(INSERT_MESSAGE)
- QUERY_SPARQL = """
+ QUERY_SPARQL = """
SELECT ?msg WHERE {
?msg a nmo:Message;
nmo:from ?c .
?c nco:hasPhoneNumber ?n .
?n maemo:localPhoneNumber '5444333'.
} """
- result = self.tracker.query (QUERY_SPARQL)
- self.assertEqual (len (result), 1)
- self.assertEqual (len (result[0]), 1)
- self.assertEqual (result[0][0], "test://test_phone_1/message")
-
+ result = self.tracker.query(QUERY_SPARQL)
+ self.assertEqual(len(result), 1)
+ self.assertEqual(len(result[0]), 1)
+ self.assertEqual(result[0][0], "test://test_phone_1/message")
- def test_phone_02 (self):
- """
- Inserting a local phone number which have spaces
- """
- INSERT_SPARQL = """
+ def test_phone_02(self):
+ """
+ Inserting a local phone number which have spaces
+ """
+ INSERT_SPARQL = """
INSERT {
<tel+3333333333> a nco:PhoneNumber ;
nco:phoneNumber <tel+3333333333> ;
@@ -844,8 +858,8 @@ class TrackerStorePhoneNumberTest (CommonTrackerStoreTest):
nco:hasPhoneNumber <tel+3333333333> .
}
"""
- self.assertRaises (Exception, self.tracker.update (INSERT_SPARQL))
+ self.assertRaises(Exception, self.tracker.update(INSERT_SPARQL))
if __name__ == "__main__":
- ut.main()
+ ut.main()
diff --git a/tests/functional-tests/02-sparql-bugs.py b/tests/functional-tests/02-sparql-bugs.py
index 30ec777be..c5f23674f 100755
--- a/tests/functional-tests/02-sparql-bugs.py
+++ b/tests/functional-tests/02-sparql-bugs.py
@@ -29,11 +29,11 @@ from common.utils.storetest import CommonTrackerStoreTest as CommonTrackerStoreT
class TrackerStoreSparqlBugsTests (CommonTrackerStoreTest):
- def test_01_NB217566_union_exists_filter (self):
- """
- NB217566: Use of UNION in EXISTS in a FILTER breaks filtering
- """
- content = """
+ def test_01_NB217566_union_exists_filter(self):
+ """
+ NB217566: Use of UNION in EXISTS in a FILTER breaks filtering
+ """
+ content = """
INSERT {
<contact:affiliation> a nco:Affiliation ;
nco:hasPhoneNumber
@@ -42,10 +42,10 @@ class TrackerStoreSparqlBugsTests (CommonTrackerStoreTest):
nco:hasAffiliation <contact:affiliation> .
}
"""
- self.tracker.update (content)
+ self.tracker.update(content)
- """ Check that these 3 queries return the same results """
- query1 = """
+ """ Check that these 3 queries return the same results """
+ query1 = """
SELECT ?_contact ?n WHERE {
?_contact a nco:PersonContact .
{
@@ -72,7 +72,7 @@ class TrackerStoreSparqlBugsTests (CommonTrackerStoreTest):
}
"""
- query2 = """
+ query2 = """
SELECT ?_contact ?n WHERE {
?_contact a nco:PersonContact .
{
@@ -87,7 +87,7 @@ class TrackerStoreSparqlBugsTests (CommonTrackerStoreTest):
}
"""
- query3 = """
+ query3 = """
SELECT ?_contact ?n WHERE {
?_contact a nco:PersonContact .
{
@@ -109,142 +109,137 @@ class TrackerStoreSparqlBugsTests (CommonTrackerStoreTest):
}
"""
- results1 = self.tracker.query (query1)
- print("1", results1)
- self.assertEqual (len (results1), 1)
- self.assertEqual (len (results1[0]), 2)
- self.assertEqual (results1[0][0], "contact:test")
- self.assertEqual (results1[0][1], "98653")
-
- results2 = self.tracker.query (query2)
- print("2", results2)
- self.assertEqual (len (results2), 1)
- self.assertEqual (len (results2[0]), 2)
- self.assertEqual (results2[0][0], "contact:test")
- self.assertEqual (results2[0][1], "98653")
-
-
- results3 = self.tracker.query (query3)
- print("3", results3)
- self.assertEqual (len (results3), 1)
- self.assertEqual (len (results3[0]), 2)
- self.assertEqual (results3[0][0], "contact:test")
- self.assertEqual (results3[0][1], "98653")
-
- """ Clean the DB """
- delete = """
+ results1 = self.tracker.query(query1)
+ print("1", results1)
+ self.assertEqual(len(results1), 1)
+ self.assertEqual(len(results1[0]), 2)
+ self.assertEqual(results1[0][0], "contact:test")
+ self.assertEqual(results1[0][1], "98653")
+
+ results2 = self.tracker.query(query2)
+ print("2", results2)
+ self.assertEqual(len(results2), 1)
+ self.assertEqual(len(results2[0]), 2)
+ self.assertEqual(results2[0][0], "contact:test")
+ self.assertEqual(results2[0][1], "98653")
+
+ results3 = self.tracker.query(query3)
+ print("3", results3)
+ self.assertEqual(len(results3), 1)
+ self.assertEqual(len(results3[0]), 2)
+ self.assertEqual(results3[0][0], "contact:test")
+ self.assertEqual(results3[0][1], "98653")
+
+ """ Clean the DB """
+ delete = """
DELETE { <contact:affiliation> a rdfs:Resource .
<contact:test> a rdfs:Resource .
}
- """
-
- def test_02_NB217636_delete_statements (self):
- """
- Bug 217636 - Not able to delete contact using
- DELETE {<contact:556> ?p ?v} WHERE {<contact:556> ?p ?v}.
"""
- data = """ INSERT {
+
+ def test_02_NB217636_delete_statements(self):
+ """
+ Bug 217636 - Not able to delete contact using
+ DELETE {<contact:556> ?p ?v} WHERE {<contact:556> ?p ?v}.
+ """
+ data = """ INSERT {
<contact:test-nb217636> a nco:PersonContact ;
nco:fullname 'Testing bug 217636'
}
"""
- self.tracker.update (data)
+ self.tracker.update(data)
- results = self.tracker.query ("""
+ results = self.tracker.query ("""
SELECT ?u WHERE {
?u a nco:PersonContact ;
nco:fullname 'Testing bug 217636' .
}
""")
- self.assertEqual (len (results), 1)
- self.assertEqual (len (results[0]), 1)
- self.assertEqual (results[0][0], "contact:test-nb217636")
+ self.assertEqual(len(results), 1)
+ self.assertEqual(len(results[0]), 1)
+ self.assertEqual(results[0][0], "contact:test-nb217636")
- problematic_delete = """
+ problematic_delete = """
DELETE { <contact:test-nb217636> ?p ?v }
WHERE { <contact:test-nb217636> ?p ?v }
"""
- self.tracker.update (problematic_delete)
+ self.tracker.update(problematic_delete)
- results_after = self.tracker.query ("""
+ results_after = self.tracker.query ("""
SELECT ?u WHERE {
?u a nco:PersonContact ;
nco:fullname 'Testing bug 217636' .
}
""")
- self.assertEqual (len (results_after), 0)
+ self.assertEqual(len(results_after), 0)
- # Safe deletion
- delete = """
+ # Safe deletion
+ delete = """
DELETE { <contact:test-nb217636> a rdfs:Resource. }
"""
- self.tracker.update (delete)
-
-
- def test_03_NB222645_non_existing_class_resource (self):
- """
- NB222645 - Inserting a resource using an non-existing class, doesn't rollback completely
- """
- query = "SELECT tracker:modified (?u) ?u WHERE { ?u a nco:Contact }"
- original_data = self.tracker.query (query)
-
- wrong_insert = "INSERT { <test://nb222645-wrong-class-contact> a nco:IMContact. } "
- self.assertRaises (GLib.Error,
- self.tracker.update,
- wrong_insert)
-
- new_data = self.tracker.query (query)
- self.assertEqual (len (original_data), len (new_data))
- # We could be more picky, but checking there are the same number of results
- # is enough to verify the problem described in the bug.
-
-
- def test_04_NB224760_too_long_filter (self):
- """
- NB#224760 - 'too many sql variables' when filter ?sth in (long list)
- """
- query = "SELECT tracker:id (?m) ?m WHERE { ?m a rdfs:Resource. FILTER (tracker:id (?m) in
(%s)) }"
- numbers = ",".join ([str (i) for i in range (1000, 2000)])
-
- results = self.tracker.query (query % (numbers))
-
- # The query will raise an exception is the bug is there
- # If we are here, everything is fine.
- self.assertIsNotNone (results)
-
- def test_05_NB281201_insert_replace_and_superproperties (self):
- """
- Bug 281201 - INSERT OR REPLACE does not delete previous values for superproperties
- """
- content = """INSERT { <test:resource:nb281201> a nie:InformationElement;
+ self.tracker.update(delete)
+
+ def test_03_NB222645_non_existing_class_resource(self):
+ """
+ NB222645 - Inserting a resource using an non-existing class, doesn't rollback completely
+ """
+ query = "SELECT tracker:modified (?u) ?u WHERE { ?u a nco:Contact }"
+ original_data = self.tracker.query(query)
+
+ wrong_insert = "INSERT { <test://nb222645-wrong-class-contact> a nco:IMContact. } "
+ self.assertRaises(GLib.Error,
+ self.tracker.update,
+ wrong_insert)
+
+ new_data = self.tracker.query(query)
+ self.assertEqual(len(original_data), len(new_data))
+ # We could be more picky, but checking there are the same number of results
+ # is enough to verify the problem described in the bug.
+
+ def test_04_NB224760_too_long_filter(self):
+ """
+ NB#224760 - 'too many sql variables' when filter ?sth in (long list)
+ """
+ query = "SELECT tracker:id (?m) ?m WHERE { ?m a rdfs:Resource. FILTER (tracker:id (?m) in (%s)) }"
+ numbers = ",".join([str(i) for i in range(1000, 2000)])
+
+ results = self.tracker.query(query % (numbers))
+
+ # The query will raise an exception is the bug is there
+ # If we are here, everything is fine.
+ self.assertIsNotNone(results)
+
+ def test_05_NB281201_insert_replace_and_superproperties(self):
+ """
+ Bug 281201 - INSERT OR REPLACE does not delete previous values for superproperties
+ """
+ content = """INSERT { <test:resource:nb281201> a nie:InformationElement;
nie:contentLastModified '2011-09-27T11:11:11Z'. }"""
- self.tracker.update (content)
+ self.tracker.update(content)
- query = """SELECT ?contentLM ?nieIEDate ?dcDate {
+ query = """SELECT ?contentLM ?nieIEDate ?dcDate {
<test:resource:nb281201> dc:date ?dcDate ;
nie:informationElementDate ?nieIEDate ;
nie:contentLastModified ?contentLM .
}"""
- result = self.tracker.query (query)
- # Only one row of results, and the 3 colums have the same value
- self.assertEqual (len (result), 1)
- self.assertEqual (result[0][0], result[0][1])
- self.assertEqual (result[0][1], result[0][2])
+ result = self.tracker.query(query)
+ # Only one row of results, and the 3 colums have the same value
+ self.assertEqual(len(result), 1)
+ self.assertEqual(result[0][0], result[0][1])
+ self.assertEqual(result[0][1], result[0][2])
- problematic = """INSERT OR REPLACE {
+ problematic = """INSERT OR REPLACE {
<test:resource:nb281201> nie:contentLastModified '2012-10-28T12:12:12'
}"""
-
- self.tracker.update (problematic)
- result = self.tracker.query (query)
- # Only one row of results, and the 3 colums have the same value
- self.assertEqual (len (result), 1)
- self.assertEqual (result[0][0], result[0][1])
- self.assertEqual (result[0][1], result[0][2])
-
+ self.tracker.update(problematic)
+ result = self.tracker.query(query)
+ # Only one row of results, and the 3 colums have the same value
+ self.assertEqual(len(result), 1)
+ self.assertEqual(result[0][0], result[0][1])
+ self.assertEqual(result[0][1], result[0][2])
if __name__ == "__main__":
- ut.main()
+ ut.main()
diff --git a/tests/functional-tests/03-fts-functions.py b/tests/functional-tests/03-fts-functions.py
index 98086a35e..df2668b22 100755
--- a/tests/functional-tests/03-fts-functions.py
+++ b/tests/functional-tests/03-fts-functions.py
@@ -25,12 +25,13 @@ and run sparql with fts functions to check the results.
import unittest as ut
from common.utils.storetest import CommonTrackerStoreTest as CommonTrackerStoreTest
+
class TestFTSFunctions (CommonTrackerStoreTest):
"""
Insert data with text and check the fts:xxxx functions are returning the expected results
"""
@ut.skip("Test currently fails.")
- def test_fts_rank (self):
+ def test_fts_rank(self):
"""
1. Insert a Contact1 with 'abcdefxyz' as fullname and nickname
2. Insert a Contact2 with 'abcdefxyz' as fullname
@@ -53,7 +54,7 @@ class TestFTSFunctions (CommonTrackerStoreTest):
nco:nickname 'abcdefxyz abcdefxyz' .
}
"""
- self.tracker.update (insert_sparql)
+ self.tracker.update(insert_sparql)
query = """
SELECT ?contact WHERE {
@@ -61,12 +62,12 @@ class TestFTSFunctions (CommonTrackerStoreTest):
fts:match 'abcdefxyz' .
} ORDER BY DESC (fts:rank(?contact))
"""
- results = self.tracker.query (query)
+ results = self.tracker.query(query)
- self.assertEqual (len(results), 3)
- self.assertEqual (results[0][0], "contact://test/fts-function/rank/1")
- self.assertEqual (results[1][0], "contact://test/fts-function/rank/2")
- self.assertEqual (results[2][0], "contact://test/fts-function/rank/3")
+ self.assertEqual(len(results), 3)
+ self.assertEqual(results[0][0], "contact://test/fts-function/rank/1")
+ self.assertEqual(results[1][0], "contact://test/fts-function/rank/2")
+ self.assertEqual(results[2][0], "contact://test/fts-function/rank/3")
delete_sparql = """
DELETE {
@@ -75,10 +76,9 @@ class TestFTSFunctions (CommonTrackerStoreTest):
<contact://test/fts-function/rank/3> a rdfs:Resource .
}
"""
- self.tracker.update (delete_sparql)
-
+ self.tracker.update(delete_sparql)
- def test_fts_offsets (self):
+ def test_fts_offsets(self):
"""
1. Insert a Contact1 with 'abcdefxyz' as fullname and nickname
2. Insert a Contact2 with 'abcdefxyz' as fullname
@@ -101,7 +101,7 @@ class TestFTSFunctions (CommonTrackerStoreTest):
nco:nickname 'abcdefxyz abcdefxyz' .
}
"""
- self.tracker.update (insert_sparql)
+ self.tracker.update(insert_sparql)
query = """
SELECT fts:offsets (?contact) WHERE {
@@ -109,12 +109,13 @@ class TestFTSFunctions (CommonTrackerStoreTest):
fts:match 'abcdefxyz' .
}
"""
- results = self.tracker.query (query)
+ results = self.tracker.query(query)
- self.assertEqual (len(results), 3)
- self.assertEqual (results[0][0], 'nco:fullname,0,nco:nickname,0')
- self.assertEqual (results[1][0], 'nco:fullname,0')
- self.assertEqual (results[2][0], 'nco:fullname,0,nco:nickname,0,nco:nickname,10')
+ self.assertEqual(len(results), 3)
+ self.assertEqual(results[0][0], 'nco:fullname,0,nco:nickname,0')
+ self.assertEqual(results[1][0], 'nco:fullname,0')
+ self.assertEqual(
+ results[2][0], 'nco:fullname,0,nco:nickname,0,nco:nickname,10')
delete_sparql = """
DELETE {
@@ -123,7 +124,7 @@ class TestFTSFunctions (CommonTrackerStoreTest):
<contact://test/fts-function/offset/3> a rdfs:Resource .
}
"""
- self.tracker.update (delete_sparql)
+ self.tracker.update(delete_sparql)
if __name__ == '__main__':
diff --git a/tests/functional-tests/04-group-concat.py b/tests/functional-tests/04-group-concat.py
index 2bdf8503a..3ae53239a 100755
--- a/tests/functional-tests/04-group-concat.py
+++ b/tests/functional-tests/04-group-concat.py
@@ -23,20 +23,22 @@ Test the GROUP_CONCAT function in Sparql. Only requires the store.
import unittest as ut
from common.utils.storetest import CommonTrackerStoreTest as CommonTrackerStoreTest
+
class TestGroupConcat (CommonTrackerStoreTest):
"""
Insert a multivalued property and request the results in GROUP_CONCAT
"""
- def test_group_concat (self):
+
+ def test_group_concat(self):
"""
1. Insert 3 capabilities for a test contact
2. Retrieve contact/capabilites without group_contact (3 results)
2. TEST: contact with group_concat capabilities (1 result)
3. Remove the test contact inserted
"""
-
+
uri = "contact://test_group_concat"
-
+
insert = """
INSERT { <%s> a nco:IMAddress;
nco:imID \"test_group_concat\";
@@ -45,7 +47,7 @@ class TestGroupConcat (CommonTrackerStoreTest):
nco:imCapability nco:im-capability-file-transfers .
}
""" % (uri)
- self.tracker.update (insert)
+ self.tracker.update(insert)
query = """
SELECT ?c ?capability WHERE {
@@ -53,23 +55,23 @@ class TestGroupConcat (CommonTrackerStoreTest):
nco:imID \"test_group_concat\";
nco:imCapability ?capability .
}
- """
- results = self.tracker.query (query)
+ """
+ results = self.tracker.query(query)
- assert len (results) == 3
+ assert len(results) == 3
group_concat_query = """
SELECT ?c GROUP_CONCAT (?capability, '|') AS ?cap WHERE {
?c a nco:IMAddress ;
nco:imID \"test_group_concat\";
nco:imCapability ?capability .
} GROUP BY (?c)
- """
- results = self.tracker.query (group_concat_query)
- assert len (results) == 1
-
- instances = results[0][1].split ('|')
- assert len (instances) == 3
-
+ """
+ results = self.tracker.query(group_concat_query)
+ assert len(results) == 1
+
+ instances = results[0][1].split('|')
+ assert len(instances) == 3
+
TEXT_CHAT = "http://www.semanticdesktop.org/ontologies/2007/03/22/nco#im-capability-text-chat"
MEDIA_CALLS = "http://www.semanticdesktop.org/ontologies/2007/03/22/nco#im-capability-media-calls"
FILE_TRANSFERS =
"http://www.semanticdesktop.org/ontologies/2007/03/22/nco#im-capability-file-transfers"
@@ -77,14 +79,13 @@ class TestGroupConcat (CommonTrackerStoreTest):
assert MEDIA_CALLS in instances
assert FILE_TRANSFERS in instances
-
#self.assertEquals (str(results[0][0]), "test_insertion_1")
delete = """
DELETE { <%s> a rdfs:Resource. }
""" % (uri)
- self.tracker.update (delete)
-
+ self.tracker.update(delete)
+
if __name__ == '__main__':
ut.main()
diff --git a/tests/functional-tests/05-coalesce.py b/tests/functional-tests/05-coalesce.py
index 6a3a6e302..a9ef15aab 100755
--- a/tests/functional-tests/05-coalesce.py
+++ b/tests/functional-tests/05-coalesce.py
@@ -23,13 +23,14 @@ Test tracker:coalesce function in Sparql. Only uses the Store
import unittest as ut
from common.utils.storetest import CommonTrackerStoreTest as CommonTrackerStoreTest
+
class TestCoalesce (CommonTrackerStoreTest):
"""
Insert and instance with some values, and tracker coalesce of some of them
with different combinations (first NULL, none NULL, all NULL...)
"""
- def setUp (self):
+ def setUp(self):
self.resource_uri = "contact://test_group_concat"
#
@@ -41,17 +42,15 @@ class TestCoalesce (CommonTrackerStoreTest):
nco:nameFamily \"family name\" .
}
""" % (self.resource_uri)
- self.tracker.update (insert)
+ self.tracker.update(insert)
- def tearDown (self):
+ def tearDown(self):
delete = """
DELETE { <%s> a rdfs:Resource. }
""" % (self.resource_uri)
- self.tracker.update (delete)
-
+ self.tracker.update(delete)
-
- def test_coalesce_first_fine (self):
+ def test_coalesce_first_fine(self):
"""
setUp: Insert a contact with only some text properties set
1. TEST: run a query with coalesce with the valid value in first position
@@ -67,13 +66,12 @@ class TestCoalesce (CommonTrackerStoreTest):
OPTIONAL { ?c nco:note ?note }
FILTER (?c != nco:default-contact-me && ?c != nco:default-contact-emergency)
}
- """
- results = self.tracker.query (query)
- assert len (results) == 1
+ """
+ results = self.tracker.query(query)
+ assert len(results) == 1
assert results[0][0] == "full name"
-
- def test_coalesce_second_fine (self):
+ def test_coalesce_second_fine(self):
"""
setUp: Insert a contact with only some text properties set
1. TEST: run a query with coalesce. First property NULL, second fine
@@ -89,13 +87,12 @@ class TestCoalesce (CommonTrackerStoreTest):
OPTIONAL { ?c nco:note ?note }
FILTER (?c != nco:default-contact-me && ?c != nco:default-contact-emergency)
}
- """
- results = self.tracker.query (query)
- assert len (results) == 1
+ """
+ results = self.tracker.query(query)
+ assert len(results) == 1
assert results[0][0] == "family name"
-
- def test_coalesce_none_fine_default (self):
+ def test_coalesce_none_fine_default(self):
"""
setUp: Insert a contact with only some text properties set
1. TEST: run a query with coalesce. all variables NULL, return default value
@@ -111,11 +108,11 @@ class TestCoalesce (CommonTrackerStoreTest):
OPTIONAL { ?c nco:note ?note }
FILTER (?c != nco:default-contact-me && ?c != nco:default-contact-emergency)
}
- """
- results = self.tracker.query (query)
- assert len (results) == 1
+ """
+ results = self.tracker.query(query)
+ assert len(results) == 1
assert results[0][0] == "test_coalesce"
-
+
if __name__ == '__main__':
ut.main()
diff --git a/tests/functional-tests/06-distance.py b/tests/functional-tests/06-distance.py
index f3e0da55e..52191559f 100755
--- a/tests/functional-tests/06-distance.py
+++ b/tests/functional-tests/06-distance.py
@@ -25,13 +25,15 @@ from common.utils.storetest import CommonTrackerStoreTest as CommonTrackerStoreT
POINT_COORDS = [
(0, 0), (1, 1), (2, 2), (3, 3), (4, 4)
- ]
+]
+
class TestDistanceFunctions (CommonTrackerStoreTest):
"""
Insert some points and get the distance between them.
"""
- def setUp (self):
+
+ def setUp(self):
self.counter = 0
for lat, log in POINT_COORDS:
insert = """
@@ -41,25 +43,24 @@ class TestDistanceFunctions (CommonTrackerStoreTest):
mlo:latitude %d .
}
""" % ("point://test/point/" + str(self.counter), log, lat)
- self.tracker.update (insert)
+ self.tracker.update(insert)
self.counter += 1
- def tearDown (self):
- for i in range (0, self.counter):
+ def tearDown(self):
+ for i in range(0, self.counter):
delete = """
DELETE {
<%s> a rdfs:Resource.
}
""" % ("point://test/point/" + str (i))
- self.tracker.update (delete)
-
+ self.tracker.update(delete)
- def get_distance_between_points (self, sum_func, id1, id2):
+ def get_distance_between_points(self, sum_func, id1, id2):
- assert 0 <= id1 <= len (POINT_COORDS)
- assert 0 <= id2 <= len (POINT_COORDS)
+ assert 0 <= id1 <= len(POINT_COORDS)
+ assert 0 <= id2 <= len(POINT_COORDS)
assert sum_func == "cartesian" or sum_func == "haversine"
-
+
query_1_to_2 = """
SELECT xsd:integer(tracker:%s-distance(?lat1,?lat2,?lon1,?lon2))
WHERE {
@@ -72,58 +73,56 @@ class TestDistanceFunctions (CommonTrackerStoreTest):
mlo:longitude ?lon2 .
}
""" % (sum_func, id1, id2)
- result = self.tracker.query (query_1_to_2)
- return int (result[0][0])
-
-
- def test_distance_cartesian_symmetry (self):
+ result = self.tracker.query(query_1_to_2)
+ return int(result[0][0])
+
+ def test_distance_cartesian_symmetry(self):
"""
setUp: Insert 5 points in the pre-defined coordinates
1. TEST: Check cartesian distance from point A to B, and from B to A
(should be the same :P)
tearDown: Remove the test points inserted before
"""
- a_to_b = self.get_distance_between_points ("cartesian", 1, 2)
+ a_to_b = self.get_distance_between_points("cartesian", 1, 2)
assert a_to_b == 204601
- b_to_a = self.get_distance_between_points ("cartesian", 2, 1)
+ b_to_a = self.get_distance_between_points("cartesian", 2, 1)
assert b_to_a == 204601
- assert a_to_b == b_to_a
+ assert a_to_b == b_to_a
- def test_distance_haversine_symmetry (self):
+ def test_distance_haversine_symmetry(self):
"""
setUp: Insert 5 points in the pre-defined coordinates
1. TEST: Check cartesian distance from point A to B, and from B to A
(should be the same :P)
tearDown: Remove the test points inserted before
"""
- a_to_b = self.get_distance_between_points ("haversine", 1, 2)
+ a_to_b = self.get_distance_between_points("haversine", 1, 2)
assert a_to_b == 157225
-
- b_to_a = self.get_distance_between_points ("haversine", 2, 1)
+
+ b_to_a = self.get_distance_between_points("haversine", 2, 1)
assert b_to_a == 157225
assert a_to_b == b_to_a
-
- def test_distance_cartesian_proportion (self):
- d_1_to_2 = self.get_distance_between_points ("cartesian", 1, 2)
- d_2_to_3 = self.get_distance_between_points ("cartesian", 2, 3)
- d_3_to_4 = self.get_distance_between_points ("cartesian", 3, 4)
+ def test_distance_cartesian_proportion(self):
+ d_1_to_2 = self.get_distance_between_points("cartesian", 1, 2)
+ d_2_to_3 = self.get_distance_between_points("cartesian", 2, 3)
+ d_3_to_4 = self.get_distance_between_points("cartesian", 3, 4)
assert d_1_to_2 > d_2_to_3 > d_3_to_4
- def test_distance_haversine_proportion (self):
- d_1_to_2 = self.get_distance_between_points ("haversine", 1, 2)
- d_2_to_3 = self.get_distance_between_points ("haversine", 2, 3)
- d_3_to_4 = self.get_distance_between_points ("haversine", 3, 4)
+ def test_distance_haversine_proportion(self):
+ d_1_to_2 = self.get_distance_between_points("haversine", 1, 2)
+ d_2_to_3 = self.get_distance_between_points("haversine", 2, 3)
+ d_3_to_4 = self.get_distance_between_points("haversine", 3, 4)
assert d_1_to_2 > d_2_to_3 > d_3_to_4
- def test_distance_different (self):
- d_2_to_3h = self.get_distance_between_points ("haversine", 2, 3)
- d_2_to_3c = self.get_distance_between_points ("cartesian", 2, 3)
+ def test_distance_different(self):
+ d_2_to_3h = self.get_distance_between_points("haversine", 2, 3)
+ d_2_to_3c = self.get_distance_between_points("cartesian", 2, 3)
assert d_2_to_3h < d_2_to_3c
-
+
if __name__ == '__main__':
ut.main()
diff --git a/tests/functional-tests/07-graph.py b/tests/functional-tests/07-graph.py
index 1ea6a6a5e..03366fd30 100755
--- a/tests/functional-tests/07-graph.py
+++ b/tests/functional-tests/07-graph.py
@@ -23,13 +23,14 @@ Tests graphs in Sparql. Only requires the store.
import unittest as ut
from common.utils.storetest import CommonTrackerStoreTest as CommonTrackerStoreTest
+
class TestGraphs (CommonTrackerStoreTest):
"""
Insert triplets in different graphs and check the query results asking in
one specific graph, in all of them and so on.
"""
- def test_graph_filter (self):
+ def test_graph_filter(self):
"""
1. Insert a contact with different phone numbers from different sources
2. Query phone numbers of a single graph
@@ -56,7 +57,7 @@ class TestGraphs (CommonTrackerStoreTest):
}
}
"""
- self.tracker.update (insert_sparql)
+ self.tracker.update(insert_sparql)
query = """
SELECT ?contact ?number WHERE {
@@ -66,11 +67,11 @@ class TestGraphs (CommonTrackerStoreTest):
}
} ORDER BY DESC (fts:rank(?contact))
"""
- results = self.tracker.query (query)
+ results = self.tracker.query(query)
- self.assertEqual (len(results), 1)
- self.assertEqual (results[0][0], "contact://test/graph/1")
- self.assertEqual (results[0][1], "tel:+1234567891")
+ self.assertEqual(len(results), 1)
+ self.assertEqual(results[0][0], "contact://test/graph/1")
+ self.assertEqual(results[0][1], "tel:+1234567891")
delete_sparql = """
DELETE {
@@ -81,7 +82,7 @@ class TestGraphs (CommonTrackerStoreTest):
}
"""
- def test_graph_insert_multiple (self):
+ def test_graph_insert_multiple(self):
"""
1. Insert a contact with the same phone number from different sources
2. Query graph uri of hasPhoneNumber statement
@@ -104,7 +105,7 @@ class TestGraphs (CommonTrackerStoreTest):
}
}
"""
- self.tracker.update (insert_sparql)
+ self.tracker.update(insert_sparql)
query = """
SELECT ?contact ?g WHERE {
@@ -114,10 +115,10 @@ class TestGraphs (CommonTrackerStoreTest):
}
}
"""
- results = self.tracker.query (query)
- self.assertEqual (len(results), 1)
- self.assertEqual (results[0][0], "contact://test/graph/1")
- self.assertEqual (results[0][1], "graph://test/graph/0")
+ results = self.tracker.query(query)
+ self.assertEqual(len(results), 1)
+ self.assertEqual(results[0][0], "contact://test/graph/1")
+ self.assertEqual(results[0][1], "graph://test/graph/0")
delete_sparql = """
DELETE {
@@ -127,6 +128,5 @@ class TestGraphs (CommonTrackerStoreTest):
"""
-
if __name__ == '__main__':
ut.main()
diff --git a/tests/functional-tests/08-unique-insertions.py b/tests/functional-tests/08-unique-insertions.py
index a5ea446d9..23650231f 100755
--- a/tests/functional-tests/08-unique-insertions.py
+++ b/tests/functional-tests/08-unique-insertions.py
@@ -23,13 +23,14 @@ Replicate the behaviour of the miner inserting information in the store.
import unittest as ut
from common.utils.storetest import CommonTrackerStoreTest as CommonTrackerStoreTest
+
class TestMinerInsertBehaviour (CommonTrackerStoreTest):
"""
Mimic the behaviour of the miner, removing the previous information of the resource
and inserting a new one.
"""
- def test_miner_unique_insertion (self):
+ def test_miner_unique_insertion(self):
"""
We actually can't test tracker-miner-fs, so we mimick its behavior in this test
1. Insert one resource
@@ -57,22 +58,22 @@ class TestMinerInsertBehaviour (CommonTrackerStoreTest):
"""
''' First insertion '''
- self.tracker.update (insert_sparql)
+ self.tracker.update(insert_sparql)
- results = self.tracker.query (select_sparql)
- self.assertEqual (len(results), 1)
+ results = self.tracker.query(select_sparql)
+ self.assertEqual(len(results), 1)
''' Second insertion / update '''
- self.tracker.update (insert_sparql)
+ self.tracker.update(insert_sparql)
- results = self.tracker.query (select_sparql)
- self.assertEqual (len(results), 1)
+ results = self.tracker.query(select_sparql)
+ self.assertEqual(len(results), 1)
''' Clean up '''
- self.tracker.update (delete_sparql)
+ self.tracker.update(delete_sparql)
- results = self.tracker.query (select_sparql)
- self.assertEqual (len(results), 0)
+ results = self.tracker.query(select_sparql)
+ self.assertEqual(len(results), 0)
if __name__ == '__main__':
diff --git a/tests/functional-tests/09-concurrent-query.py b/tests/functional-tests/09-concurrent-query.py
index 8e4a97292..f362dc98d 100755
--- a/tests/functional-tests/09-concurrent-query.py
+++ b/tests/functional-tests/09-concurrent-query.py
@@ -28,42 +28,44 @@ from common.utils.storetest import CommonTrackerStoreTest as CommonTrackerStoreT
AMOUNT_OF_TEST_INSTANCES = 100
AMOUNT_OF_QUERIES = 10
+
class TestConcurrentQuery (CommonTrackerStoreTest):
"""
Send a bunch of queries to the daemon asynchronously, to test the queue
holding those queries
"""
- def setUp (self):
- self.main_loop = GLib.MainLoop ()
-
- self.mock_data_insert ()
+
+ def setUp(self):
+ self.main_loop = GLib.MainLoop()
+
+ self.mock_data_insert()
self.finish_counter = 0
-
- def mock_data_insert (self):
+
+ def mock_data_insert(self):
query = "INSERT {\n"
- for i in range (0, AMOUNT_OF_TEST_INSTANCES):
- query += "<test-09:instance-%d> a nco:PersonContact ; nco:fullname 'moe %d'.\n" % (i, i)
+ for i in range(0, AMOUNT_OF_TEST_INSTANCES):
+ query += "<test-09:instance-%d> a nco:PersonContact ; nco:fullname 'moe %d'.\n" % (
+ i, i)
query += "}"
- self.tracker.update (query)
-
- def mock_data_delete (self):
+ self.tracker.update(query)
+
+ def mock_data_delete(self):
query = "DELETE {\n"
- for i in range (0, AMOUNT_OF_TEST_INSTANCES):
+ for i in range(0, AMOUNT_OF_TEST_INSTANCES):
query += "<test-09:instance-%d> a rdfs:Resource.\n" % (i)
query += "}"
- self.tracker.update (query)
+ self.tracker.update(query)
query = "DELETE {\n"
- for i in range (0, AMOUNT_OF_QUERIES):
+ for i in range(0, AMOUNT_OF_QUERIES):
query += "<test-09:picture-%d> a rdfs:Resource.\n" % (i)
query += "}"
- self.tracker.update (query)
-
+ self.tracker.update(query)
- def test_async_queries (self):
+ def test_async_queries(self):
QUERY = "SELECT ?u WHERE { ?u a nco:PersonContact. FILTER regex (?u, 'test-09:ins')}"
UPDATE = "INSERT { <test-09:picture-%d> a nmm:Photo. }"
- for i in range (0, AMOUNT_OF_QUERIES):
+ for i in range(0, AMOUNT_OF_QUERIES):
self.tracker.query(
QUERY,
result_handler=self.reply_cb,
@@ -74,26 +76,26 @@ class TestConcurrentQuery (CommonTrackerStoreTest):
error_handler=self.error_handler)
# Safeguard of 60 seconds. The last reply should quit the loop
- GLib.timeout_add_seconds (60, self.timeout_cb)
- self.main_loop.run ()
-
- def reply_cb (self, obj, results, data):
+ GLib.timeout_add_seconds(60, self.timeout_cb)
+ self.main_loop.run()
+
+ def reply_cb(self, obj, results, data):
self.finish_counter += 1
- self.assertEqual (len (results), AMOUNT_OF_TEST_INSTANCES)
+ self.assertEqual(len(results), AMOUNT_OF_TEST_INSTANCES)
if (self.finish_counter >= AMOUNT_OF_QUERIES):
- self.timeout_cb ()
+ self.timeout_cb()
- def update_cb (self, obj, results, data):
- self.assertTrue (True)
+ def update_cb(self, obj, results, data):
+ self.assertTrue(True)
- def error_handler (self, obj, e, user_data):
+ def error_handler(self, obj, e, user_data):
print("ERROR in DBus call: %s" % e)
raise(e)
- def timeout_cb (self):
- self.mock_data_delete ()
- self.main_loop.quit ()
+ def timeout_cb(self):
+ self.mock_data_delete()
+ self.main_loop.quit()
return False
if __name__ == "__main__":
- ut.main ()
+ ut.main()
diff --git a/tests/functional-tests/10-sqlite-misused.py b/tests/functional-tests/10-sqlite-misused.py
index c08751d15..cb0a7cec2 100755
--- a/tests/functional-tests/10-sqlite-misused.py
+++ b/tests/functional-tests/10-sqlite-misused.py
@@ -28,35 +28,37 @@ from common.utils import configuration as cfg
import unittest as ut
from common.utils.storetest import CommonTrackerStoreTest as CommonTrackerStoreTest
+
class TestSqliteMisused (CommonTrackerStoreTest):
"""
Send queries while importing files (in .ttl directory)
"""
- def setUp (self):
- self.main_loop = GLib.MainLoop ()
+
+ def setUp(self):
+ self.main_loop = GLib.MainLoop()
self.files_counter = 0
- def test_queries_while_import (self):
+ def test_queries_while_import(self):
assert os.path.isdir(cfg.generated_ttl_dir())
for root, dirs, files in os.walk(cfg.generated_ttl_dir()):
- for ttl_file in [f for f in files if f.endswith (".ttl")]:
- full_path = os.path.abspath(os.path.join (root, ttl_file))
+ for ttl_file in [f for f in files if f.endswith(".ttl")]:
+ full_path = os.path.abspath(os.path.join(root, ttl_file))
self.files_counter += 1
self.tracker.load(
"file://" + full_path, timeout=30000,
result_handler=self.loaded_success_cb,
error_handler=self.loaded_failed_cb,
- user_data = full_path)
+ user_data=full_path)
- GLib.timeout_add_seconds (2, self.run_a_query)
+ GLib.timeout_add_seconds(2, self.run_a_query)
# Safeguard of 60 seconds. The last reply should quit the loop
# It doesn't matter if we didn't import all of the files yet.
- GLib.timeout_add_seconds (60, self.timeout_cb)
- self.main_loop.run ()
+ GLib.timeout_add_seconds(60, self.timeout_cb)
+ self.main_loop.run()
- def run_a_query (self):
+ def run_a_query(self):
QUERY = "SELECT ?u ?title WHERE { ?u a nie:InformationElement; nie:title ?title. }"
self.tracker.query(
QUERY, timeout=20000,
@@ -64,26 +66,26 @@ class TestSqliteMisused (CommonTrackerStoreTest):
error_handler=self.error_handler)
return True
- def reply_cb (self, obj, results, data):
+ def reply_cb(self, obj, results, data):
print("Query replied correctly")
- def error_handler (self, obj, error, data):
+ def error_handler(self, obj, error, data):
print("ERROR in DBus call: %s" % error)
- def loaded_success_cb (self, obj, results, user_data):
+ def loaded_success_cb(self, obj, results, user_data):
self.files_counter -= 1
if (self.files_counter == 0):
print("Last file loaded")
- self.timeout_cb ()
+ self.timeout_cb()
print("Success loading %s" % user_data)
- def loaded_failed_cb (self, obj, error, user_data):
+ def loaded_failed_cb(self, obj, error, user_data):
raise RuntimeError("Failed loading %s: %s" % (user_data, error))
- def timeout_cb (self):
+ def timeout_cb(self):
print("Forced timeout after 60 sec.")
- self.main_loop.quit ()
+ self.main_loop.quit()
return False
if __name__ == "__main__":
- ut.main ()
+ ut.main()
diff --git a/tests/functional-tests/11-sqlite-batch-misused.py
b/tests/functional-tests/11-sqlite-batch-misused.py
index 4053d584f..fad38ba19 100755
--- a/tests/functional-tests/11-sqlite-batch-misused.py
+++ b/tests/functional-tests/11-sqlite-batch-misused.py
@@ -31,31 +31,33 @@ from common.utils.storetest import CommonTrackerStoreTest as CommonTrackerStoreT
# Number of instances per batch
BATCH_SIZE = 3000
+
class TestSqliteBatchMisused (CommonTrackerStoreTest):
"""
Send big batchSparqlUpdates and run queries at the same time
Don't run this script directly, use the bash script "force-sqlite-misused.sh" instead
to configure properly the environment
"""
- def setUp (self):
- self.main_loop = GLib.MainLoop ()
+
+ def setUp(self):
+ self.main_loop = GLib.MainLoop()
self.batch_counter = 0
- def test_queries_while_batch_insert (self):
- self.assertTrue (os.path.exists (cfg.generated_ttl_dir()))
+ def test_queries_while_batch_insert(self):
+ self.assertTrue(os.path.exists(cfg.generated_ttl_dir()))
for root, dirs, files in os.walk(cfg.generated_ttl_dir()):
- for ttl_file in [f for f in files if f.endswith (".ttl")]:
- full_path = os.path.abspath(os.path.join (root, ttl_file))
+ for ttl_file in [f for f in files if f.endswith(".ttl")]:
+ full_path = os.path.abspath(os.path.join(root, ttl_file))
print(full_path)
counter = 0
current_batch = ""
for line in open(full_path):
- if (line.startswith ("@prefix")):
+ if (line.startswith("@prefix")):
continue
current_batch += line
- if len(line) > 1 and line[:-1].endswith ('.'):
+ if len(line) > 1 and line[:-1].endswith('.'):
counter += 1
if counter >= BATCH_SIZE:
@@ -65,17 +67,17 @@ class TestSqliteBatchMisused (CommonTrackerStoreTest):
timeout=20000,
result_handler=self.batch_success_cb,
error_handler=self.batch_failed_cb)
- self.run_a_query ()
+ self.run_a_query()
counter = 0
current_batch = ""
self.batch_counter += 1
- GLib.timeout_add_seconds (2, self.run_a_query)
+ GLib.timeout_add_seconds(2, self.run_a_query)
# Safeguard of 60 seconds. The last reply should quit the loop
- GLib.timeout_add_seconds (60, self.timeout_cb)
- self.main_loop.run ()
+ GLib.timeout_add_seconds(60, self.timeout_cb)
+ self.main_loop.run()
- def run_a_query (self):
+ def run_a_query(self):
QUERY = "SELECT ?u ?title WHERE { ?u a nie:InformationElement; nie:title ?title. }"
self.tracker.query(
QUERY, timeout=20000,
@@ -83,28 +85,28 @@ class TestSqliteBatchMisused (CommonTrackerStoreTest):
error_handler=self.error_handler)
return True
- def reply_cb (self, obj, results, data):
+ def reply_cb(self, obj, results, data):
print("Query replied correctly")
- def error_handler (self, error_msg):
+ def error_handler(self, error_msg):
print("Query failed", error_msg)
raise error_msg
- def batch_success_cb (self, obj, result, user_data):
+ def batch_success_cb(self, obj, result, user_data):
self.batch_counter -= 1
if (self.batch_counter == 0):
print("Last batch was success")
- self.timeout_cb ()
+ self.timeout_cb()
print("Success processing a batch")
- def batch_failed_cb (self, obj, error, user_data):
+ def batch_failed_cb(self, obj, error, user_data):
print("Failed processing a batch: %s" % error)
raise error
- def timeout_cb (self):
+ def timeout_cb(self):
print("Forced timeout after 60 sec.")
- self.main_loop.quit ()
+ self.main_loop.quit()
return False
if __name__ == "__main__":
- ut.main ()
+ ut.main()
diff --git a/tests/functional-tests/12-transactions.py b/tests/functional-tests/12-transactions.py
index 3264da7d2..5f6d870d3 100755
--- a/tests/functional-tests/12-transactions.py
+++ b/tests/functional-tests/12-transactions.py
@@ -27,6 +27,7 @@ from common.utils.storetest import CommonTrackerStoreTest as CommonTrackerStoreT
TEST_INSTANCE_PATTERN = "test://12-transactions-%d"
+
class TrackerTransactionsTest (CommonTrackerStoreTest):
"""
In a loop:
@@ -38,49 +39,49 @@ class TrackerTransactionsTest (CommonTrackerStoreTest):
If the commit was real, all the inserted instances should be there.
"""
- def setUp (self):
+ def setUp(self):
self.instance_counter = 0
- def tearDown (self):
+ def tearDown(self):
print("Tear down (will take some time to remove all resources)")
delete_sparql = "DELETE { ?u a rdfs:Resource } WHERE { ?u a nmo:Email} \n"
- self.tracker.update (delete_sparql,
- timeout=60000)
+ self.tracker.update(delete_sparql,
+ timeout=60000)
self.instance_counter = 0
- def insert_and_commit (self, number):
+ def insert_and_commit(self, number):
insert_sparql = "INSERT {\n"
- for i in range (0, number):
- insert_sparql += " <" + TEST_INSTANCE_PATTERN % (self.instance_counter) + ">"
+ for i in range(0, number):
+ insert_sparql += " <" + \
+ TEST_INSTANCE_PATTERN % (self.instance_counter) + ">"
insert_sparql += " a nmo:Email.\n "
self.instance_counter += 1
insert_sparql += "}"
- self.tracker.batch_update (insert_sparql)
- #print "Waiting for commit (", number," instances)"
+ self.tracker.batch_update(insert_sparql)
+ # print "Waiting for commit (", number," instances)"
#start = time.time ()
- self.tracker.batch_commit ()
+ self.tracker.batch_commit()
#end = time.time ()
- #print "BatchCommit returned (after %d s.)" % (end - start)
-
+ # print "BatchCommit returned (after %d s.)" % (end - start)
- def test_commit_and_abort (self):
+ def test_commit_and_abort(self):
- for i in range (0, 20):
+ for i in range(0, 20):
NUMBER_OF_INSTANCES = 1000
- self.insert_and_commit (NUMBER_OF_INSTANCES)
+ self.insert_and_commit(NUMBER_OF_INSTANCES)
self.tracker.kill()
self.tracker.start()
try:
- results = self.tracker.count_instances ("nmo:Email")
+ results = self.tracker.count_instances("nmo:Email")
except:
print("Timeout, probably replaying journal or something (wait 20 sec.)")
- time.sleep (20)
- results = self.tracker.count_instances ()
+ time.sleep(20)
+ results = self.tracker.count_instances()
# Every iteration we are adding new instances in the store!
- self.assertEqual (results, NUMBER_OF_INSTANCES * (i+1))
+ self.assertEqual(results, NUMBER_OF_INSTANCES * (i + 1))
if __name__ == "__main__":
- ut.main ()
+ ut.main()
diff --git a/tests/functional-tests/13-threaded-store.py b/tests/functional-tests/13-threaded-store.py
index 0cd8f427b..d3fb88023 100755
--- a/tests/functional-tests/13-threaded-store.py
+++ b/tests/functional-tests/13-threaded-store.py
@@ -29,11 +29,14 @@ from common.utils import configuration as cfg
import unittest as ut
from common.utils.storetest import CommonTrackerStoreTest as CommonTrackerStoreTest
-MAX_TEST_TIME = 60 # seconds to finish the tests (to avoid infinite waitings)
+MAX_TEST_TIME = 60 # seconds to finish the tests (to avoid infinite waitings)
+
+AMOUNT_SIMPLE_QUERIES = 10
+# ms (How long do we wait for an answer to the complex query)
+COMPLEX_QUERY_TIMEOUT = 15000
+# seconds (How freq do we send a simple query to the daemon)
+SIMPLE_QUERY_FREQ = 2
-AMOUNT_SIMPLE_QUERIES = 10
-COMPLEX_QUERY_TIMEOUT = 15000 # ms (How long do we wait for an answer to the complex query)
-SIMPLE_QUERY_FREQ = 2 # seconds (How freq do we send a simple query to the daemon)
class TestThreadedStore (CommonTrackerStoreTest):
"""
@@ -42,14 +45,15 @@ class TestThreadedStore (CommonTrackerStoreTest):
Reported in bug NB#183499
"""
- def setUp (self):
- self.main_loop = GLib.MainLoop ()
+
+ def setUp(self):
+ self.main_loop = GLib.MainLoop()
self.simple_queries_counter = AMOUNT_SIMPLE_QUERIES
self.simple_queries_answers = 0
- def __populate_database (self):
+ def __populate_database(self):
- self.assertTrue (os.path.exists (cfg.generated_ttl_dir()))
+ self.assertTrue(os.path.exists(cfg.generated_ttl_dir()))
for ttl_file in ["010-nco_EmailAddress.ttl",
"011-nco_PostalAddress.ttl",
"012-nco_PhoneNumber.ttl",
@@ -58,17 +62,18 @@ class TestThreadedStore (CommonTrackerStoreTest):
"018-nco_PersonContact.ttl",
"012-nco_PhoneNumber.ttl",
"016-nco_ContactIM.ttl"]:
- full_path = os.path.abspath(os.path.join (cfg.generated_ttl_dir(), ttl_file))
+ full_path = os.path.abspath(os.path.join(
+ cfg.generated_ttl_dir(), ttl_file))
print(full_path)
self.tracker.get_tracker_iface().Load(
'(s)', "file://" + full_path, timeout=30000)
@ut.skip("Test fails with 'GDBus.Error:org.freedesktop.Tracker1.SparqlError.Internal: parser stack
overflow (36)'")
- def test_complex_query (self):
- start = time.time ()
- self.__populate_database ()
- end = time.time ()
- print("Loading: %.3f sec." % (end-start))
+ def test_complex_query(self):
+ start = time.time()
+ self.__populate_database()
+ end = time.time()
+ print("Loading: %.3f sec." % (end - start))
COMPLEX_QUERY = """
SELECT ?url nie:url(?photo) nco:imStatusMessage (?url)
@@ -94,17 +99,18 @@ class TestThreadedStore (CommonTrackerStoreTest):
# Standard timeout
print("Send complex query")
- self.complex_start = time.time ()
+ self.complex_start = time.time()
self.tracker.query(
COMPLEX_QUERY, timeout=COMPLEX_QUERY_TIMEOUT,
response_handler=self.reply_complex,
error_handler=self.error_handler_complex)
- self.timeout_id = GLib.timeout_add_seconds (MAX_TEST_TIME, self.__timeout_on_idle)
- GLib.timeout_add_seconds (SIMPLE_QUERY_FREQ, self.__simple_query)
- self.main_loop.run ()
+ self.timeout_id = GLib.timeout_add_seconds(
+ MAX_TEST_TIME, self.__timeout_on_idle)
+ GLib.timeout_add_seconds(SIMPLE_QUERY_FREQ, self.__simple_query)
+ self.main_loop.run()
- def __simple_query (self):
+ def __simple_query(self):
print("Send simple query (%d)" % (self.simple_queries_counter))
SIMPLE_QUERY = "SELECT ?name WHERE { ?u a nco:PersonContact; nco:fullname ?name. }"
self.tracker.query(
@@ -118,28 +124,28 @@ class TestThreadedStore (CommonTrackerStoreTest):
return False
return True
- def reply_simple (self, obj, results, data):
+ def reply_simple(self, obj, results, data):
print("Simple query answered")
- self.assertNotEqual (len (results), 0)
+ self.assertNotEqual(len(results), 0)
self.simple_queries_answers += 1
if (self.simple_queries_answers == AMOUNT_SIMPLE_QUERIES):
print("All simple queries answered")
- self.main_loop.quit ()
+ self.main_loop.quit()
- def reply_complex (self, obj, results, data):
- print("Complex query: %.3f" % (time.time () - self.complex_start))
+ def reply_complex(self, obj, results, data):
+ print("Complex query: %.3f" % (time.time() - self.complex_start))
- def error_handler (self, error_msg):
+ def error_handler(self, error_msg):
print("ERROR in dbus call", error_msg)
- def error_handler_complex (self, error_msg):
+ def error_handler_complex(self, error_msg):
print("Complex query timedout in DBus (", error_msg, ")")
- def __timeout_on_idle (self):
+ def __timeout_on_idle(self):
print("Timeout... asumming idle")
- self.main_loop.quit ()
+ self.main_loop.quit()
return False
-
+
if __name__ == "__main__":
- ut.main ()
+ ut.main()
diff --git a/tests/functional-tests/14-signals.py b/tests/functional-tests/14-signals.py
index 0924a04b1..44806e8a2 100755
--- a/tests/functional-tests/14-signals.py
+++ b/tests/functional-tests/14-signals.py
@@ -38,14 +38,16 @@ SIGNALS_IFACE = "org.freedesktop.Tracker1.Resources"
CONTACT_CLASS_URI = "http://www.semanticdesktop.org/ontologies/2007/03/22/nco#PersonContact"
-REASONABLE_TIMEOUT = 10 # Time waiting for the signal to be emitted
+REASONABLE_TIMEOUT = 10 # Time waiting for the signal to be emitted
+
class TrackerStoreSignalsTests (CommonTrackerStoreTest):
"""
Insert/update/remove instances from nco:PersonContact
and check that the signals are emitted
"""
- def setUp (self):
+
+ def setUp(self):
self.clean_up_list = []
self.loop = GLib.MainLoop()
@@ -57,14 +59,13 @@ class TrackerStoreSignalsTests (CommonTrackerStoreTest):
self.results_deletes = None
self.results_inserts = None
- def tearDown (self):
+ def tearDown(self):
for uri in self.clean_up_list:
- self.tracker.update ("DELETE { <%s> a rdfs:Resource }" % uri)
+ self.tracker.update("DELETE { <%s> a rdfs:Resource }" % uri)
self.clean_up_list = []
-
- def __connect_signal (self):
+ def __connect_signal(self):
"""
After connecting to the signal, call self.__wait_for_signal.
"""
@@ -77,23 +78,25 @@ class TrackerStoreSignalsTests (CommonTrackerStoreTest):
flags=Gio.DBusSignalFlags.NONE,
callback=self.__signal_received_cb)
- def __wait_for_signal (self):
+ def __wait_for_signal(self):
"""
In the callback of the signals, there should be a self.loop.quit ()
"""
- self.timeout_id = GLib.timeout_add_seconds (REASONABLE_TIMEOUT, self.__timeout_on_idle)
- self.loop.run ()
+ self.timeout_id = GLib.timeout_add_seconds(
+ REASONABLE_TIMEOUT, self.__timeout_on_idle)
+ self.loop.run()
- def __timeout_on_idle (self):
- self.loop.quit ()
- self.fail ("Timeout, the signal never came!")
+ def __timeout_on_idle(self):
+ self.loop.quit()
+ self.fail("Timeout, the signal never came!")
- def __pretty_print_array (self, array):
+ def __pretty_print_array(self, array):
for g, s, o, p in array:
- uri, prop, value = self.tracker.query ("SELECT tracker:uri (%s), tracker:uri (%s), tracker:uri
(%s) WHERE {}" % (s, o, p))
- print(" - (", "-".join ([g, uri, prop, value]), ")")
-
- def __signal_received_cb (self, connection, sender_name, object_path, interface_name, signal_name,
parameters):
+ uri, prop, value = self.tracker.query(
+ "SELECT tracker:uri (%s), tracker:uri (%s), tracker:uri (%s) WHERE {}" % (s, o, p))
+ print(" - (", "-".join([g, uri, prop, value]), ")")
+
+ def __signal_received_cb(self, connection, sender_name, object_path, interface_name, signal_name,
parameters):
"""
Save the content of the signal and disconnect the callback
"""
@@ -104,14 +107,13 @@ class TrackerStoreSignalsTests (CommonTrackerStoreTest):
self.results_inserts = inserts
if (self.timeout_id != 0):
- GLib.source_remove (self.timeout_id )
+ GLib.source_remove(self.timeout_id)
self.timeout_id = 0
- self.loop.quit ()
+ self.loop.quit()
self.bus.signal_unsubscribe(self.cb_id)
-
- def test_01_insert_contact (self):
- self.clean_up_list.append ("test://signals-contact-add")
+ def test_01_insert_contact(self):
+ self.clean_up_list.append("test://signals-contact-add")
CONTACT = """
INSERT {
<test://signals-contact-add> a nco:PersonContact ;
@@ -122,16 +124,16 @@ class TrackerStoreSignalsTests (CommonTrackerStoreTest):
nco:hasPhoneNumber <tel:555555555> .
}
"""
- self.__connect_signal ()
- self.tracker.update (CONTACT)
- time.sleep (1)
- self.__wait_for_signal ()
+ self.__connect_signal()
+ self.tracker.update(CONTACT)
+ time.sleep(1)
+ self.__wait_for_signal()
# validate results
- self.assertEqual (len (self.results_deletes), 0)
- self.assertEqual (len (self.results_inserts), 6)
-
- def test_02_remove_contact (self):
+ self.assertEqual(len(self.results_deletes), 0)
+ self.assertEqual(len(self.results_inserts), 6)
+
+ def test_02_remove_contact(self):
CONTACT = """
INSERT {
<test://signals-contact-remove> a nco:PersonContact ;
@@ -139,56 +141,56 @@ class TrackerStoreSignalsTests (CommonTrackerStoreTest):
nco:nameFamily 'Contact-family removed'.
}
"""
- self.__connect_signal ()
- self.tracker.update (CONTACT)
- self.__wait_for_signal ()
-
- self.__connect_signal ()
+ self.__connect_signal()
+ self.tracker.update(CONTACT)
+ self.__wait_for_signal()
+
+ self.__connect_signal()
self.tracker.update ("""
DELETE { <test://signals-contact-remove> a rdfs:Resource }
""")
- self.__wait_for_signal ()
+ self.__wait_for_signal()
# Validate results:
- self.assertEqual (len (self.results_deletes), 1)
- self.assertEqual (len (self.results_inserts), 0)
+ self.assertEqual(len(self.results_deletes), 1)
+ self.assertEqual(len(self.results_inserts), 0)
+
+ def test_03_update_contact(self):
+ self.clean_up_list.append("test://signals-contact-update")
+ self.__connect_signal()
+ self.tracker.update(
+ "INSERT { <test://signals-contact-update> a nco:PersonContact }")
+ self.__wait_for_signal()
- def test_03_update_contact (self):
- self.clean_up_list.append ("test://signals-contact-update")
+ self.__connect_signal()
+ self.tracker.update(
+ "INSERT { <test://signals-contact-update> nco:fullname 'wohoo'}")
+ self.__wait_for_signal()
- self.__connect_signal ()
- self.tracker.update ("INSERT { <test://signals-contact-update> a nco:PersonContact }")
- self.__wait_for_signal ()
-
- self.__connect_signal ()
- self.tracker.update ("INSERT { <test://signals-contact-update> nco:fullname 'wohoo'}")
- self.__wait_for_signal ()
+ self.assertEqual(len(self.results_deletes), 0)
+ self.assertEqual(len(self.results_inserts), 1)
- self.assertEqual (len (self.results_deletes), 0)
- self.assertEqual (len (self.results_inserts), 1)
+ def test_04_fullupdate_contact(self):
+ self.clean_up_list.append("test://signals-contact-fullupdate")
+ self.__connect_signal()
+ self.tracker.update(
+ "INSERT { <test://signals-contact-fullupdate> a nco:PersonContact; nco:fullname 'first value' }")
+ self.__wait_for_signal()
- def test_04_fullupdate_contact (self):
- self.clean_up_list.append ("test://signals-contact-fullupdate")
-
- self.__connect_signal ()
- self.tracker.update ("INSERT { <test://signals-contact-fullupdate> a nco:PersonContact; nco:fullname
'first value' }")
- self.__wait_for_signal ()
-
- self.__connect_signal ()
+ self.__connect_signal()
self.tracker.update ("""
DELETE { <test://signals-contact-fullupdate> nco:fullname ?x }
WHERE { <test://signals-contact-fullupdate> a nco:PersonContact; nco:fullname ?x }
INSERT { <test://signals-contact-fullupdate> nco:fullname 'second value'}
""")
- self.__wait_for_signal ()
+ self.__wait_for_signal()
+
+ self.assertEqual(len(self.results_deletes), 1)
+ self.assertEqual(len(self.results_inserts), 1)
- self.assertEqual (len (self.results_deletes), 1)
- self.assertEqual (len (self.results_inserts), 1)
-
if __name__ == "__main__":
ut.main()
-
diff --git a/tests/functional-tests/15-statistics.py b/tests/functional-tests/15-statistics.py
index 6fbc8210e..ac6a2f210 100755
--- a/tests/functional-tests/15-statistics.py
+++ b/tests/functional-tests/15-statistics.py
@@ -31,96 +31,97 @@ RDFS_RESOURCE = "rdfs:Resource"
NIE_IE = "nie:InformationElement"
RDFS_CLASS = "rdfs:Class"
+
class TrackerStoreStatisticsTests (CommonTrackerStoreTest):
"""
Check initial statistics, add, remove, update content and check results stats
"""
- def __get_stats (self):
+
+ def __get_stats(self):
results = {}
- for classname, count in self.tracker.get_stats ():
- results [str(classname)] = int(count)
+ for classname, count in self.tracker.get_stats():
+ results[str(classname)] = int(count)
return results
- def setUp (self):
+ def setUp(self):
"""
Each test append to this list the used URIS, so they can be removed
in the tearDown
"""
self.clean_up_instances = []
- def tearDown (self):
+ def tearDown(self):
for uri in self.clean_up_instances:
- self.tracker.update ("DELETE { <%s> a rdfs:Resource. }" % (uri))
+ self.tracker.update("DELETE { <%s> a rdfs:Resource. }" % (uri))
self.clean_up_instances = []
- time.sleep (1)
-
- def test_stats_01_insert_base_class (self):
- self.clean_up_instances.append ("test://stats-01")
-
- old_stats = self.__get_stats ()
- self.tracker.update ("INSERT { <test://stats-01> a nie:InformationElement. }")
- new_stats = self.__get_stats ()
+ time.sleep(1)
+
+ def test_stats_01_insert_base_class(self):
+ self.clean_up_instances.append("test://stats-01")
+
+ old_stats = self.__get_stats()
+ self.tracker.update(
+ "INSERT { <test://stats-01> a nie:InformationElement. }")
+ new_stats = self.__get_stats()
increased_classes = [NIE_IE, RDFS_RESOURCE]
- for k, v in new_stats.items ():
+ for k, v in new_stats.items():
if k in increased_classes:
- self.assertEqual (old_stats[k]+1, new_stats[k])
+ self.assertEqual(old_stats[k] + 1, new_stats[k])
else:
- self.assertEqual (old_stats [k], new_stats [k],
- "Class %s should have the same instances" % k)
+ self.assertEqual(old_stats[k], new_stats[k],
+ "Class %s should have the same instances" % k)
+ def test_stats_02_insert_deep_class(self):
+ self.clean_up_instances.append("test://stats-02")
+ old_stats = self.__get_stats()
+ self.tracker.update("INSERT { <test://stats-02> a nmm:Photo. }")
+ new_stats = self.__get_stats()
- def test_stats_02_insert_deep_class (self):
- self.clean_up_instances.append ("test://stats-02")
- old_stats = self.__get_stats ()
- self.tracker.update ("INSERT { <test://stats-02> a nmm:Photo. }")
- new_stats = self.__get_stats ()
-
- increased_classes = [ NIE_IE, RDFS_RESOURCE]
+ increased_classes = [NIE_IE, RDFS_RESOURCE]
new_classes = ["nmm:Photo", "nfo:Visual", "nfo:Image", "nfo:Media"]
# There were no instances of those classes before, check they are now
for c in new_classes:
- self.assertIn (c, new_stats)
-
- for k, v in new_stats.items ():
+ self.assertIn(c, new_stats)
+
+ for k, v in new_stats.items():
if k in increased_classes:
- self.assertEqual (old_stats [k]+1, new_stats[k])
+ self.assertEqual(old_stats[k] + 1, new_stats[k])
elif k in new_classes:
# This classes could exists previous or not!
if k in old_stats:
- self.assertEqual (old_stats [k]+1, new_stats [k])
+ self.assertEqual(old_stats[k] + 1, new_stats[k])
else:
- self.assertEqual (new_stats [k], 1)
+ self.assertEqual(new_stats[k], 1)
else:
- self.assertEqual (old_stats [k], new_stats[k])
+ self.assertEqual(old_stats[k], new_stats[k])
- def test_stats_03_delete_deep_class (self):
- self.clean_up_instances.append ("test://stats-03")
- self.tracker.update ("INSERT { <test://stats-03> a nmm:Photo. }")
+ def test_stats_03_delete_deep_class(self):
+ self.clean_up_instances.append("test://stats-03")
+ self.tracker.update("INSERT { <test://stats-03> a nmm:Photo. }")
- old_stats = self.__get_stats ()
- self.tracker.update ("DELETE { <test://stats-03> a rdfs:Resource. }")
- new_stats = self.__get_stats ()
+ old_stats = self.__get_stats()
+ self.tracker.update("DELETE { <test://stats-03> a rdfs:Resource. }")
+ new_stats = self.__get_stats()
decreased_classes = [NIE_IE, RDFS_RESOURCE]
# These classes could have no instance
- no_instances_classes = ["nmm:Photo", "nfo:Visual", "nfo:Image", "nfo:Media"]
+ no_instances_classes = ["nmm:Photo",
+ "nfo:Visual", "nfo:Image", "nfo:Media"]
for c in no_instances_classes:
if (old_stats[c] == 1):
- self.assertNotIn (c, new_stats)
+ self.assertNotIn(c, new_stats)
else:
- self.assertEqual (old_stats[c]-1, new_stats[c])
+ self.assertEqual(old_stats[c] - 1, new_stats[c])
- for k, v in new_stats.items ():
+ for k, v in new_stats.items():
if k in decreased_classes:
- self.assertEqual (old_stats [k]-1, new_stats[k])
+ self.assertEqual(old_stats[k] - 1, new_stats[k])
else:
- self.assertEqual (old_stats [k], new_stats [k])
+ self.assertEqual(old_stats[k], new_stats[k])
if __name__ == "__main__":
- ut.main ()
-
-
+ ut.main()
diff --git a/tests/functional-tests/16-collation.py b/tests/functional-tests/16-collation.py
index 76e22f236..36a1fbbc7 100755
--- a/tests/functional-tests/16-collation.py
+++ b/tests/functional-tests/16-collation.py
@@ -29,31 +29,33 @@ import locale
import unittest as ut
from common.utils.storetest import CommonTrackerStoreTest as CommonTrackerStoreTest
+
class TrackerStoreCollationTests (CommonTrackerStoreTest):
"""
Insert few instances with a text field containing collation-problematic words.
Ask for those instances order by the field and check the results.
"""
- def setUp (self):
+
+ def setUp(self):
"""
Each test append to this list the used URIS, so they can be removed
in the tearDown
"""
self.clean_up_instances = []
- def tearDown (self):
+ def tearDown(self):
for uri in self.clean_up_instances:
- self.tracker.update ("DELETE { <%s> a rdfs:Resource. }" % (uri))
+ self.tracker.update("DELETE { <%s> a rdfs:Resource. }" % (uri))
self.clean_up_instances = []
- time.sleep (1)
+ time.sleep(1)
- def __insert_text (self, text):
- uri = "test://collation-01-%d" % (random.randint (1, 1000))
+ def __insert_text(self, text):
+ uri = "test://collation-01-%d" % (random.randint(1, 1000))
# There is a remote chance to get a duplicate int
while (uri in self.clean_up_instances):
- uri = "test://collation-01-%d" % (random.randint (1, 1000))
- self.clean_up_instances.append (uri)
-
+ uri = "test://collation-01-%d" % (random.randint(1, 1000))
+ self.clean_up_instances.append(uri)
+
self.tracker.update ("""
INSERT {
<%s> a nie:InformationElement ;
@@ -62,7 +64,7 @@ class TrackerStoreCollationTests (CommonTrackerStoreTest):
}
""" % (uri, text))
- def get_text_sorted_by_collation (self):
+ def get_text_sorted_by_collation(self):
return self.tracker.query ("""
SELECT ?title WHERE {
?u a nie:InformationElement ;
@@ -71,57 +73,57 @@ class TrackerStoreCollationTests (CommonTrackerStoreTest):
} ORDER BY ?title
""")
- def __collation_test (self, input_list, expected_list):
+ def __collation_test(self, input_list, expected_list):
for i in input_list:
- self.__insert_text (i)
+ self.__insert_text(i)
- results = [r[0] for r in self.get_text_sorted_by_collation ()]
- self.assertEqual (len (results), len (expected_list))
+ results = [r[0] for r in self.get_text_sorted_by_collation()]
+ self.assertEqual(len(results), len(expected_list))
- for r in range (0, len (results)):
- self.assertEqual (results[r], expected_list [r],
- """Error:
+ for r in range(0, len(results)):
+ self.assertEqual(results[r], expected_list[r],
+ """Error:
Expected : *** %s
Result : *** %s
Using locale (%s, %s)
""" % (expected_list,
results,
- locale.getdefaultlocale ()[0],
- locale.getdefaultlocale ()[1]))
+ locale.getdefaultlocale()[0],
+ locale.getdefaultlocale()[1]))
- def test_collation_01 (self):
+ def test_collation_01(self):
"""
Behaves as case-insensitive
"""
input_dt = ["abb", "bb", "Abc", "Ba"]
expected = ["abb", "Abc", "Ba", "bb"]
- self.__collation_test (input_dt, expected)
+ self.__collation_test(input_dt, expected)
- def test_collation_02 (self):
+ def test_collation_02(self):
"""
In conflict, Capital letters go *after* small letters
"""
input_dt = ["Bb", "bb", "aa", "Aa"]
expected = ["aa", "Aa", "bb", "Bb"]
- self.__collation_test (input_dt, expected)
+ self.__collation_test(input_dt, expected)
- def test_collation_03 (self):
+ def test_collation_03(self):
"""
Example from the unicode spec
http://www.unicode.org/reports/tr10/#Main_Algorithm
"""
input_dt = ["Cab", "cab", "dab", "cáb"]
expected = ["cab", "Cab", "cáb", "dab"]
- self.__collation_test (input_dt, expected)
+ self.__collation_test(input_dt, expected)
- def test_collation_04 (self):
+ def test_collation_04(self):
"""
Spanish test in english locale
"""
input_dt = ["ä", "ö", "a", "e", "i", "o", "u"]
expected = ["a", "ä", "e", "i", "o", "ö", "u"]
- self.__collation_test (input_dt, expected)
+ self.__collation_test(input_dt, expected)
if __name__ == "__main__":
print("""
@@ -129,6 +131,4 @@ if __name__ == "__main__":
* Check what happens in non-english encoding
* Dynamic change of collation (not implemented yet in tracker)
""")
- ut.main ()
-
-
+ ut.main()
diff --git a/tests/functional-tests/17-ontology-changes.py b/tests/functional-tests/17-ontology-changes.py
index 3c5ff29c6..687757fe1 100755
--- a/tests/functional-tests/17-ontology-changes.py
+++ b/tests/functional-tests/17-ontology-changes.py
@@ -38,7 +38,6 @@ from common.utils.expectedFailure import expectedFailureJournal
import unittest as ut
-
RDFS_RANGE = "http://www.w3.org/2000/01/rdf-schema#range"
XSD_DATETIME = "http://www.w3.org/2001/XMLSchema#dateTime"
XSD_STRING = "http://www.w3.org/2001/XMLSchema#string"
@@ -46,7 +45,7 @@ XSD_INTEGER = "http://www.w3.org/2001/XMLSchema#integer"
TEST_PREFIX = "http://example.org/ns#"
-TEST_ENV_VARS = { "LC_COLLATE": "en_GB.utf8" }
+TEST_ENV_VARS = {"LC_COLLATE": "en_GB.utf8"}
REASONABLE_TIMEOUT = 5
@@ -56,6 +55,7 @@ class UnableToBootException (Exception):
class TrackerSystemAbstraction (object):
+
def __init__(self, settings=None):
self.store = None
self._dirs = {}
@@ -66,7 +66,7 @@ class TrackerSystemAbstraction (object):
def xdg_cache_home(self):
return os.path.join(self._basedir, 'cache')
- def set_up_environment (self, settings=None, ontodir=None):
+ def set_up_environment(self, settings=None, ontodir=None):
"""
Sets up the XDG_*_HOME variables and make sure the directories exist
@@ -78,22 +78,23 @@ class TrackerSystemAbstraction (object):
self._basedir = tempfile.mkdtemp()
self._dirs = {
- "XDG_DATA_HOME" : self.xdg_data_home(),
+ "XDG_DATA_HOME": self.xdg_data_home(),
"XDG_CACHE_HOME": self.xdg_cache_home()
}
for var, directory in list(self._dirs.items()):
- os.makedirs (directory)
- os.makedirs (os.path.join(directory, 'tracker'))
- os.environ [var] = directory
+ os.makedirs(directory)
+ os.makedirs(os.path.join(directory, 'tracker'))
+ os.environ[var] = directory
if ontodir:
- helpers.log ("export %s=%s" % ("TRACKER_DB_ONTOLOGIES_DIR", ontodir))
- os.environ ["TRACKER_DB_ONTOLOGIES_DIR"] = ontodir
+ helpers.log("export %s=%s" %
+ ("TRACKER_DB_ONTOLOGIES_DIR", ontodir))
+ os.environ["TRACKER_DB_ONTOLOGIES_DIR"] = ontodir
- for var, value in TEST_ENV_VARS.items ():
- helpers.log ("export %s=%s" %(var, value))
- os.environ [var] = value
+ for var, value in TEST_ENV_VARS.items():
+ helpers.log("export %s=%s" % (var, value))
+ os.environ[var] = value
# Previous loop should have set DCONF_PROFILE to the test location
if settings is not None:
@@ -106,32 +107,33 @@ class TrackerSystemAbstraction (object):
for key, value in contents.items():
dconf.write(key, value)
- def tracker_store_testing_start (self, confdir=None, ontodir=None):
+ def tracker_store_testing_start(self, confdir=None, ontodir=None):
"""
Stops any previous instance of the store, calls set_up_environment,
and starts a new instances of the store
"""
- self.set_up_environment (confdir, ontodir)
+ self.set_up_environment(confdir, ontodir)
- self.store = helpers.StoreHelper ()
- self.store.start ()
+ self.store = helpers.StoreHelper()
+ self.store.start()
- def tracker_store_restart_with_new_ontologies (self, ontodir):
- self.store.stop ()
+ def tracker_store_restart_with_new_ontologies(self, ontodir):
+ self.store.stop()
if ontodir:
- os.environ ["TRACKER_DB_ONTOLOGIES_DIR"] = ontodir
+ os.environ["TRACKER_DB_ONTOLOGIES_DIR"] = ontodir
try:
- self.store.start ()
+ self.store.start()
except GLib.Error:
- raise UnableToBootException ("Unable to boot the store \n(" + str(e) + ")")
+ raise UnableToBootException(
+ "Unable to boot the store \n(" + str(e) + ")")
- def finish (self):
+ def finish(self):
"""
Stop all running processes and remove all test data.
"""
if self.store:
- self.store.stop ()
+ self.store.stop()
for path in list(self._dirs.values()):
shutil.rmtree(path)
@@ -142,73 +144,71 @@ class OntologyChangeTestTemplate (ut.TestCase):
"""
Template class for the ontology changes tests. The tests are subclasses
of this, implementing these methods:
-
+
* set_ontology_dirs
* insert_data
* validate_status
-
+
and adding a method 'test_x_y_z' to be invoked by unittest.
-
+
Check doc in those methods for the specific details.
"""
-
- def get_ontology_dir (self, param):
+
+ def get_ontology_dir(self, param):
return os.path.join(cfg.TEST_ONTOLOGIES_DIR, param)
- def setUp (self):
- self.system = TrackerSystemAbstraction ()
+ def setUp(self):
+ self.system = TrackerSystemAbstraction()
- def tearDown (self):
+ def tearDown(self):
self.system.finish()
- def template_test_ontology_change (self):
-
- self.set_ontology_dirs ()
+ def template_test_ontology_change(self):
-
- basic_ontologies = self.get_ontology_dir (self.FIRST_ONTOLOGY_DIR)
- modified_ontologies = self.get_ontology_dir (self.SECOND_ONTOLOGY_DIR)
+ self.set_ontology_dirs()
- self.__assert_ontology_dates (basic_ontologies, modified_ontologies)
+ basic_ontologies = self.get_ontology_dir(self.FIRST_ONTOLOGY_DIR)
+ modified_ontologies = self.get_ontology_dir(self.SECOND_ONTOLOGY_DIR)
+ self.__assert_ontology_dates(basic_ontologies, modified_ontologies)
- self.system.tracker_store_testing_start (ontodir=basic_ontologies)
+ self.system.tracker_store_testing_start(ontodir=basic_ontologies)
self.tracker = self.system.store
- self.insert_data ()
+ self.insert_data()
try:
# Boot the second set of ontologies
- self.system.tracker_store_restart_with_new_ontologies (modified_ontologies)
+ self.system.tracker_store_restart_with_new_ontologies(
+ modified_ontologies)
except UnableToBootException as e:
- self.fail (str(self.__class__) + " " + str(e))
+ self.fail(str(self.__class__) + " " + str(e))
- self.validate_status ()
+ self.validate_status()
- def set_ontology_dirs (self):
+ def set_ontology_dirs(self):
"""
Implement this method in the subclass setting values for:
self.FIRST_ONTOLOGY_DIR and
self.SECOND_ONTOLOGY_DIR
"""
- raise Exception ("Subclasses must implement 'set_ontology_dir'")
+ raise Exception("Subclasses must implement 'set_ontology_dir'")
- def insert_data (self):
+ def insert_data(self):
"""
Put in the store some data with the FIRST ontology
"""
- raise Exception ("Subclasses must implement 'insert_data'")
+ raise Exception("Subclasses must implement 'insert_data'")
- def validate_status (self):
+ def validate_status(self):
"""
This is called after restarting the store with the SECOND ontology
Check that the inserted data was handled correctly and the ontology
is up to date
"""
- raise Exception ("Subclasses must implement 'validate_status'")
+ raise Exception("Subclasses must implement 'validate_status'")
-
- def assertInDbusResult (self, member, dbus_result, column=0):
+ def assertInDbusResult(self, member, dbus_result, column=0):
"""
Convenience assertion used in these tests
"""
@@ -216,42 +216,47 @@ class OntologyChangeTestTemplate (ut.TestCase):
if member == row[column]:
return
# This is going to fail with pretty printing
- self.assertIn (member, dbus_result)
+ self.assertIn(member, dbus_result)
- def assertNotInDbusResult (self, member, dbus_result, column=0):
+ def assertNotInDbusResult(self, member, dbus_result, column=0):
"""
Convenience assertion used in these tests
"""
for row in dbus_result:
if member == str(row[column]):
# This is going to fail with pretty printing
- self.fail ("'%s' wasn't supposed to be in '%s'" % (member, dbus_result))
+ self.fail("'%s' wasn't supposed to be in '%s'" %
+ (member, dbus_result))
return
- def __assert_ontology_dates (self, first_dir, second_dir):
+ def __assert_ontology_dates(self, first_dir, second_dir):
"""
Asserts that 91-test.ontology in second_dir has a more recent
modification time than in first_dir
"""
ISO9601_REGEX = "(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z)"
- def get_ontology_date (ontology):
- for line in open (ontology, 'r'):
+ def get_ontology_date(ontology):
+ for line in open(ontology, 'r'):
if "nao:lastModified" in line:
- getmodtime = re.compile ('nao:lastModified\ \"' + ISO9601_REGEX + '\"')
- modtime_match = getmodtime.search (line)
+ getmodtime = re.compile(
+ 'nao:lastModified\ \"' + ISO9601_REGEX + '\"')
+ modtime_match = getmodtime.search(line)
if (modtime_match):
- nao_date = modtime_match.group (1)
- return time.strptime(nao_date, "%Y-%m-%dT%H:%M:%SZ")
+ nao_date = modtime_match.group(1)
+ return time.strptime(nao_date, "%Y-%m-%dT%H:%M:%SZ")
else:
print("something funky in", line)
break
- first_date = get_ontology_date (os.path.join (first_dir, "91-test.ontology"))
- second_date = get_ontology_date (os.path.join (second_dir, "91-test.ontology"))
+ first_date = get_ontology_date(
+ os.path.join(first_dir, "91-test.ontology"))
+ second_date = get_ontology_date(
+ os.path.join(second_dir, "91-test.ontology"))
if first_date >= second_date:
- self.fail ("nao:modifiedTime in '%s' is not more recent in the second ontology" %
("91-test.ontology"))
+ self.fail("nao:modifiedTime in '%s' is not more recent in the second ontology" % (
+ "91-test.ontology"))
class PropertyRangeStringToDate (OntologyChangeTestTemplate):
@@ -261,26 +266,28 @@ class PropertyRangeStringToDate (OntologyChangeTestTemplate):
@ut.skip("Fails with: basic-future/91-test.ontology: Unsupported ontology change for
http://example.org/ns#a_string: can't change rdfs:range (old=http://www.w3.org/2001/XMLSchema#dateTime,
attempted new=http://www.w3.org/2001/XMLSchema#string)")
@expectedFailureJournal()
- def test_property_range_string_to_date (self):
- self.template_test_ontology_change ()
+ def test_property_range_string_to_date(self):
+ self.template_test_ontology_change()
- def set_ontology_dirs (self):
+ def set_ontology_dirs(self):
self.FIRST_ONTOLOGY_DIR = "basic"
self.SECOND_ONTOLOGY_DIR = "property-range-string-to-date"
- def insert_data (self):
+ def insert_data(self):
self.instance = "test://ontology-change/property-range/string-to-date"
- self.tracker.update ("INSERT { <%s> a test:A ; test:a_string '2010-10-12T13:30:00Z' }"
+ self.tracker.update("INSERT { <%s> a test:A ; test:a_string '2010-10-12T13:30:00Z' }"
% (self.instance))
- def validate_status (self):
+ def validate_status(self):
# Query the ontology itself
- result = self.tracker.query ("SELECT ?o WHERE { test:a_string rdfs:range ?o }")
- self.assertEqual (result[0][0], XSD_DATETIME)
+ result = self.tracker.query(
+ "SELECT ?o WHERE { test:a_string rdfs:range ?o }")
+ self.assertEqual(result[0][0], XSD_DATETIME)
# Check the value is there
- result = self.tracker.query ("SELECT ?o WHERE { <%s> test:a_string ?o . }" % (self.instance))
- self.assertEqual (result[0][0], "2010-10-12T13:30:00Z")
+ result = self.tracker.query(
+ "SELECT ?o WHERE { <%s> test:a_string ?o . }" % (self.instance))
+ self.assertEqual(result[0][0], "2010-10-12T13:30:00Z")
class PropertyRangeDateToString (OntologyChangeTestTemplate):
@@ -290,50 +297,57 @@ class PropertyRangeDateToString (OntologyChangeTestTemplate):
@expectedFailureJournal()
@ut.skip("fails with: basic-future/91-test.ontology: Unsupported ontology change for
http://example.org/ns#a_string: can't change rdfs:range (old=http://www.w3.org/2001/XMLSchema#dateTime,
attempted new=http://www.w3.org/2001/XMLSchema#string)")
- def test_property_range_date_to_string (self):
- self.template_test_ontology_change ()
+ def test_property_range_date_to_string(self):
+ self.template_test_ontology_change()
- def set_ontology_dirs (self):
+ def set_ontology_dirs(self):
self.FIRST_ONTOLOGY_DIR = "property-range-string-to-date"
self.SECOND_ONTOLOGY_DIR = "basic-future"
-
- def insert_data (self):
+
+ def insert_data(self):
self.instance = "test://ontology-change/property-range/date-to-string"
- self.tracker.update ("INSERT { <%s> a test:A ; test:a_string '2010-10-12T13:30:00Z' }"
+ self.tracker.update("INSERT { <%s> a test:A ; test:a_string '2010-10-12T13:30:00Z' }"
% (self.instance))
- def validate_status (self):
+ def validate_status(self):
# Query the ontology itself
- result = self.tracker.query ("SELECT ?o WHERE { test:a_string rdfs:range ?o }")
- self.assertEqual (result[0][0], XSD_STRING)
+ result = self.tracker.query(
+ "SELECT ?o WHERE { test:a_string rdfs:range ?o }")
+ self.assertEqual(result[0][0], XSD_STRING)
# Check the value is there
- result = self.tracker.query ("SELECT ?o WHERE { <%s> test:a_string ?o . }" % (self.instance))
- self.assertEqual (result[0][0], "2010-10-12T13:30:00Z")
+ result = self.tracker.query(
+ "SELECT ?o WHERE { <%s> test:a_string ?o . }" % (self.instance))
+ self.assertEqual(result[0][0], "2010-10-12T13:30:00Z")
+
class PropertyRangeIntToString (OntologyChangeTestTemplate):
"""
Change the range of a property from int to string. There shouldn't be any data loss.
"""
@ut.skip("Fails with: Unable to insert multiple values for subject `http://example.org/ns#a_int' and
single valued property `rdfs:comment' (old_value: 'This property is integer in basic here is string', new
value: 'Property to test the changes string/int')")
- def test_property_range_int_to_str (self):
- self.template_test_ontology_change ()
+ def test_property_range_int_to_str(self):
+ self.template_test_ontology_change()
- def set_ontology_dirs (self):
+ def set_ontology_dirs(self):
self.FIRST_ONTOLOGY_DIR = "basic"
self.SECOND_ONTOLOGY_DIR = "property-range-int-to-string"
- def insert_data (self):
+ def insert_data(self):
self.instance = "test://ontology-change/property-range/int-to-string"
- self.tracker.update ("INSERT { <%s> a test:A; test:a_int 12. }" % (self.instance))
+ self.tracker.update(
+ "INSERT { <%s> a test:A; test:a_int 12. }" % (self.instance))
- def validate_status (self):
- result = self.tracker.query ("SELECT ?o WHERE { test:a_int rdfs:range ?o. }")
- self.assertEqual (str(result[0][0]), XSD_STRING)
+ def validate_status(self):
+ result = self.tracker.query(
+ "SELECT ?o WHERE { test:a_int rdfs:range ?o. }")
+ self.assertEqual(str(result[0][0]), XSD_STRING)
# Check the value is there
- result = self.tracker.query ("SELECT ?o WHERE { <%s> test:a_int ?o .}" % (self.instance))
- self.assertEqual (result[0][0], "12")
+ result = self.tracker.query(
+ "SELECT ?o WHERE { <%s> test:a_int ?o .}" % (self.instance))
+ self.assertEqual(result[0][0], "12")
+
class PropertyRangeStringToInt (OntologyChangeTestTemplate):
"""
@@ -341,56 +355,64 @@ class PropertyRangeStringToInt (OntologyChangeTestTemplate):
"""
@ut.skip("Fails with: Unable to insert multiple values for subject `http://example.org/ns#a_int' and
single valued property `rdfs:comment' (old_value: 'Property to test the changes string/int', new value: 'This
property is integer in basic here is string')")
- def test_property_range_str_to_int (self):
- self.template_test_ontology_change ()
+ def test_property_range_str_to_int(self):
+ self.template_test_ontology_change()
- def set_ontology_dirs (self):
+ def set_ontology_dirs(self):
self.FIRST_ONTOLOGY_DIR = "property-range-int-to-string"
self.SECOND_ONTOLOGY_DIR = "basic-future"
- def insert_data (self):
+ def insert_data(self):
self.instance = "test://ontology-change/property-range/string-to-int"
- self.tracker.update ("INSERT { <%s> a test:A; test:a_int '12'. }" % (self.instance))
+ self.tracker.update(
+ "INSERT { <%s> a test:A; test:a_int '12'. }" % (self.instance))
- def validate_status (self):
- result = self.tracker.query ("SELECT ?o WHERE { test:a_int rdfs:range ?o. }")
- self.assertEqual (str(result[0][0]), XSD_INTEGER)
+ def validate_status(self):
+ result = self.tracker.query(
+ "SELECT ?o WHERE { test:a_int rdfs:range ?o. }")
+ self.assertEqual(str(result[0][0]), XSD_INTEGER)
# Check the value is there
- result = self.tracker.query ("SELECT ?o WHERE { <%s> test:a_int ?o .}" % (self.instance))
- self.assertEqual (result[0][0], "12")
-
+ result = self.tracker.query(
+ "SELECT ?o WHERE { <%s> test:a_int ?o .}" % (self.instance))
+ self.assertEqual(result[0][0], "12")
+
+
class PropertyMaxCardinality1toN (OntologyChangeTestTemplate):
"""
Change cardinality of a property from 1 to N. There shouldn't be any data loss
"""
@expectedFailureJournal()
- def test_property_cardinality_1_to_n (self):
- self.template_test_ontology_change ()
+ def test_property_cardinality_1_to_n(self):
+ self.template_test_ontology_change()
- def set_ontology_dirs (self):
+ def set_ontology_dirs(self):
#self.FIRST_ONTOLOGY_DIR = "basic"
#self.SECOND_ONTOLOGY_DIR = "cardinality"
self.FIRST_ONTOLOGY_DIR = "cardinality"
self.SECOND_ONTOLOGY_DIR = "basic-future"
- def insert_data (self):
+ def insert_data(self):
self.instance = "test://ontology-change/cardinality/1-to-n"
- self.tracker.update ("INSERT { <%s> a test:A; test:a_n_cardinality 'some text'. }" % (self.instance))
+ self.tracker.update(
+ "INSERT { <%s> a test:A; test:a_n_cardinality 'some text'. }" % (self.instance))
+
+ result = self.tracker.query(
+ "SELECT ?o WHERE { test:a_n_cardinality nrl:maxCardinality ?o}")
+ self.assertEqual(int(result[0][0]), 1)
- result = self.tracker.query ("SELECT ?o WHERE { test:a_n_cardinality nrl:maxCardinality ?o}")
- self.assertEqual (int (result[0][0]), 1)
+ def validate_status(self):
+ result = self.tracker.query(
+ "SELECT ?o WHERE { test:a_n_cardinality nrl:maxCardinality ?o}")
+ self.assertEqual(len(result), 0, "Cardinality should be 0")
-
- def validate_status (self):
- result = self.tracker.query ("SELECT ?o WHERE { test:a_n_cardinality nrl:maxCardinality ?o}")
- self.assertEqual (len (result), 0, "Cardinality should be 0")
-
# Check the value is there
- result = self.tracker.query ("SELECT ?o WHERE { <%s> test:a_n_cardinality ?o .}" % (self.instance))
- self.assertEqual (str(result[0][0]), "some text")
+ result = self.tracker.query(
+ "SELECT ?o WHERE { <%s> test:a_n_cardinality ?o .}" % (self.instance))
+ self.assertEqual(str(result[0][0]), "some text")
+
class PropertyMaxCardinalityNto1 (OntologyChangeTestTemplate):
"""
@@ -400,78 +422,87 @@ class PropertyMaxCardinalityNto1 (OntologyChangeTestTemplate):
"""
@ut.expectedFailure
- def test_property_cardinality_n_to_1 (self):
- self.template_test_ontology_change ()
+ def test_property_cardinality_n_to_1(self):
+ self.template_test_ontology_change()
- def set_ontology_dirs (self):
+ def set_ontology_dirs(self):
self.FIRST_ONTOLOGY_DIR = "basic"
self.SECOND_ONTOLOGY_DIR = "cardinality"
- def insert_data (self):
+ def insert_data(self):
self.instance = "test://ontology-change/cardinality/1-to-n"
- self.tracker.update ("INSERT { <%s> a test:A; test:a_n_cardinality 'some text'. }" % (self.instance))
+ self.tracker.update(
+ "INSERT { <%s> a test:A; test:a_n_cardinality 'some text'. }" % (self.instance))
+
+ result = self.tracker.query(
+ "SELECT ?o WHERE { test:a_n_cardinality nrl:maxCardinality ?o}")
+ self.assertEqual(len(result), 0, "Cardinality should be 0")
- result = self.tracker.query ("SELECT ?o WHERE { test:a_n_cardinality nrl:maxCardinality ?o}")
- self.assertEqual (len (result), 0, "Cardinality should be 0")
+ def validate_status(self):
+ result = self.tracker.query(
+ "SELECT ?o WHERE { test:a_n_cardinality nrl:maxCardinality ?o}")
+ self.assertEqual(int(result[0][0]), 1, "Cardinality should be 1")
-
- def validate_status (self):
- result = self.tracker.query ("SELECT ?o WHERE { test:a_n_cardinality nrl:maxCardinality ?o}")
- self.assertEqual (int (result[0][0]), 1, "Cardinality should be 1")
-
# Check the value is there
- result = self.tracker.query ("SELECT ?o WHERE { <%s> test:a_n_cardinality ?o .}" % (self.instance))
- self.assertEqual (str(result[0][0]), "some text")
+ result = self.tracker.query(
+ "SELECT ?o WHERE { <%s> test:a_n_cardinality ?o .}" % (self.instance))
+ self.assertEqual(str(result[0][0]), "some text")
+
class ClassNotifySet (OntologyChangeTestTemplate):
"""
Set tracker:notify to true in a class and check there is no data loss
"""
- def test_property_notify_set (self):
- self.template_test_ontology_change ()
- def set_ontology_dirs (self):
+ def test_property_notify_set(self):
+ self.template_test_ontology_change()
+
+ def set_ontology_dirs(self):
self.FIRST_ONTOLOGY_DIR = "basic"
self.SECOND_ONTOLOGY_DIR = "notify"
- def insert_data (self):
+ def insert_data(self):
self.instance = "test://ontology-change/notify/true"
- self.tracker.update ("INSERT { <%s> a test:A; test:a_string 'some text'. }" % (self.instance))
+ self.tracker.update(
+ "INSERT { <%s> a test:A; test:a_string 'some text'. }" % (self.instance))
+ def validate_status(self):
+ result = self.tracker.query(
+ "SELECT ?notify WHERE { test:A tracker:notify ?notify}")
+ self.assertEqual(str(result[0][0]), "true")
+
+ result = self.tracker.query("SELECT ?u WHERE { ?u a test:A. }")
+ self.assertEqual(str(result[0][0]), self.instance)
- def validate_status (self):
- result = self.tracker.query ("SELECT ?notify WHERE { test:A tracker:notify ?notify}")
- self.assertEqual (str(result[0][0]), "true")
-
- result = self.tracker.query ("SELECT ?u WHERE { ?u a test:A. }")
- self.assertEqual (str(result[0][0]), self.instance)
class ClassNotifyUnset (OntologyChangeTestTemplate):
"""
Set tracker:notify to true in a class and check there is no data loss
"""
- def test_property_notify_set (self):
- self.template_test_ontology_change ()
- def set_ontology_dirs (self):
+ def test_property_notify_set(self):
+ self.template_test_ontology_change()
+
+ def set_ontology_dirs(self):
self.FIRST_ONTOLOGY_DIR = "notify"
self.SECOND_ONTOLOGY_DIR = "basic-future"
- def insert_data (self):
+ def insert_data(self):
self.instance = "test://ontology-change/notify/true"
- self.tracker.update ("INSERT { <%s> a test:A; test:a_string 'some text'. }" % (self.instance))
-
+ self.tracker.update(
+ "INSERT { <%s> a test:A; test:a_string 'some text'. }" % (self.instance))
- def validate_status (self):
- result = self.tracker.query ("SELECT ?notify WHERE { test:A tracker:notify ?notify}")
- if (len (result) == 1):
+ def validate_status(self):
+ result = self.tracker.query(
+ "SELECT ?notify WHERE { test:A tracker:notify ?notify}")
+ if (len(result) == 1):
# Usually is (none) but it was "true" before so now has value.
- self.assertEqual (result[0][0], "false")
+ self.assertEqual(result[0][0], "false")
else:
- self.assertEqual (len (result), 0)
-
- result = self.tracker.query ("SELECT ?u WHERE { ?u a test:A. }")
- self.assertEqual (str(result[0][0]), self.instance)
+ self.assertEqual(len(result), 0)
+
+ result = self.tracker.query("SELECT ?u WHERE { ?u a test:A. }")
+ self.assertEqual(str(result[0][0]), self.instance)
class PropertyIndexedSet (OntologyChangeTestTemplate):
@@ -479,179 +510,192 @@ class PropertyIndexedSet (OntologyChangeTestTemplate):
Set tracker:indexed true to single and multiple valued properties.
Check that instances and content of the property are still in the DB
"""
- def test_indexed_set (self):
- self.template_test_ontology_change ()
- def set_ontology_dirs (self):
+ def test_indexed_set(self):
+ self.template_test_ontology_change()
+
+ def set_ontology_dirs(self):
self.FIRST_ONTOLOGY_DIR = "basic"
self.SECOND_ONTOLOGY_DIR = "indexed"
- def insert_data (self):
+ def insert_data(self):
# Instance with value in the single valued property
self.instance_single_valued = "test://ontology-change/indexed/single/true"
- self.tracker.update ("INSERT { <%s> a test:A ; test:a_string 'anything 1'. }"
+ self.tracker.update("INSERT { <%s> a test:A ; test:a_string 'anything 1'. }"
% (self.instance_single_valued))
# Instance with value in the n valued property
self.instance_n_valued = "test://ontology-change/indexed/multiple/true"
- self.tracker.update ("INSERT { <%s> a test:A ; test:a_n_cardinality 'anything n'. }"
+ self.tracker.update("INSERT { <%s> a test:A ; test:a_n_cardinality 'anything n'. }"
% (self.instance_n_valued))
- def validate_status (self):
+ def validate_status(self):
# Check ontology and instance for the single valued property
- result = self.tracker.query ("SELECT ?indexed WHERE { test:a_string tracker:indexed ?indexed}")
- self.assertEqual (str(result[0][0]), "true")
+ result = self.tracker.query(
+ "SELECT ?indexed WHERE { test:a_string tracker:indexed ?indexed}")
+ self.assertEqual(str(result[0][0]), "true")
- result = self.tracker.query ("SELECT ?content WHERE { <%s> a test:A; test:a_string ?content. }"
+ result = self.tracker.query("SELECT ?content WHERE { <%s> a test:A; test:a_string ?content. }"
% (self.instance_single_valued))
- self.assertEqual (str(result[0][0]), "anything 1")
+ self.assertEqual(str(result[0][0]), "anything 1")
# Check ontology and instance for the multiple valued property
- result = self.tracker.query ("SELECT ?indexed WHERE { test:a_n_cardinality tracker:indexed
?indexed}")
- self.assertEqual (str(result[0][0]), "true")
+ result = self.tracker.query(
+ "SELECT ?indexed WHERE { test:a_n_cardinality tracker:indexed ?indexed}")
+ self.assertEqual(str(result[0][0]), "true")
- result = self.tracker.query ("SELECT ?content WHERE { <%s> a test:A; test:a_n_cardinality ?content.
}"
+ result = self.tracker.query("SELECT ?content WHERE { <%s> a test:A; test:a_n_cardinality ?content. }"
% (self.instance_n_valued))
- self.assertEqual (str(result[0][0]), "anything n")
+ self.assertEqual(str(result[0][0]), "anything n")
+
class PropertyIndexedUnset (OntologyChangeTestTemplate):
"""
tracker:indexed property from true to false in single and multiple valued properties.
Check that instances and content of the property are still in the DB.
"""
- def test_indexed_unset (self):
- self.template_test_ontology_change ()
- def set_ontology_dirs (self):
+ def test_indexed_unset(self):
+ self.template_test_ontology_change()
+
+ def set_ontology_dirs(self):
self.FIRST_ONTOLOGY_DIR = "indexed"
self.SECOND_ONTOLOGY_DIR = "basic-future"
- def insert_data (self):
+ def insert_data(self):
# Instance with value in the single valued property
self.instance_single_valued = "test://ontology-change/indexed/single/true"
- self.tracker.update ("INSERT { <%s> a test:A ; test:a_string 'anything 1'. }"
+ self.tracker.update("INSERT { <%s> a test:A ; test:a_string 'anything 1'. }"
% (self.instance_single_valued))
# Instance with value in the n valued property
self.instance_n_valued = "test://ontology-change/indexed/multiple/true"
- self.tracker.update ("INSERT { <%s> a test:A ; test:a_n_cardinality 'anything n'. }"
+ self.tracker.update("INSERT { <%s> a test:A ; test:a_n_cardinality 'anything n'. }"
% (self.instance_n_valued))
- def validate_status (self):
+ def validate_status(self):
#
# NOTE: tracker:indexed can be 'false' or None. In both cases is fine.
- #
-
+ #
+
# Check ontology and instance for the single valued property
- result = self.tracker.query ("SELECT ?indexed WHERE { test:a_string tracker:indexed ?indexed}")
- self.assertEqual (str(result[0][0]), "false")
+ result = self.tracker.query(
+ "SELECT ?indexed WHERE { test:a_string tracker:indexed ?indexed}")
+ self.assertEqual(str(result[0][0]), "false")
- result = self.tracker.query ("SELECT ?content WHERE { <%s> a test:A; test:a_string ?content. }"
+ result = self.tracker.query("SELECT ?content WHERE { <%s> a test:A; test:a_string ?content. }"
% (self.instance_single_valued))
- self.assertEqual (str(result[0][0]), "anything 1")
+ self.assertEqual(str(result[0][0]), "anything 1")
# Check ontology and instance for the multiple valued property
- result = self.tracker.query ("SELECT ?indexed WHERE { test:a_n_cardinality tracker:indexed
?indexed}")
- self.assertEqual (str(result[0][0]), "false")
+ result = self.tracker.query(
+ "SELECT ?indexed WHERE { test:a_n_cardinality tracker:indexed ?indexed}")
+ self.assertEqual(str(result[0][0]), "false")
- result = self.tracker.query ("SELECT ?content WHERE { <%s> a test:A; test:a_n_cardinality ?content.
}"
+ result = self.tracker.query("SELECT ?content WHERE { <%s> a test:A; test:a_n_cardinality ?content. }"
% (self.instance_n_valued))
- self.assertEqual (str(result[0][0]), "anything n")
+ self.assertEqual(str(result[0][0]), "anything n")
+
class OntologyAddClassTest (OntologyChangeTestTemplate):
"""
Add a class in the ontology.
"""
- def test_ontology_add_class (self):
- self.template_test_ontology_change ()
- def set_ontology_dirs (self):
+ def test_ontology_add_class(self):
+ self.template_test_ontology_change()
+
+ def set_ontology_dirs(self):
self.FIRST_ONTOLOGY_DIR = "basic"
self.SECOND_ONTOLOGY_DIR = "add-class"
- def insert_data (self):
+ def insert_data(self):
# No need, adding a class
pass
- def validate_status (self):
+ def validate_status(self):
# check the class is there
- result = self.tracker.query ("SELECT ?k WHERE { ?k a rdfs:Class. }")
- self.assertInDbusResult (TEST_PREFIX + "D", result)
+ result = self.tracker.query("SELECT ?k WHERE { ?k a rdfs:Class. }")
+ self.assertInDbusResult(TEST_PREFIX + "D", result)
- result = self.tracker.query ("SELECT ?k WHERE { ?k a rdfs:Class. }")
- self.assertInDbusResult (TEST_PREFIX + "E", result)
+ result = self.tracker.query("SELECT ?k WHERE { ?k a rdfs:Class. }")
+ self.assertInDbusResult(TEST_PREFIX + "E", result)
class OntologyRemoveClassTest (OntologyChangeTestTemplate):
"""
Remove a class from the ontology. With and without superclasses.
"""
- def test_ontology_remove_class (self):
- self.template_test_ontology_change ()
- def set_ontology_dirs (self):
+ def test_ontology_remove_class(self):
+ self.template_test_ontology_change()
+
+ def set_ontology_dirs(self):
self.FIRST_ONTOLOGY_DIR = "add-class"
self.SECOND_ONTOLOGY_DIR = "basic-future"
- def insert_data (self):
+ def insert_data(self):
self.instance_e = "test://ontology-change/removal/class/1"
- self.tracker.update ("INSERT { <%s> a test:E. }" % self.instance_e)
+ self.tracker.update("INSERT { <%s> a test:E. }" % self.instance_e)
self.instance_d = "test://ontology-change/removal/class/2"
- self.tracker.update ("INSERT { <%s> a test:D. }" % self.instance_d)
+ self.tracker.update("INSERT { <%s> a test:D. }" % self.instance_d)
- def validate_status (self):
+ def validate_status(self):
#
# The classes are not actually removed... so this assertions are not valid (yet?)
#
-
+
#result = self.tracker.query ("SELECT ?k WHERE { ?k a rdfs:Class. }")
#self.assertNotInDbusResult (TEST_PREFIX + "E", result)
#self.assertNotInDbusResult (TEST_PREFIX + "D", result)
# D is a subclass of A, removing D should keep the A instances
- result = self.tracker.query ("SELECT ?i WHERE { ?i a test:A. }")
- self.assertEqual (result[0][0], self.instance_e)
+ result = self.tracker.query("SELECT ?i WHERE { ?i a test:A. }")
+ self.assertEqual(result[0][0], self.instance_e)
+
class OntologyAddPropertyTest (OntologyChangeTestTemplate):
"""
Add new properties in the ontology, with/without super prop and different ranges and cardinalities
"""
@ut.skip("Fails with:Unable to insert multiple values for subject `http://example.org/ns#a_int' and
single valued property `rdfs:comment' (old_value: 'This property is integer in basic here is string', new
value: 'Property to test the changes string/int')")
- def test_ontology_add_property (self):
- self.template_test_ontology_change ()
+ def test_ontology_add_property(self):
+ self.template_test_ontology_change()
- def set_ontology_dirs (self):
+ def set_ontology_dirs(self):
self.FIRST_ONTOLOGY_DIR = "basic"
self.SECOND_ONTOLOGY_DIR = "add-prop"
- def insert_data (self):
+ def insert_data(self):
# No need, adding new properties
pass
- def validate_status (self):
- result = self.tracker.query ("SELECT ?k WHERE { ?k a rdf:Property}")
- self.assertInDbusResult (TEST_PREFIX + "new_prop_int", result)
- self.assertInDbusResult (TEST_PREFIX + "new_prop_int_n", result)
+ def validate_status(self):
+ result = self.tracker.query("SELECT ?k WHERE { ?k a rdf:Property}")
+ self.assertInDbusResult(TEST_PREFIX + "new_prop_int", result)
+ self.assertInDbusResult(TEST_PREFIX + "new_prop_int_n", result)
- self.assertInDbusResult (TEST_PREFIX + "new_prop_string", result)
- self.assertInDbusResult (TEST_PREFIX + "new_prop_string_n", result)
+ self.assertInDbusResult(TEST_PREFIX + "new_prop_string", result)
+ self.assertInDbusResult(TEST_PREFIX + "new_prop_string_n", result)
+
+ self.assertInDbusResult(TEST_PREFIX + "new_subprop_string", result)
+ self.assertInDbusResult(TEST_PREFIX + "new_subprop_string_n", result)
- self.assertInDbusResult (TEST_PREFIX + "new_subprop_string", result)
- self.assertInDbusResult (TEST_PREFIX + "new_subprop_string_n", result)
class OntologyRemovePropertyTest (OntologyChangeTestTemplate):
"""
Remove properties from the ontology, with and without super props and different ranges and cardinalities
"""
- def test_ontology_remove_property (self):
- self.template_test_ontology_change ()
- def set_ontology_dirs (self):
+ def test_ontology_remove_property(self):
+ self.template_test_ontology_change()
+
+ def set_ontology_dirs(self):
self.FIRST_ONTOLOGY_DIR = "add-prop"
self.SECOND_ONTOLOGY_DIR = "basic-future"
- def insert_data (self):
+ def insert_data(self):
self.instance_a = "test://ontology-change/remove/properties/1"
self.tracker.update ("""
INSERT { <%s> a test:A;
@@ -670,14 +714,16 @@ class OntologyRemovePropertyTest (OntologyChangeTestTemplate):
test:new_subprop_string_n 'super-prop also keeps this value'.
}
""" % (self.instance_b))
- self.assertTrue (self.tracker.ask ("ASK { <%s> a test:A}" % (self.instance_a)), "The instance is not
there")
+ self.assertTrue(self.tracker.ask("ASK { <%s> a test:A}" % (
+ self.instance_a)), "The instance is not there")
- def validate_status (self):
+ def validate_status(self):
#
# Note: on removal basically nothing happens. The property and values are still in the DB
#
- # Maybe we should test there forcing a db reconstruction and journal replay
-
+ # Maybe we should test there forcing a db reconstruction and journal
+ # replay
+
# First the ontology
## result = self.tracker.query ("SELECT ?k WHERE { ?k a rdf:Property}")
## self.assertNotInDbusResult (TEST_PREFIX + "new_prop_int", result)
@@ -690,28 +736,33 @@ class OntologyRemovePropertyTest (OntologyChangeTestTemplate):
## self.assertNotInDbusResult (TEST_PREFIX + "new_subprop_string_n", result)
# The instances are still there
- self.assertTrue (self.tracker.ask ("ASK { <%s> a test:A}" % (self.instance_a)))
- self.assertTrue (self.tracker.ask ("ASK { <%s> a test:B}" % (self.instance_b)))
+ self.assertTrue(self.tracker.ask(
+ "ASK { <%s> a test:A}" % (self.instance_a)))
+ self.assertTrue(self.tracker.ask(
+ "ASK { <%s> a test:B}" % (self.instance_b)))
+
+ check = self.tracker.ask(
+ "ASK { <%s> test:a_superprop 'super-prop keeps this value' }" % (self.instance_b))
+ self.assertTrue(check, "This property and value should exist")
+
+ check = self.tracker.ask(
+ "ASK { <%s> test:a_superprop_n 'super-prop also keeps this value' }" % (self.instance_b))
+ self.assertTrue(check, "This property and value should exist")
- check = self.tracker.ask ("ASK { <%s> test:a_superprop 'super-prop keeps this value' }" %
(self.instance_b))
- self.assertTrue (check, "This property and value should exist")
-
- check = self.tracker.ask ("ASK { <%s> test:a_superprop_n 'super-prop also keeps this value' }" %
(self.instance_b))
- self.assertTrue (check, "This property and value should exist")
class DomainIndexAddTest (OntologyChangeTestTemplate):
"""
Add tracker:domainIndex to a class and check there is no data loss.
"""
@ut.skip("Fails with: basic-future/91-test.ontology: Unsupported ontology change for test:b_property:
can't change rdfs:domain (old=test:A, attempted new=test:B) ")
- def test_domain_index_add (self):
- self.template_test_ontology_change ()
+ def test_domain_index_add(self):
+ self.template_test_ontology_change()
- def set_ontology_dirs (self):
+ def set_ontology_dirs(self):
self.FIRST_ONTOLOGY_DIR = "basic"
self.SECOND_ONTOLOGY_DIR = "add-domainIndex"
- def insert_data (self):
+ def insert_data(self):
self.instance_a = "test://ontology-changes/properties/add-domain-index/a"
self.tracker.update ("""
INSERT { <%s> a test:B ;
@@ -724,34 +775,39 @@ class DomainIndexAddTest (OntologyChangeTestTemplate):
test:a_string 'test-value' ;
test:a_n_cardinality 'another-test-value'. }""" % (self.instance_b))
- def validate_status (self):
+ def validate_status(self):
# Check the ontology
- has_domainIndex = self.tracker.ask ("ASK { test:B tracker:domainIndex test:a_string }")
- self.assertTrue (has_domainIndex)
+ has_domainIndex = self.tracker.ask(
+ "ASK { test:B tracker:domainIndex test:a_string }")
+ self.assertTrue(has_domainIndex)
- has_domainIndex = self.tracker.ask ("ASK { test:C tracker:domainIndex test:a_n_cardinality }")
- self.assertTrue (has_domainIndex)
+ has_domainIndex = self.tracker.ask(
+ "ASK { test:C tracker:domainIndex test:a_n_cardinality }")
+ self.assertTrue(has_domainIndex)
# Check the data
- dataok = self.tracker.ask ("ASK { <%s> test:a_string 'test-value' }" % (self.instance_a))
- self.assertTrue (dataok)
+ dataok = self.tracker.ask(
+ "ASK { <%s> test:a_string 'test-value' }" % (self.instance_a))
+ self.assertTrue(dataok)
- dataok = self.tracker.ask ("ASK { <%s> test:a_n_cardinality 'another-test-value' }" %
(self.instance_b))
- self.assertTrue (dataok)
+ dataok = self.tracker.ask(
+ "ASK { <%s> test:a_n_cardinality 'another-test-value' }" % (self.instance_b))
+ self.assertTrue(dataok)
class DomainIndexRemoveTest (OntologyChangeTestTemplate):
"""
Remove tracker:domainIndex to a class and check there is no data loss.
"""
- def test_domain_index_remove (self):
- self.template_test_ontology_change ()
- def set_ontology_dirs (self):
+ def test_domain_index_remove(self):
+ self.template_test_ontology_change()
+
+ def set_ontology_dirs(self):
self.FIRST_ONTOLOGY_DIR = "add-domainIndex"
self.SECOND_ONTOLOGY_DIR = "basic-future"
- def insert_data (self):
+ def insert_data(self):
self.instance_a = "test://ontology-changes/properties/add-domain-index/a"
self.tracker.update ("""
INSERT { <%s> a test:B ;
@@ -764,20 +820,24 @@ class DomainIndexRemoveTest (OntologyChangeTestTemplate):
test:a_string 'test-value' ;
test:a_n_cardinality 'another-test-value'. }""" % (self.instance_b))
- def validate_status (self):
+ def validate_status(self):
# Check the ontology
- has_domainIndex = self.tracker.ask ("ASK { test:B tracker:domainIndex test:a_string }")
- self.assertFalse (has_domainIndex)
+ has_domainIndex = self.tracker.ask(
+ "ASK { test:B tracker:domainIndex test:a_string }")
+ self.assertFalse(has_domainIndex)
- has_domainIndex = self.tracker.ask ("ASK { test:C tracker:domainIndex test:a_n_cardinality }")
- self.assertFalse (has_domainIndex)
+ has_domainIndex = self.tracker.ask(
+ "ASK { test:C tracker:domainIndex test:a_n_cardinality }")
+ self.assertFalse(has_domainIndex)
# Check the data
- dataok = self.tracker.ask ("ASK { <%s> test:a_string 'test-value' }" % (self.instance_a))
- self.assertTrue (dataok)
+ dataok = self.tracker.ask(
+ "ASK { <%s> test:a_string 'test-value' }" % (self.instance_a))
+ self.assertTrue(dataok)
- dataok = self.tracker.ask ("ASK { <%s> test:a_n_cardinality 'another-test-value' }" %
(self.instance_b))
- self.assertTrue (dataok)
+ dataok = self.tracker.ask(
+ "ASK { <%s> test:a_n_cardinality 'another-test-value' }" % (self.instance_b))
+ self.assertTrue(dataok)
class SuperclassRemovalTest (OntologyChangeTestTemplate):
@@ -786,17 +846,17 @@ class SuperclassRemovalTest (OntologyChangeTestTemplate):
"""
@expectedFailureJournal()
@ut.skip("Fails with: Unsupported ontology change for http://example.org/ns#B: can't change
rdfs:subClassOf (old=-, attempted new=-)")
- def test_superclass_removal (self):
- self.template_test_ontology_change ()
-
- def set_ontology_dirs (self):
+ def test_superclass_removal(self):
+ self.template_test_ontology_change()
+
+ def set_ontology_dirs(self):
self.FIRST_ONTOLOGY_DIR = "basic"
self.SECOND_ONTOLOGY_DIR = "superclass-remove"
-
- def insert_data (self):
- is_subclass = self.tracker.ask ("ASK {test:B rdfs:subClassOf test:A}")
- self.assertTrue (is_subclass)
-
+
+ def insert_data(self):
+ is_subclass = self.tracker.ask("ASK {test:B rdfs:subClassOf test:A}")
+ self.assertTrue(is_subclass)
+
self.instance_a = "test://ontology-changes/superclasses/remove-superclass/a"
self.tracker.update ("""
INSERT { <%s> a test:A . }
@@ -807,21 +867,22 @@ class SuperclassRemovalTest (OntologyChangeTestTemplate):
INSERT { <%s> a test:B . }
""" % (self.instance_b))
- result = self.tracker.count_instances ("test:B")
- self.assertEqual (result, 1)
+ result = self.tracker.count_instances("test:B")
+ self.assertEqual(result, 1)
+
+ result = self.tracker.count_instances("test:A")
+ self.assertEqual(result, 2)
- result = self.tracker.count_instances ("test:A")
- self.assertEqual (result, 2)
+ def validate_status(self):
+ is_subclass = self.tracker.ask("ASK {test:B rdfs:subClassOf test:A}")
+ self.assertFalse(is_subclass)
- def validate_status (self):
- is_subclass = self.tracker.ask ("ASK {test:B rdfs:subClassOf test:A}")
- self.assertFalse (is_subclass)
+ result = self.tracker.count_instances("test:B")
+ self.assertEqual(result, 1)
- result = self.tracker.count_instances ("test:B")
- self.assertEqual (result, 1)
+ result = self.tracker.count_instances("test:A")
+ self.assertEqual(result, 1)
- result = self.tracker.count_instances ("test:A")
- self.assertEqual (result, 1)
class SuperclassAdditionTest (OntologyChangeTestTemplate):
"""
@@ -829,17 +890,17 @@ class SuperclassAdditionTest (OntologyChangeTestTemplate):
"""
@ut.skip("Fails with: basic-future/91-test.ontology: Unsupported ontology change for test:B: can't
change rdfs:subClassOf (old=-, attempted new=test:A)")
@expectedFailureJournal()
- def test_superclass_addition (self):
- self.template_test_ontology_change ()
-
- def set_ontology_dirs (self):
+ def test_superclass_addition(self):
+ self.template_test_ontology_change()
+
+ def set_ontology_dirs(self):
self.FIRST_ONTOLOGY_DIR = "superclass-remove"
self.SECOND_ONTOLOGY_DIR = "basic-future"
-
- def insert_data (self):
- is_subclass = self.tracker.ask ("ASK {test:B rdfs:subClassOf test:A}")
- self.assertFalse (is_subclass)
-
+
+ def insert_data(self):
+ is_subclass = self.tracker.ask("ASK {test:B rdfs:subClassOf test:A}")
+ self.assertFalse(is_subclass)
+
self.instance_a = "test://ontology-changes/superclasses/remove-superclass/a"
self.tracker.update ("""
INSERT { <%s> a test:A . }
@@ -850,22 +911,22 @@ class SuperclassAdditionTest (OntologyChangeTestTemplate):
INSERT { <%s> a test:B . }
""" % (self.instance_b))
- result = self.tracker.count_instances ("test:B")
- self.assertEqual (result, 1)
+ result = self.tracker.count_instances("test:B")
+ self.assertEqual(result, 1)
+
+ result = self.tracker.count_instances("test:A")
+ self.assertEqual(result, 1)
- result = self.tracker.count_instances ("test:A")
- self.assertEqual (result, 1)
-
- def validate_status (self):
- is_subclass = self.tracker.ask ("ASK {test:B rdfs:subClassOf test:A}")
- self.assertTrue (is_subclass)
+ def validate_status(self):
+ is_subclass = self.tracker.ask("ASK {test:B rdfs:subClassOf test:A}")
+ self.assertTrue(is_subclass)
- result = self.tracker.count_instances ("test:B")
- self.assertEqual (result, 1)
+ result = self.tracker.count_instances("test:B")
+ self.assertEqual(result, 1)
+
+ result = self.tracker.count_instances("test:A")
+ self.assertEqual(result, 2)
- result = self.tracker.count_instances ("test:A")
- self.assertEqual (result, 2)
-
class PropertyPromotionTest (OntologyChangeTestTemplate):
"""
@@ -873,35 +934,36 @@ class PropertyPromotionTest (OntologyChangeTestTemplate):
"""
@ut.skip("Fails with: basic-future/91-test.ontology: Unsupported ontology change for test:b_property:
can't change rdfs:domain (old=test:A, attempted new=test:B)")
@expectedFailureJournal()
- def test_property_promotion (self):
- self.template_test_ontology_change ()
-
- def set_ontology_dirs (self):
+ def test_property_promotion(self):
+ self.template_test_ontology_change()
+
+ def set_ontology_dirs(self):
self.FIRST_ONTOLOGY_DIR = "basic"
self.SECOND_ONTOLOGY_DIR = "property-promotion"
-
- def insert_data (self):
+
+ def insert_data(self):
self.instance_b = "test://ontology-change/property/promotion-to-superclass/b"
self.tracker.update ("""
INSERT { <%s> a test:B; test:b_property 'content-b-test'; test:b_property_n 'b-test-n'. }
""" % (self.instance_b))
self.instance_a = "test://ontology-change/property/promotion-to-superclass/a"
- self.assertRaises (GLib.Error,
- self.tracker.update,
- "INSERT { <%s> a test:A; test:b_property 'content-a-test'.}" % (self.instance_a))
-
- def validate_status (self):
+ self.assertRaises(GLib.Error,
+ self.tracker.update,
+ "INSERT { <%s> a test:A; test:b_property 'content-a-test'.}" % (self.instance_a))
+
+ def validate_status(self):
# This insertion should work now
self.tracker.update ("""
INSERT { <%s> a test:A; test:b_property 'content-a-test'.}
""" % (self.instance_a))
# No data loss
- result = self.tracker.query ("SELECT ?v ?w WHERE { <%s> test:b_property ?v ; test:b_property_n ?w }"
+ result = self.tracker.query("SELECT ?v ?w WHERE { <%s> test:b_property ?v ; test:b_property_n ?w }"
% (self.instance_b))
- self.assertEqual (result [0][0], "content-b-test")
- self.assertEqual (result [0][1], "b-test-n")
+ self.assertEqual(result[0][0], "content-b-test")
+ self.assertEqual(result[0][1], "b-test-n")
+
class PropertyRelegationTest (OntologyChangeTestTemplate):
"""
@@ -909,14 +971,14 @@ class PropertyRelegationTest (OntologyChangeTestTemplate):
"""
@ut.skip("Fails")
@expectedFailureJournal()
- def test_property_relegation (self):
- self.template_test_ontology_change ()
-
- def set_ontology_dirs (self):
+ def test_property_relegation(self):
+ self.template_test_ontology_change()
+
+ def set_ontology_dirs(self):
self.FIRST_ONTOLOGY_DIR = "property-promotion"
self.SECOND_ONTOLOGY_DIR = "basic-future"
-
- def insert_data (self):
+
+ def insert_data(self):
self.instance_b = "test://ontology-change/property/promotion-to-superclass/b"
self.tracker.update ("""
INSERT { <%s> a test:B; test:b_property 'content-b-test'; test:b_property_n 'b-test-n'. }
@@ -926,21 +988,18 @@ class PropertyRelegationTest (OntologyChangeTestTemplate):
self.tracker.update ("""
INSERT { <%s> a test:A; test:b_property 'content-a-test'.}
""" % (self.instance_a))
-
- def validate_status (self):
+
+ def validate_status(self):
# This insertion should fail now
- self.assertRaises (GLib.Error,
- self.tracker.update,
- "INSERT { <%s> a test:A; test:b_property 'content-a-test'.}" % (self.instance_a))
+ self.assertRaises(GLib.Error,
+ self.tracker.update,
+ "INSERT { <%s> a test:A; test:b_property 'content-a-test'.}" % (self.instance_a))
# No data loss
- result = self.tracker.query ("SELECT ?v ?w WHERE { <%s> test:b_property ?v; test:b_property_n ?w }"
+ result = self.tracker.query("SELECT ?v ?w WHERE { <%s> test:b_property ?v; test:b_property_n ?w }"
% (self.instance_b))
- self.assertEqual (result [0][0], "content-b-test")
- self.assertEqual (result [0][1], "b-test-n")
-
+ self.assertEqual(result[0][0], "content-b-test")
+ self.assertEqual(result[0][1], "b-test-n")
if __name__ == "__main__":
- ut.main ()
-
-
+ ut.main()
diff --git a/tests/functional-tests/common/utils/configuration.py
b/tests/functional-tests/common/utils/configuration.py
index 5332e26e7..9fd8c1c64 100644
--- a/tests/functional-tests/common/utils/configuration.py
+++ b/tests/functional-tests/common/utils/configuration.py
@@ -60,7 +60,9 @@ DCONF_MINER_SCHEMA = "org.freedesktop.Tracker.Miner.Files"
# Autoconf substitutes paths in the configuration.json file without
# expanding variables, so we need to manually insert these.
-def expandvars (variable):
+
+
+def expandvars(variable):
# Note: the order matters!
result = variable
for var, value in [("${datarootdir}", RAW_DATAROOT_DIR),
@@ -68,7 +70,7 @@ def expandvars (variable):
("${prefix}", PREFIX),
("@top_srcdir@", TOP_SRCDIR),
("@top_builddir@", TOP_BUILDDIR)]:
- result = result.replace (var, value)
+ result = result.replace(var, value)
return result
@@ -77,15 +79,18 @@ PREFIX = config['PREFIX']
RAW_EXEC_PREFIX = config['RAW_EXEC_PREFIX']
RAW_DATAROOT_DIR = config['RAW_DATAROOT_DIR']
-TOP_SRCDIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))))
+TOP_SRCDIR = os.path.dirname(os.path.dirname(
+ os.path.dirname(os.path.dirname(os.path.dirname(__file__)))))
TOP_BUILDDIR = os.environ['TRACKER_FUNCTIONAL_TEST_BUILD_DIR']
-TEST_ONTOLOGIES_DIR = os.path.normpath(expandvars(config['TEST_ONTOLOGIES_DIR']))
+TEST_ONTOLOGIES_DIR = os.path.normpath(
+ expandvars(config['TEST_ONTOLOGIES_DIR']))
TRACKER_STORE_PATH = os.path.normpath(expandvars(config['TRACKER_STORE_PATH']))
disableJournal = (len(config['disableJournal']) == 0)
+
def generated_ttl_dir():
if TOP_BUILDDIR:
return os.path.join(TOP_BUILDDIR, 'tests', 'functional-tests', 'ttl')
diff --git a/tests/functional-tests/common/utils/dconf.py b/tests/functional-tests/common/utils/dconf.py
index 8aa74f29a..d4b42dfe9 100644
--- a/tests/functional-tests/common/utils/dconf.py
+++ b/tests/functional-tests/common/utils/dconf.py
@@ -5,6 +5,7 @@ import os
from common.utils.helpers import log
+
class DConfClient(object):
"""
Allow changing Tracker configuration in DConf.
@@ -20,7 +21,7 @@ class DConfClient(object):
break.
"""
- def __init__ (self, schema):
+ def __init__(self, schema):
self._settings = Gio.Settings.new(schema)
backend = self._settings.get_property('backend')
@@ -69,10 +70,10 @@ class DConfClient(object):
# XDG_CONFIG_HOME is useless, so we use HOME. This code should not be
# needed unless for some reason the test is not being run via the
# 'test-runner.sh' script.
- dconf_db = os.path.join (os.environ ["HOME"],
- ".config",
- "dconf",
- "trackertest")
- if os.path.exists (dconf_db):
- log ("[Conf] Removing dconf database: " + dconf_db)
- os.remove (dconf_db)
+ dconf_db = os.path.join(os.environ["HOME"],
+ ".config",
+ "dconf",
+ "trackertest")
+ if os.path.exists(dconf_db):
+ log("[Conf] Removing dconf database: " + dconf_db)
+ os.remove(dconf_db)
diff --git a/tests/functional-tests/common/utils/expectedFailure.py
b/tests/functional-tests/common/utils/expectedFailure.py
index 1b11ec170..e7f0eb68c 100644
--- a/tests/functional-tests/common/utils/expectedFailure.py
+++ b/tests/functional-tests/common/utils/expectedFailure.py
@@ -1,25 +1,25 @@
#!/usr/bin/python3
-## Code taken and modified from unittest2 framework (case.py)
+# Code taken and modified from unittest2 framework (case.py)
-## Copyright (c) 1999-2003 Steve Purcell
-## Copyright (c) 2003-2010 Python Software Foundation
-## Copyright (c) 2010, Nokia (ivan frade nokia com)
+# Copyright (c) 1999-2003 Steve Purcell
+# Copyright (c) 2003-2010 Python Software Foundation
+# Copyright (c) 2010, Nokia (ivan frade nokia com)
-## This module is free software, and you may redistribute it and/or modify
-## it under the same terms as Python itself, so long as this copyright message
-## and disclaimer are retained in their original form.
+# This module is free software, and you may redistribute it and/or modify
+# it under the same terms as Python itself, so long as this copyright message
+# and disclaimer are retained in their original form.
-## IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
-## SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF
-## THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
-## DAMAGE.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+# SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF
+# THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+# DAMAGE.
-## THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
-## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
-## PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS,
-## AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
-## SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+# THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+# PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS,
+# AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
+# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
"""
Write values in tracker and check the actual values are written
@@ -29,11 +29,12 @@ import sys
from functools import wraps
import common.utils.configuration as cfg
+
def expectedFailureJournal():
"""
Decorator to handle tests that are expected to fail when journal is disabled.
"""
- def decorator (func):
+ def decorator(func):
# no wrapping if journal is enabled, test is expected to pass
if not cfg.disableJournal:
return func
@@ -44,6 +45,7 @@ def expectedFailureJournal():
func(*args, **kwargs)
except Exception:
raise ut.case._ExpectedFailure(sys.exc_info())
- raise Exception ("Unexpected success. This should fail because journal is disabled")
+ raise Exception(
+ "Unexpected success. This should fail because journal is disabled")
return wrapper
return decorator
diff --git a/tests/functional-tests/common/utils/helpers.py b/tests/functional-tests/common/utils/helpers.py
index 8e6a3225c..6e5c26c40 100644
--- a/tests/functional-tests/common/utils/helpers.py
+++ b/tests/functional-tests/common/utils/helpers.py
@@ -28,14 +28,17 @@ import re
from common.utils import configuration as cfg
from common.utils import options as options
+
class NoMetadataException (Exception):
pass
REASONABLE_TIMEOUT = 30
-def log (message):
- if options.is_verbose ():
- print (message)
+
+def log(message):
+ if options.is_verbose():
+ print(message)
+
class Helper:
"""
@@ -54,11 +57,11 @@ class Helper:
BUS_NAME = None
PROCESS_NAME = None
- def __init__ (self):
+ def __init__(self):
self.process = None
self.available = False
- self.loop = GLib.MainLoop ()
+ self.loop = GLib.MainLoop()
self.install_glib_excepthook(self.loop)
self.bus = Gio.bus_get_sync(Gio.BusType.SESSION, None)
@@ -68,51 +71,52 @@ class Helper:
Handler to abort test if an exception occurs inside the GLib main loop.
"""
old_hook = sys.excepthook
+
def new_hook(etype, evalue, etb):
old_hook(etype, evalue, etb)
GLib.MainLoop.quit(loop)
sys.exit(1)
sys.excepthook = new_hook
- def _start_process (self, env=None):
+ def _start_process(self, env=None):
path = self.PROCESS_PATH
- flags = getattr (self,
- "FLAGS",
- [])
+ flags = getattr(self,
+ "FLAGS",
+ [])
kws = {}
- if not options.is_verbose ():
- FNULL = open ('/dev/null', 'w')
- kws.update({ 'stdout': FNULL, 'stderr': subprocess.PIPE })
+ if not options.is_verbose():
+ FNULL = open('/dev/null', 'w')
+ kws.update({'stdout': FNULL, 'stderr': subprocess.PIPE})
if env:
kws['env'] = env
command = [path] + flags
- log ("Starting %s" % ' '.join(command))
+ log("Starting %s" % ' '.join(command))
try:
- return subprocess.Popen ([path] + flags, **kws)
+ return subprocess.Popen([path] + flags, **kws)
except OSError as e:
raise RuntimeError("Error starting %s: %s" % (path, e))
def _bus_name_appeared(self, name, owner, data):
- log ("[%s] appeared in the bus as %s" % (self.PROCESS_NAME, owner))
+ log("[%s] appeared in the bus as %s" % (self.PROCESS_NAME, owner))
self.available = True
self.loop.quit()
def _bus_name_vanished(self, name, data):
- log ("[%s] disappeared from the bus" % self.PROCESS_NAME)
+ log("[%s] disappeared from the bus" % self.PROCESS_NAME)
self.available = False
self.loop.quit()
- def _process_watch_cb (self):
+ def _process_watch_cb(self):
if self.process_watch_timeout == 0:
# The GLib seems to call the timeout after we've removed it
# sometimes, which causes errors unless we detect it.
return False
- status = self.process.poll ()
+ status = self.process.poll()
if status is None:
return True # continue
@@ -124,15 +128,16 @@ class Helper:
error = ""
else:
error = self.process.stderr.read()
- raise RuntimeError("%s exited with status: %i\n%s" % (self.PROCESS_NAME, status, error))
+ raise RuntimeError("%s exited with status: %i\n%s" %
+ (self.PROCESS_NAME, status, error))
- def _timeout_on_idle_cb (self):
- log ("[%s] Timeout waiting... asumming idle." % self.PROCESS_NAME)
- self.loop.quit ()
+ def _timeout_on_idle_cb(self):
+ log("[%s] Timeout waiting... asumming idle." % self.PROCESS_NAME)
+ self.loop.quit()
self.timeout_id = None
return False
- def start (self, env=None):
+ def start(self, env=None):
"""
Start an instance of process and wait for it to appear on the bus.
"""
@@ -146,25 +151,27 @@ class Helper:
self.loop.run()
if options.is_manual_start():
- print ("Start %s manually" % self.PROCESS_NAME)
+ print("Start %s manually" % self.PROCESS_NAME)
else:
if self.available:
# It's running, but we didn't start it...
- raise Exception ("Unable to start test instance of %s: "
- "already running " % self.PROCESS_NAME)
+ raise Exception("Unable to start test instance of %s: "
+ "already running " % self.PROCESS_NAME)
- self.process = self._start_process (env=env)
- log ('[%s] Started process %i' % (self.PROCESS_NAME, self.process.pid))
- self.process_watch_timeout = GLib.timeout_add (200, self._process_watch_cb)
+ self.process = self._start_process(env=env)
+ log('[%s] Started process %i' %
+ (self.PROCESS_NAME, self.process.pid))
+ self.process_watch_timeout = GLib.timeout_add(
+ 200, self._process_watch_cb)
self.abort_if_process_exits_with_status_0 = True
# Run the loop until the bus name appears, or the process dies.
- self.loop.run ()
+ self.loop.run()
self.abort_if_process_exits_with_status_0 = False
- def stop (self):
+ def stop(self):
if self.process is None:
# Seems that it didn't even start...
return
@@ -180,36 +187,37 @@ class Helper:
time.sleep(0.1)
if time.time() > (start + REASONABLE_TIMEOUT):
- log ("[%s] Failed to terminate, sending kill!" % self.PROCESS_NAME)
+ log("[%s] Failed to terminate, sending kill!" %
+ self.PROCESS_NAME)
self.process.kill()
self.process.wait()
- log ("[%s] stopped." % self.PROCESS_NAME)
+ log("[%s] stopped." % self.PROCESS_NAME)
# Run the loop until the bus name appears, or the process dies.
- self.loop.run ()
+ self.loop.run()
Gio.bus_unwatch_name(self._bus_name_watch_id)
self.process = None
- def kill (self):
+ def kill(self):
if options.is_manual_start():
- log ("kill(): ignoring, because process was started manually.")
+ log("kill(): ignoring, because process was started manually.")
return
if self.process_watch_timeout != 0:
GLib.source_remove(self.process_watch_timeout)
self.process_watch_timeout = 0
- self.process.kill ()
+ self.process.kill()
# Name owner changed callback should take us out from this loop
- self.loop.run ()
+ self.loop.run()
Gio.bus_unwatch_name(self._bus_name_watch_id)
self.process = None
- log ("[%s] killed." % self.PROCESS_NAME)
+ log("[%s] killed." % self.PROCESS_NAME)
class StoreHelper (Helper):
@@ -224,8 +232,8 @@ class StoreHelper (Helper):
PROCESS_PATH = cfg.TRACKER_STORE_PATH
BUS_NAME = cfg.TRACKER_BUSNAME
- def start (self, env=None):
- Helper.start (self, env=env)
+ def start(self, env=None):
+ Helper.start(self, env=env)
self.resources = Gio.DBusProxy.new_sync(
self.bus, Gio.DBusProxyFlags.DO_NOT_AUTO_START, None,
@@ -243,50 +251,50 @@ class StoreHelper (Helper):
self.bus, Gio.DBusProxyFlags.DO_NOT_AUTO_START, None,
cfg.TRACKER_BUSNAME, cfg.TRACKER_STATUS_OBJ_PATH, cfg.STATUS_IFACE)
- log ("[%s] booting..." % self.PROCESS_NAME)
- self.status_iface.Wait ()
- log ("[%s] ready." % self.PROCESS_NAME)
+ log("[%s] booting..." % self.PROCESS_NAME)
+ self.status_iface.Wait()
+ log("[%s] ready." % self.PROCESS_NAME)
- def stop (self):
- Helper.stop (self)
+ def stop(self):
+ Helper.stop(self)
- def query (self, query, timeout=5000, **kwargs):
- return self.resources.SparqlQuery ('(s)', query, timeout=timeout, **kwargs)
+ def query(self, query, timeout=5000, **kwargs):
+ return self.resources.SparqlQuery('(s)', query, timeout=timeout, **kwargs)
- def update (self, update_sparql, timeout=5000, **kwargs):
- return self.resources.SparqlUpdate ('(s)', update_sparql, timeout=timeout, **kwargs)
+ def update(self, update_sparql, timeout=5000, **kwargs):
+ return self.resources.SparqlUpdate('(s)', update_sparql, timeout=timeout, **kwargs)
- def load (self, ttl_uri, timeout=5000, **kwargs):
- return self.resources.Load ('(s)', ttl_uri, timeout=timeout, **kwargs)
+ def load(self, ttl_uri, timeout=5000, **kwargs):
+ return self.resources.Load('(s)', ttl_uri, timeout=timeout, **kwargs)
- def batch_update (self, update_sparql, **kwargs):
- return self.resources.BatchSparqlUpdate ('(s)', update_sparql, **kwargs)
+ def batch_update(self, update_sparql, **kwargs):
+ return self.resources.BatchSparqlUpdate('(s)', update_sparql, **kwargs)
- def batch_commit (self, **kwargs):
- return self.resources.BatchCommit (**kwargs)
+ def batch_commit(self, **kwargs):
+ return self.resources.BatchCommit(**kwargs)
- def backup (self, backup_file, **kwargs):
- return self.backup_iface.Save ('(s)', backup_file, **kwargs)
+ def backup(self, backup_file, **kwargs):
+ return self.backup_iface.Save('(s)', backup_file, **kwargs)
- def restore (self, backup_file, **kwargs):
- return self.backup_iface.Restore ('(s)', backup_file, **kwargs)
+ def restore(self, backup_file, **kwargs):
+ return self.backup_iface.Restore('(s)', backup_file, **kwargs)
- def get_stats (self, **kwargs):
+ def get_stats(self, **kwargs):
return self.stats_iface.Get(**kwargs)
- def get_tracker_iface (self):
+ def get_tracker_iface(self):
return self.resources
- def count_instances (self, ontology_class):
+ def count_instances(self, ontology_class):
QUERY = """
SELECT COUNT(?u) WHERE {
?u a %s .
}
"""
- result = self.resources.SparqlQuery ('(s)', QUERY % (ontology_class))
+ result = self.resources.SparqlQuery('(s)', QUERY % (ontology_class))
- if (len (result) == 1):
- return int (result [0][0])
+ if (len(result) == 1):
+ return int(result[0][0])
else:
return -1
@@ -297,11 +305,11 @@ class StoreHelper (Helper):
result = self.query(
'SELECT tracker:id(%s) WHERE { }' % uri)
if len(result) == 1:
- return int (result [0][0])
+ return int(result[0][0])
elif len(result) == 0:
- raise Exception ("No entry for resource %s" % uri)
+ raise Exception("No entry for resource %s" % uri)
else:
- raise Exception ("Multiple entries for resource %s" % uri)
+ raise Exception("Multiple entries for resource %s" % uri)
# FIXME: rename to get_resource_id_by_nepomuk_url !!
def get_resource_id(self, url):
@@ -311,19 +319,19 @@ class StoreHelper (Helper):
result = self.query(
'SELECT tracker:id(?r) WHERE { ?r nie:url "%s" }' % url)
if len(result) == 1:
- return int (result [0][0])
+ return int(result[0][0])
elif len(result) == 0:
- raise Exception ("No entry for resource %s" % url)
+ raise Exception("No entry for resource %s" % url)
else:
- raise Exception ("Multiple entries for resource %s" % url)
+ raise Exception("Multiple entries for resource %s" % url)
- def ask (self, ask_query):
- assert ask_query.strip ().startswith ("ASK")
- result = self.query (ask_query)
- assert len (result) == 1
+ def ask(self, ask_query):
+ assert ask_query.strip().startswith("ASK")
+ result = self.query(ask_query)
+ assert len(result) == 1
if result[0][0] == "true":
return True
elif result[0][0] == "false":
return False
else:
- raise Exception ("Something fishy is going on")
+ raise Exception("Something fishy is going on")
diff --git a/tests/functional-tests/common/utils/options.py b/tests/functional-tests/common/utils/options.py
index 1b46cad94..d11d5a12f 100644
--- a/tests/functional-tests/common/utils/options.py
+++ b/tests/functional-tests/common/utils/options.py
@@ -1,5 +1,6 @@
import os
+
def get_environment_boolean(variable):
'''Parse a yes/no boolean passed through the environment.'''
@@ -12,12 +13,14 @@ def get_environment_boolean(variable):
raise RuntimeError('Unexpected value for %s: %s' %
(variable, value))
+
def is_verbose():
"""
True to log process status information to stdout
"""
return get_environment_boolean('TRACKER_TESTS_VERBOSE')
+
def is_manual_start():
"""
False to start the processes automatically
diff --git a/tests/functional-tests/common/utils/storetest.py
b/tests/functional-tests/common/utils/storetest.py
index febd49529..dad9a0ac6 100644
--- a/tests/functional-tests/common/utils/storetest.py
+++ b/tests/functional-tests/common/utils/storetest.py
@@ -29,17 +29,17 @@ from common.utils import configuration as cfg
class CommonTrackerStoreTest (ut.TestCase):
- """
- Common superclass for tests that just require a fresh store running
- """
- @classmethod
- def setUpClass (self):
- env = os.environ
- env['LC_COLLATE'] = 'en_GB.utf8'
+ """
+ Common superclass for tests that just require a fresh store running
+ """
+ @classmethod
+ def setUpClass(self):
+ env = os.environ
+ env['LC_COLLATE'] = 'en_GB.utf8'
- self.tracker = StoreHelper()
- self.tracker.start(env=env)
+ self.tracker = StoreHelper()
+ self.tracker.start(env=env)
- @classmethod
- def tearDownClass (self):
- self.tracker.stop()
+ @classmethod
+ def tearDownClass(self):
+ self.tracker.stop()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]