-
Notifications
You must be signed in to change notification settings - Fork 565
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds cbd() function to Graph() and tests and dependency on black
- Loading branch information
Nicholas Car
committed
Mar 13, 2020
1 parent
0e5efef
commit a7863d2
Showing
3 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ pyparsing | |
requests | ||
six | ||
doctest-ignore-unicode | ||
black |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import unittest | ||
from rdflib import Graph, Namespace | ||
|
||
|
||
class CbdTestCase(unittest.TestCase): | ||
"""Tests the Graph class' cbd() function""" | ||
|
||
def setUp(self): | ||
self.g = Graph() | ||
# adding example data for testing | ||
self.g.parse( | ||
data="""PREFIX ex: <http://ex/> | ||
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> | ||
ex:R1 | ||
a rdf:Resource ; | ||
ex:hasChild ex:R2 , ex:R3 . | ||
ex:R2 | ||
ex:propOne ex:P1 ; | ||
ex:propTwo ex:P2 . | ||
ex:R3 | ||
ex:propOne ex:P3 ; | ||
ex:propTwo ex:P4 ; | ||
ex:propThree [ | ||
a rdf:Resource ; | ||
ex:propFour "Some Literal" ; | ||
ex:propFive ex:P5 ; | ||
ex:propSix [ | ||
ex:propSeven ex:P7 ; | ||
] ; | ||
] . | ||
""", | ||
format="turtle", | ||
) | ||
|
||
self.EX = Namespace("http://ex/") | ||
self.g.bind("ex", self.EX) | ||
|
||
def testCbd(self): | ||
self.assertEqual( | ||
len(self.g.cbd(self.EX.R1)), 3, "cbd() for R1 should return 3 triples" | ||
) | ||
|
||
self.assertEqual( | ||
len(self.g.cbd(self.EX.R2)), 2, "cbd() for R3 should return 2 triples" | ||
) | ||
|
||
self.assertEqual( | ||
len(self.g.cbd(self.EX.R3)), 8, "cbd() for R3 should return 8 triples" | ||
) | ||
|
||
self.assertEqual( | ||
len(self.g.cbd(self.EX.R4)), 0, "cbd() for R4 should return 0 triples" | ||
) | ||
|
||
def tearDown(self): | ||
self.g.close() | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |