-
Notifications
You must be signed in to change notification settings - Fork 542
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert some more graph tests to pytest
This patch converts some additional graph tests to pytest, I'm doing this in preperation for adding more tests to `test_diff.py`.
- Loading branch information
Showing
4 changed files
with
105 additions
and
117 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
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 |
---|---|---|
@@ -1,88 +1,81 @@ | ||
import unittest | ||
|
||
from rdflib import Graph | ||
from rdflib.container import Alt, Bag, Seq | ||
from rdflib.term import BNode, Literal | ||
|
||
|
||
class TestContainer(unittest.TestCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
cls.g = Graph() | ||
cls.c1 = Bag(cls.g, BNode()) | ||
cls.c2 = Bag( | ||
cls.g, BNode(), [Literal("1"), Literal("2"), Literal("3"), Literal("4")] | ||
) | ||
cls.c3 = Alt( | ||
cls.g, BNode(), [Literal("1"), Literal("2"), Literal("3"), Literal("4")] | ||
) | ||
cls.c4 = Seq( | ||
cls.g, BNode(), [Literal("1"), Literal("2"), Literal("3"), Literal("4")] | ||
) | ||
|
||
def testA(self): | ||
self.assertEqual(len(self.c1) == 0, True) | ||
|
||
def testB(self): | ||
self.assertEqual(len(self.c2) == 4, True) | ||
|
||
def testC(self): | ||
self.c2.append(Literal("5")) | ||
del self.c2[2] | ||
self.assertEqual(len(self.c2) == 4, True) | ||
|
||
def testD(self): | ||
self.assertEqual(self.c2.index(Literal("5")) == 4, True) | ||
|
||
def testE(self): | ||
self.assertEqual(self.c2[2] == Literal("3"), True) | ||
|
||
def testF(self): | ||
self.c2[2] = Literal("9") | ||
self.assertEqual(self.c2[2] == Literal("9"), True) | ||
|
||
def testG(self): | ||
self.c2.clear() | ||
self.assertEqual(len(self.c2) == 0, True) | ||
|
||
def testH(self): | ||
self.c2.append_multiple([Literal("80"), Literal("90")]) | ||
self.assertEqual(self.c2[1] == Literal("80"), True) | ||
|
||
def testI(self): | ||
self.assertEqual(self.c2[2] == Literal("90"), True) | ||
|
||
def testJ(self): | ||
self.assertEqual(len(self.c2) == 2, True) | ||
|
||
def testK(self): | ||
self.assertEqual(self.c2.end() == 2, True) | ||
|
||
def testL(self): | ||
self.assertEqual( | ||
self.c3.anyone() | ||
in [Literal("1"), Literal("2"), Literal("3"), Literal("4")], | ||
True, | ||
) | ||
|
||
def testM(self): | ||
self.c4.add_at_position(3, Literal("60")) | ||
self.assertEqual(len(self.c4) == 5, True) | ||
|
||
def testN(self): | ||
self.assertEqual(self.c4.index(Literal("60")) == 3, True) | ||
|
||
def testO(self): | ||
self.assertEqual(self.c4.index(Literal("3")) == 4, True) | ||
|
||
def testP(self): | ||
self.assertEqual(self.c4.index(Literal("4")) == 5, True) | ||
|
||
def testQ(self): | ||
self.assertEqual( | ||
self.c2.index(Literal("1000")) == 3, False | ||
) # there is no Literal("1000") in the Bag | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() | ||
from rdflib import Graph | ||
from rdflib.container import Alt, Bag, Seq | ||
from rdflib.term import BNode, Literal | ||
|
||
|
||
class TestContainer: | ||
@classmethod | ||
def setup_class(cls): | ||
cls.g = Graph() | ||
cls.c1 = Bag(cls.g, BNode()) | ||
cls.c2 = Bag( | ||
cls.g, BNode(), [Literal("1"), Literal("2"), Literal("3"), Literal("4")] | ||
) | ||
cls.c3 = Alt( | ||
cls.g, BNode(), [Literal("1"), Literal("2"), Literal("3"), Literal("4")] | ||
) | ||
cls.c4 = Seq( | ||
cls.g, BNode(), [Literal("1"), Literal("2"), Literal("3"), Literal("4")] | ||
) | ||
|
||
def testA(self): | ||
assert len(self.c1) == 0 | ||
|
||
def testB(self): | ||
assert len(self.c2) == 4 | ||
|
||
def testC(self): | ||
self.c2.append(Literal("5")) | ||
del self.c2[2] | ||
assert len(self.c2) == 4 | ||
|
||
def testD(self): | ||
assert self.c2.index(Literal("5")) == 4 | ||
|
||
def testE(self): | ||
assert self.c2[2] == Literal("3") | ||
|
||
def testF(self): | ||
self.c2[2] = Literal("9") | ||
assert self.c2[2] == Literal("9") | ||
|
||
def testG(self): | ||
self.c2.clear() | ||
assert len(self.c2) == 0 | ||
|
||
def testH(self): | ||
self.c2.append_multiple([Literal("80"), Literal("90")]) | ||
assert self.c2[1] == Literal("80") | ||
|
||
def testI(self): | ||
assert self.c2[2] == Literal("90") | ||
|
||
def testJ(self): | ||
assert len(self.c2) == 2 | ||
|
||
def testK(self): | ||
assert self.c2.end() == 2 | ||
|
||
def testL(self): | ||
assert self.c3.anyone() in [ | ||
Literal("1"), | ||
Literal("2"), | ||
Literal("3"), | ||
Literal("4"), | ||
] | ||
|
||
def testM(self): | ||
self.c4.add_at_position(3, Literal("60")) | ||
assert len(self.c4) == 5 | ||
|
||
def testN(self): | ||
assert self.c4.index(Literal("60")) == 3 | ||
|
||
def testO(self): | ||
assert self.c4.index(Literal("3")) == 4 | ||
|
||
def testP(self): | ||
assert self.c4.index(Literal("4")) == 5 | ||
|
||
def testQ(self): | ||
assert self.c2.index(Literal("1000")) != 3 |
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