[tracker] functional-tests: Update test to use SLO (instead of MLO)
- From: Ivan Frade <ifrade src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker] functional-tests: Update test to use SLO (instead of MLO)
- Date: Fri, 4 Feb 2011 16:36:22 +0000 (UTC)
commit 0185746d919ae6998c51c474097831db7f6fce6d
Author: Ivan Frade <ivan frade nokia com>
Date: Fri Feb 4 18:33:49 2011 +0200
functional-tests: Update test to use SLO (instead of MLO)
Added infrastructure to expect @URNUUID@ as value of a property
and to expect a property without a concrete value
tests/functional-tests/400-extractor.py | 57 ++++++++++++++++----
tests/functional-tests/common/utils/helpers.py | 33 ++++++------
tests/functional-tests/test-extraction-data/README | 21 ++++++--
.../images/test-image-1.expected | 3 +-
4 files changed, 79 insertions(+), 35 deletions(-)
---
diff --git a/tests/functional-tests/400-extractor.py b/tests/functional-tests/400-extractor.py
index 6e3f6d1..f2babe5 100755
--- a/tests/functional-tests/400-extractor.py
+++ b/tests/functional-tests/400-extractor.py
@@ -129,6 +129,15 @@ class ExtractionTestCase (ut.TestCase):
self.fail (self._formatMessage (msg, standardMsg))
else:
return
+
+ def assertIsURN (self, supposed_uuid, msg=None):
+ import uuid
+
+ try:
+ uuid.UUID (supposed_uuid)
+ except ValueError:
+ standardMsg = "'%s' is not a valid UUID" % (supposed_uuid)
+ self.fail (self._formatMessage (msg, standardMsg))
def __assert_extraction_ok (self, result):
self.__check_section ("Metadata", result)
@@ -143,12 +152,18 @@ class ExtractionTestCase (ut.TestCase):
error_extra_prop = "Property '%s' was explicitely banned for file \n'%s'\n (requested on '%s' [%s])"
error_extra_prop_v = "Property '%s' with value '%s' was explicitely banned for file \n'%s'\n (requested on %s' [%s])"
- expected_pairs = [ (k.replace ("_", ":"), v)
- for (k,v) in self.configParser.items (section)
- if not k.startswith ("!")]
- unexpected_pairs = [ (k[1:].replace ("_", ":"), v)
- for (k,v) in self.configParser.items (section)
- if k.startswith ("!")]
+ expected_pairs = [] # List of expected (key, value)
+ unexpected_pairs = [] # List of unexpected (key, value)
+ expected_keys = [] # List of expected keys (the key must be there, value doesnt matter)
+
+ for k, v in self.configParser.items (section):
+ if k.startswith ("!"):
+ unexpected_pairs.append ( (k[1:].replace ("_", ":"), v) )
+ elif k.startswith ("@"):
+ expected_keys.append ( k[1:].replace ("_", ":") )
+ else:
+ expected_pairs.append ( (k.replace ("_", ":"), v) )
+
for (prop, value) in expected_pairs:
self.assertDictHasKey (result, prop,
@@ -156,11 +171,19 @@ class ExtractionTestCase (ut.TestCase):
self.file_to_extract,
self.rel_description,
section))
- self.assertIn (value, result [prop],
- error_wrong_value % (prop,
- self.file_to_extract,
- self.rel_description,
- section))
+ if value == "@URNUUID@":
+ # Watch out! We take only the FIRST element. Incompatible with multiple-valued props.
+ self.assertIsURN (result [prop][0],
+ error_wrong_value % (prop,
+ self.file_to_extract,
+ self.rel_description,
+ section))
+ else:
+ self.assertIn (value, result [prop],
+ error_wrong_value % (prop,
+ self.file_to_extract,
+ self.rel_description,
+ section))
for (prop, value) in unexpected_pairs:
# There is no prop, or it is but not with that value
@@ -169,6 +192,11 @@ class ExtractionTestCase (ut.TestCase):
self.file_to_extract,
self.rel_description,
section))
+ if (value == "@URNUUID@"):
+ self.assertIsURN (result [prop][0], error_extra_prop % (prop,
+ self.file_to_extract,
+ self.rel_description,
+ section))
else:
self.assertNotIn (value, result [prop], error_extra_prop_v % (prop,
value,
@@ -176,6 +204,13 @@ class ExtractionTestCase (ut.TestCase):
self.rel_description,
section))
+ for prop in expected_keys:
+ self.assertDictHasKey (result, prop,
+ error_missing_prop % (prop,
+ self.file_to_extract,
+ self.rel_description,
+ section))
+
if __name__ == "__main__":
##
diff --git a/tests/functional-tests/common/utils/helpers.py b/tests/functional-tests/common/utils/helpers.py
index 0e69c62..96674f8 100644
--- a/tests/functional-tests/common/utils/helpers.py
+++ b/tests/functional-tests/common/utils/helpers.py
@@ -190,6 +190,14 @@ class ExtractorHelper ():
def __process_lines (self, embedded):
"""
+ Translate each line in a "prop value" string, handling anonymous nodes.
+
+ Example:
+ nfo:width 699 ; -> 'nfo:width 699'
+ or
+ nao:hasTag [ a nao:Tag ;
+ nao:prefLabel "tracker"] ; -> nao:hasTag:prefLabel 'tracker'
+
Would be so cool to implement this with yield and generators... :)
"""
grouped_lines = []
@@ -248,9 +256,8 @@ class ExtractorHelper ():
nao:hasTag [a nao:Tag; nao:prefLabel "xxx"]
-> nao:hasTag:prefLabel "xxx"
- mlo:location [a mlo:GeoPoint; mlo:city "Delhi"; mlo:country "India"]
- -> mlo:location:city "Delhi"
- -> mlo:location:country "India"
+ slo:location [a slo:GeoPoint; slo:postalAddress <urn:uuid:1231-123> .]
+ -> slo:location <urn:uuid:1231-123>
nfo:hasMediaFileListEntry [ a nfo:MediaFileListEntry ; nfo:entryUrl "file://x.mp3"; nfo:listPosition 1]
-> nfo:hasMediaFileListEntry:entryUrl "file://x.mp3"
@@ -269,24 +276,16 @@ class ExtractorHelper ():
return [line]
# location case
- elif line.startswith ("mlo:location"):
-
+ elif line.startswith ("slo:location"):
results = []
# Can have country AND/OR city
- getcountry = re.compile ("mlo:country\ \"(\w+)\"")
- getcity = re.compile ("mlo:city\ \"(\w+)\"")
+ getpa = re.compile ("slo:postalAddress\ \<([\w:-]+)\>")
+ pa_match = getpa.search (line)
- country_match = getcountry.search (line)
- city_match = getcity.search (line)
-
- if (country_match):
- results.append ('mlo:location:country "%s" ;' % (country_match.group(1)))
-
- if (city_match):
- results.append ('mlo:location:city "%s" ;' % (city_match.group(1)))
-
- if (not country_match and not city_match):
+ if (pa_match):
+ results.append ('slo:location:postalAddress "%s" ;' % (pa_match.group(1)))
+ else:
print "FIXME another location subproperty in ", line
return results
diff --git a/tests/functional-tests/test-extraction-data/README b/tests/functional-tests/test-extraction-data/README
index 149c0f9..ae8d3dc 100644
--- a/tests/functional-tests/test-extraction-data/README
+++ b/tests/functional-tests/test-extraction-data/README
@@ -23,7 +23,14 @@ The Metadata section contains pairs of property=values with few special rules:
E.G. nfo:duration=5 -> nfo_duration=5
but a=nmm:Video -> a=nmm:Video
-2. If the property name is prefixed with '!' then the property is NOT expected in the extraction
+2. If the property name is prefixed with '@' then the property is expected in the extraction, but the value
+ won't be checked.
+
+ E.G. The extraction is: slo:location [a slo:GeoPoint; slo:postalAddress <urn:uuid:123-123>];
+
+ @slo_location= -> PASS slo:location is in the extraction
+
+3. If the property name is prefixed with '!' then the property is NOT expected in the extraction
If the negated property has a value, it forbids the exact value. Otherwise, it forbids the property at all.
E.G. The extraction is: a nmm:Video; nfo:duration 50.
@@ -32,12 +39,16 @@ The Metadata section contains pairs of property=values with few special rules:
!nfo_duration=12 -> PASS because duration has a different value
!nfo_duration= -> FAIL because there shouldn't be any nfo:duration at all
-3. The translation of the extraction results to a python dictionary is very basic.
+4. The translation of the extraction results to a python dictionary is very basic.
It handles a couple of special cases, relevant for testing:
+ E.G.
+
+ nao:hasTag [a nao:Tag; nao:prefLabel "XXX"] -> nao_hasTag_prefLabel=XXX
+
+5. There is (so far only) one constant defined to use in the values:
- mlo:location [a mlo:GeoPoint; mlo:city "XXX"] -> mlo_location_city=XXX
- mlo:location [a mlo:GeoPoint; mlo:country "XXX"] -> mlo_location_country=XXX
- nao:hasTag [a nao:Tag; nao:prefLabel "XXX"] -> nao_hasTag_prefLabel=XXX
+ @URNUUID@ meaning an automatic generated urn:uuid:1231-123-123 URL
+ [This constant must not be used with multiple-valued properties. The code only check the first result.]
Example
======
diff --git a/tests/functional-tests/test-extraction-data/images/test-image-1.expected b/tests/functional-tests/test-extraction-data/images/test-image-1.expected
index ce3f682..03b142d 100644
--- a/tests/functional-tests/test-extraction-data/images/test-image-1.expected
+++ b/tests/functional-tests/test-extraction-data/images/test-image-1.expected
@@ -13,8 +13,7 @@ nie_title=Kid
nmm_fnumber=5
nmm_focalLength=5
nie_comment=This is a for tracker test
-mlo_location_city=Tig
-mlo_location_country=Banglore
+slo_location_postalAddress= URNUUID@
nfo_horizontalResolution=20
nfo_verticalResolution=20
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]