@@ -407,15 +407,22 @@ def testSupportedLanguages(self) -> None:
407407
408408 def testEncode (self ) -> None :
409409 ctx = self ._parse_fixture ()
410+ # This test is here for backward compatibility purposes,
411+ # in case someone was relying on encoding contexts this way
410412 self .assertEqual (ctx .ctx .encode (None , 0 ), ctx ._response .uast )
413+ self .assertEqual (ctx .encode (), ctx ._response .uast )
411414
412415 def testEncodeWithEmptyContext (self ) -> None :
413416 ctx = ResultContext ()
414417 obj = {"k1" : "v1" , "k2" : "v2" }
415418 fmt = 1 # YAML
416419
420+ # This test is here for backward compatibility purposes,
421+ # in case someone was relying on encoding contexts this way
417422 data = ctx .ctx .encode (obj , fmt )
418- self .assertDictEqual (obj , decode (data , format = fmt ).load ())
423+ other_data = ctx .encode (obj , fmt )
424+ self .assertDictEqual (obj , decode (data , format = fmt ).load ())
425+ self .assertDictEqual (obj , decode (other_data , format = fmt ).load ())
419426
420427 def testGetAll (self ) -> None :
421428 ctx = self ._parse_fixture ()
@@ -560,16 +567,17 @@ def testPythonContextFilter(self) -> None:
560567 for nodeC , nodePy in zip (itC , itPy ):
561568 self .assertEqual (nodeC .get (), nodePy )
562569
563- def testEncodeDecodePythonContext (self ) -> None :
570+ def testBinaryEncodeDecodePythonContext (self ) -> None :
571+ # Binary encoding should be invertible
564572 # C++ memory context
565573 ctxC = self ._parse_fixture ()
566574 # Python memory context
567575 pyDict = ctxC .root .get ()
568576 ctxPy = bblfsh .context (pyDict )
569- encoded = ctxPy .encode (fmt = 1 ) # YAML
570- decoded = decode (encoded , format = 1 )
577+ encoded = ctxPy .encode (fmt = 0 ) # Binary encoding
578+ decoded = decode (encoded , format = 0 )
571579
572- self .assertEqual (encoded , decoded .load ())
580+ self .assertEqual (pyDict , decoded .load ())
573581
574582if __name__ == "__main__" :
575583 unittest .main ()
0 commit comments