[Python-modules-commits] [python-pyld] 67/276: Pass compaction tests.

Wolfgang Borgert debacle at moszumanska.debian.org
Wed Oct 8 23:47:54 UTC 2014


This is an automated email from the git hooks/post-receive script.

debacle pushed a commit to branch master
in repository python-pyld.

commit ecf779dbc564165ba3ac6cbdc1952d713aa3bb28
Author: Dave Longley <dlongley at digitalbazaar.com>
Date:   Fri Apr 27 01:28:19 2012 -0400

    Pass compaction tests.
---
 lib/pyld/jsonld.py | 17 +++++++++--------
 tests/runtests.py  |  6 ++++--
 2 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/lib/pyld/jsonld.py b/lib/pyld/jsonld.py
index b31dd74..23d5b45 100644
--- a/lib/pyld/jsonld.py
+++ b/lib/pyld/jsonld.py
@@ -224,7 +224,7 @@ class JsonLdProcessor:
                 graph = compacted
                 compacted = {}
                 compacted['@context'] = ctx
-                for k, v in graph:
+                for k, v in graph.items():
                     compacted[k] = v
 
         if options['activeCtx']:
@@ -717,7 +717,7 @@ class JsonLdProcessor:
 
             # recursively process element keys
             rval = {}
-            for key, value in element:
+            for key, value in element.items():
                 # compact @id and @type(s)
                 if key == '@id' or key == '@type':
                     # compact single @id
@@ -741,7 +741,7 @@ class JsonLdProcessor:
                 # preserve empty arrays
                 if len(value) == 0:
                     prop = self._compactIri(ctx, key)
-                    JsonLdProcessor.addValue(rval, prop, array(), True)
+                    JsonLdProcessor.addValue(rval, prop, [], True)
 
                 # recusively process array values
                 for v in value:
@@ -1982,6 +1982,7 @@ class JsonLdProcessor:
         if _is_keyword(iri):
             # return alias if available
             aliases = ctx['keywords'][iri]
+            print 'aliases: %s' % aliases
             if len(aliases) > 0:
               return aliases[0]
             else:
@@ -1993,7 +1994,7 @@ class JsonLdProcessor:
         highest = 0
         list_container = False
         is_list = _is_list(value)
-        for term, entry in ctx['mappings']:
+        for term, entry in ctx['mappings'].items():
             has_container = '@container' in entry
 
             # skip terms with non-matching iris
@@ -2033,7 +2034,7 @@ class JsonLdProcessor:
 
         # no term matches, add possible CURIEs
         if len(terms) == 0:
-            for term, entry in ctx['mappings']:
+            for term, entry in ctx['mappings'].items():
                 # skip terms with colons, they can't be prefixes
                 if term.find(':') != -1:
                     continue
@@ -2051,7 +2052,7 @@ class JsonLdProcessor:
             return iri
 
         # return shortest and lexicographically-least term
-        sort(terms, key=cmp_to_key(_compare_shortest_least))
+        terms.sort(key=cmp_to_key(_compare_shortest_least))
         return terms[0]
 
     def _defineContextMapping(self, active_ctx, ctx, key, base, defined):
@@ -2131,9 +2132,9 @@ class JsonLdProcessor:
 
                 # uniquely add key as a keyword alias and resort
                 aliases = active_ctx['keywords'][value]
-                if key in aliases:
+                if key not in aliases:
                     aliases.append(key)
-                    sort(aliases, key=cmp_to_key(_compare_shortest_least))
+                    aliases.sort(key=cmp_to_key(_compare_shortest_least))
             else:
                 # expand value to a full IRI
                 value = self._expandContextIri(
diff --git a/tests/runtests.py b/tests/runtests.py
index f5a4080..3816de2 100644
--- a/tests/runtests.py
+++ b/tests/runtests.py
@@ -22,8 +22,8 @@ from pyld import jsonld
 # supported test types
 TEST_TYPES = [
     'jld:ExpandTest',
-    'jld:NormalizeTest']#,
-    #'jld:CompactTest',
+    'jld:NormalizeTest',
+    'jld:CompactTest']#,
     #'jld:FrameTest']
 
 # FIXME: remove me
@@ -192,6 +192,8 @@ def deep_compare(expect, result):
         if len(expect) != len(result):
             return False
         for k, v in expect.items():
+            if k not in result:
+                return False
             if not deep_compare(v, result[k]):
                 return False
         return True

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-pyld.git



More information about the Python-modules-commits mailing list