Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.

Commit 6806c93

Browse files
committed
Adds tests for python context
Signed-off-by: ncordon <[email protected]>
1 parent 6607959 commit 6806c93

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

bblfsh/test.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import typing as t
33
import unittest
44
import gc
5-
5+
import bblfsh
66
import docker
77

88
from bblfsh import (BblfshClient, iterator, TreeOrder,
@@ -14,6 +14,7 @@
1414
from bblfsh.pyuast import uast, decode
1515
from functools import cmp_to_key
1616

17+
1718
class BblfshTests(unittest.TestCase):
1819
BBLFSH_SERVER_EXISTED = None
1920
fixtures_pyfile = "fixtures/test.py"
@@ -532,6 +533,33 @@ def testFilterOrphanNode(self) -> None:
532533
typ = obj["@type"]
533534
self.assertEqual("uast:RuntimeImport", typ)
534535

536+
def testPythonContextIterate(self) -> None:
537+
# C++ memory context
538+
ctxC = self._parse_fixture()
539+
# Python memory context
540+
pyDict = ctxC.root.get()
541+
ctxPy = bblfsh.context(pyDict)
542+
543+
for treeOrder in TreeOrder:
544+
itC = ctxC.iterate(treeOrder)
545+
itPy = ctxPy.iterate(treeOrder)
546+
547+
for nodeC, nodePy in zip(itC, itPy):
548+
self.assertEqual(nodeC.get(), nodePy)
549+
550+
def testPythonContextFilter(self) -> None:
551+
# C++ memory context
552+
ctxC = self._parse_fixture()
553+
# Python memory context
554+
pyDict = ctxC.root.get()
555+
ctxPy = bblfsh.context(pyDict)
556+
557+
itC = ctxC.filter("//*[@role='Identifier']")
558+
itPy = ctxPy.filter("//*[@role='Identifier']")
559+
560+
for nodeC, nodePy in zip(itC, itPy):
561+
self.assertEqual(nodeC.get(), nodePy)
562+
535563

536564
if __name__ == "__main__":
537565
unittest.main()

0 commit comments

Comments
 (0)