From 10935dd865a498a8f48031aafbe2b12c8b86830c Mon Sep 17 00:00:00 2001 From: William Waites Date: Thu, 19 Jan 2017 12:52:40 +0000 Subject: [PATCH] correctly return the length of rdf:List for #223 --- rdflib/collection.py | 7 +------ test/test_issue223.py | 7 ++++--- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/rdflib/collection.py b/rdflib/collection.py index 3983c1758..4fc3d1c87 100644 --- a/rdflib/collection.py +++ b/rdflib/collection.py @@ -82,12 +82,7 @@ def _get_container(self, index): def __len__(self): """length of items in collection.""" - count = 0 - links = set() - for item in self.graph.items(self.uri): - links.add(item) - count += 1 - return count + return len(list(self.graph.items(self.uri))) def index(self, item): """ diff --git a/test/test_issue223.py b/test/test_issue223.py index 8a05da88a..5b1761ea4 100644 --- a/test/test_issue223.py +++ b/test/test_issue223.py @@ -11,8 +11,9 @@ def test_collection_with_duplicates(): g = Graph().parse(data=ttl, format="turtle") for _,_,o in g.triples((URIRef("http://example.org/s"), URIRef("http://example.org/p"), None)): break - c = list(Collection(g, o)) - assert c == list(URIRef("http://example.org/" + x) for x in ["a", "b", "a"]) - + c = Collection(g, o) + assert list(c) == list(URIRef("http://example.org/" + x) for x in ["a", "b", "a"]) + assert len(c) == 3 + if __name__ == '__main__': test_collection_with_duplicates()