@@ -507,7 +507,7 @@ def _write(self, name, content):
507507 f .write (content )
508508
509509 def _run (self , * args ):
510- env = dict (os .environ , PYTHONPATH = self .ROOT )
510+ env = dict (os .environ , PYTHONPATH = self .ROOT , PYTHONUTF8 = '1' )
511511 return subprocess .run ([sys .executable , self .SCRIPT ] + list (args ),
512512 cwd = self .dir , env = env , capture_output = True ,
513513 text = True )
@@ -588,7 +588,7 @@ def test_invalid_json(self):
588588 for content in ('' , '{"a": }' , '{"a": 1}\n {"a": 2}' ):
589589 with self .subTest (content = content ):
590590 self ._write ('invalid.json' , content )
591- proc = self ._run ('/a' , 'invalid.json' )
591+ proc = self ._run ('--continue-on-error' , ' /a' , 'invalid.json' )
592592 self .assertEqual (proc .returncode , 1 )
593593 self .assertEqual (proc .stdout , '' )
594594 self .assertIn ("Could not parse JSON in 'invalid.json':" ,
@@ -602,7 +602,7 @@ def test_invalid_json_in_one_file(self):
602602 with self .subTest (index = index ):
603603 files = ['a.json' , 'b.json' ]
604604 files .insert (index , 'invalid.json' )
605- proc = self ._run ('/a' , * files )
605+ proc = self ._run ('--continue-on-error' , ' /a' , * files )
606606 self .assertEqual (proc .returncode , 1 )
607607 self .assertEqual (proc .stdout , self .A_OUT + self .B_OUT )
608608 self .assertIn ("Could not parse JSON in 'invalid.json':" ,
@@ -611,13 +611,65 @@ def test_invalid_json_in_one_file(self):
611611
612612 def test_invalid_json_and_unresolvable_pointer (self ):
613613 self ._write ('invalid.json' , '{"a": }' )
614- proc = self ._run ('/b' , 'invalid.json' , 'a.json' , 'b.json' )
614+ proc = self ._run ('--continue-on-error' , '/b' ,
615+ 'invalid.json' , 'a.json' , 'b.json' )
615616 self .assertEqual (proc .returncode , 1 )
616617 self .assertEqual (proc .stdout , '1\n ' )
617618 self .assertIn ("Could not parse JSON in 'invalid.json':" , proc .stderr )
618619 self .assertIn ('Could not resolve pointer:' , proc .stderr )
619620 self .assertNotIn ('Traceback' , proc .stderr )
620621
622+ def test_invalid_json_stops_without_continue_on_error (self ):
623+ self ._write ('invalid.json' , '{"a": }' )
624+ for index in range (3 ):
625+ with self .subTest (index = index ):
626+ files = ['a.json' , 'b.json' ]
627+ files .insert (index , 'invalid.json' )
628+ proc = self ._run ('/a' , * files )
629+ self .assertEqual (proc .returncode , 1 )
630+ self .assertEqual (proc .stdout ,
631+ '' .join ([self .A_OUT , self .B_OUT ][:index ]))
632+ self .assertIn ('JSONDecodeError' , proc .stderr )
633+
634+ def test_invalid_encoding_in_one_file (self ):
635+ with open (os .path .join (self .dir , 'invalid.json' ), 'wb' ) as f :
636+ f .write (b'{"a":"\xff "}' )
637+ for index in range (3 ):
638+ with self .subTest (index = index ):
639+ files = ['a.json' , 'b.json' ]
640+ files .insert (index , 'invalid.json' )
641+ proc = self ._run ('--continue-on-error' , '/a' , * files )
642+ self .assertEqual (proc .returncode , 1 )
643+ self .assertEqual (proc .stdout , self .A_OUT + self .B_OUT )
644+ self .assertIn ("Could not parse JSON in 'invalid.json':" ,
645+ proc .stderr )
646+ self .assertIn ('decode' , proc .stderr )
647+ self .assertNotIn ('Traceback' , proc .stderr )
648+
649+ def test_invalid_encoding_stops_without_continue_on_error (self ):
650+ with open (os .path .join (self .dir , 'invalid.json' ), 'wb' ) as f :
651+ f .write (b'{"a":"\xff "}' )
652+ proc = self ._run ('/a' , 'a.json' , 'invalid.json' , 'b.json' )
653+ self .assertEqual (proc .returncode , 1 )
654+ self .assertEqual (proc .stdout , self .A_OUT )
655+ self .assertIn ('UnicodeDecodeError' , proc .stderr )
656+
657+ def test_continue_on_error_with_valid_files (self ):
658+ for pointer in (['/a' ], ['-p' , '/a' ], ['-f' , 'ptr.txt' ]):
659+ with self .subTest (pointer = pointer ):
660+ proc = self ._run ('--continue-on-error' , * pointer ,
661+ 'a.json' , 'b.json' )
662+ self .assertEqual (proc .returncode , 0 , proc .stderr )
663+ self .assertEqual (proc .stdout , self .A_OUT + self .B_OUT )
664+ self .assertEqual (proc .stderr , '' )
665+
666+ def test_continue_on_error_does_not_skip_missing_files (self ):
667+ proc = self ._run ('--continue-on-error' , '/a' ,
668+ 'a.json' , 'missing.json' , 'b.json' )
669+ self .assertEqual (proc .returncode , 2 )
670+ self .assertEqual (proc .stdout , self .A_OUT )
671+ self .assertIn ('missing.json' , proc .stderr )
672+
621673 def test_pointer_file_requires_value (self ):
622674 proc = self ._run ('-f' , '-p' , '/a' , 'a.json' )
623675 self .assertEqual (proc .returncode , 2 )
0 commit comments