Exemple #1
0
 def __init__(self,
              encoding=None,
              object_hook=None,
              parse_float=None,
              parse_int=None,
              parse_constant=None,
              strict=True,
              object_pairs_hook=None):
     super(JsJSONDecoder,
           self).__init__(encoding, object_hook, parse_float, parse_int,
                          parse_constant, strict, object_pairs_hook)
     self.parse_object = JsJSONObject
     self.scan_once = py_make_scanner(self)
Exemple #2
0
    def test_make_scanner_correct(self):
        """
        Description: Ensures that the py_make_scanner() function
        correctly configures the scan_once() function with
        the correct parameters.

        Input: A context containing default values for each
        member.

        Output: An instance of the py_make_scanner:scan_once()
        function.

        Test Case: Corresponds to test case TEST-0087.
        """
        context = ScannerContext()
        scan_once = scanner.py_make_scanner(context)
Exemple #3
0
    def test_make_scanner_scan_once_none(self):
        """
        Description: Tests that the py_make_scanner:scan_once()
        function errors out when given a None type as the input
        string.

        Input:
            (None, int): (None, 0)

        Output:
            (JSONDecodeError)

        Test Case: Corresponds to test case TEST-0093.
        """
        test_input = (None, 0)
        context = ScannerContext()
        scan_once = scanner.py_make_scanner(context)
        self.assertRaises(errors.JSONDecodeError, scan_once, test_input[0],
                          test_input[1])
Exemple #4
0
    def test_make_scanner_scan_once_correct(self):
        """
        Description: Tests that the py_make_scanner:scan_once()
        function properly scans a JSON token given correct
        parameters.

        Input:
            (str, int): ("["abc", "def", "ghi"]", 0)

        Output:
            (list): ["abc", "def", "ghi"]

        Test Case: Corresponds to test case TEST-0092.
        """
        test_input = "[\"abc\", \"def\", \"ghi\"]"
        test_output = ["abc", "def", "ghi"]
        context = ScannerContext()
        scan_once = scanner.py_make_scanner(context)
        output, _ = scan_once(test_input, 0)
        self.assertEqual(output, test_output)
Exemple #5
0
    def test_make_scanner_scan_once_iindex(self):
        """
        Description: Tests that the py_make_scanner:scan_once()
        function errors out when given a valid JSON string as the
        input string and an invalid index.

        Input:
            (str, int): ("["abc", "def", "ghi"]", -1)

        Output:
            (JSONDecodeError)

        Test Case: Corresponds to test case TEST-0094.
        """
        test_input = ("[\"abc\", \"def\", \"ghi\"]", -1)

        context = ScannerContext()
        scan_once = scanner.py_make_scanner(context)

        self.assertRaises(errors.JSONDecodeError, scan_once, test_input[0],
                          test_input[1])
Exemple #6
0
 def __init__(self, *args, **kwargs):
     super(ForgivingDecoder, self).__init__(*args, **kwargs)
     self.parse_string = forgiving_scanstring
     self.scan_once = py_make_scanner(self)
Exemple #7
0
 def __init__(self, *args, **kwargs):
     super(ForgivingDecoder, self).__init__(*args, **kwargs)
     self.parse_string = forgiving_scanstring
     self.scan_once = py_make_scanner(self)
Exemple #8
0
 def __init__(self, encoding=None, object_hook=None, parse_float=None,
         parse_int=None, parse_constant=None, strict=True,
         object_pairs_hook=None):
     super(JsJSONDecoder, self).__init__(encoding, object_hook, parse_float, parse_int, parse_constant, strict, object_pairs_hook)
     self.parse_object = JsJSONObject
     self.scan_once = py_make_scanner(self)