code: def test_json_validator(
      expected_type: type, valid: str, valid_parsed: Any, invalid: str
  ):
      parser = argparse.ArgumentParser()
      parser.add_argument("--x", type=JsonValidator(expected_type))
  
      class ArgparseFailure(Exception):
          pass
  
      def _exit(status, message):
          raise ArgparseFailure(
              f"Unexpected argparse failure: {message}"
          )
  
      parser.exit = _exit  # override exit to raise exception, rather than invoking sys.exit()
  
      opts = parser.parse_args([f"--x={valid}"])
      assert opts.x == valid_parsed
      assert repr(opts.x) == repr(valid_parsed)  # check types
  
      with pytest.raises(ArgparseFailure):
          parser.parse_args([f"--x={invalid}"])
  
imports: import argparse
  from typing import Any, Dict, List, Tuple, Union
  import pytest
  from options.parse_args import JsonValidator
label_desc: Use image node_id 1 for calling a global function with example usage: test_json_validator(expected_type, valid, valid_parsed, invalid) without return types