Пример #1
0
 def is_valid_json(json: str) -> bool:
     try:
         ujson.decode(json)
     except:
         return False
     else:
         return True
Пример #2
0
 def test_encodeDictConversion(self):
     input = { "k1": 1, "k2":  2, "k3": 3, "k4": 4 }
     output = ujson.encode(input)
     self.assertEquals(input, json.loads(output))
     self.assertEquals(input, ujson.decode(output))
     self.assertEquals(input, ujson.decode(output))
     pass
Пример #3
0
 def test_dynamic_by_name(self):
     VISITOR_ID_1 = uuid.uuid4().hex
     EVENT_1 = "Event 1 %s" % uuid.uuid4().hex
     EVENT_2 = "Event 2 %s" % uuid.uuid4().hex
     yield self.post_event(VISITOR_ID_1, EVENT_1)
     yield self.post_event(VISITOR_ID_1, EVENT_2)
     events = yield self.get_event_dict()
     event_id_1 = events[EVENT_1]
     event_id_2 = events[EVENT_2]
     qs = urlencode([("event", EVENT_1), ("event", EVENT_2)])
     result = yield request(
         "GET",
         "%s/funnel?%s" % (self.url, qs),
         username=self.username,
         password=self.password) 
     self.assertEqual(result.code, 200)
     returned_event_ids = ujson.decode(result.body)["event_ids"]
     self.assertTrue(event_id_1 in returned_event_ids)
     self.assertTrue(event_id_2 in returned_event_ids)
     funnel = ujson.decode(result.body)["funnel"]
     unique_funnel = ujson.decode(result.body)["unique_funnel"]
     self.assertEqual(funnel[0][0], event_id_1)
     self.assertEqual(funnel[1][0], event_id_2)
     self.assertEqual(funnel[0][1], 1)
     self.assertEqual(funnel[1][1], 1)
     self.assertEqual(unique_funnel[0][0], event_id_1)
     self.assertEqual(unique_funnel[1][0], event_id_2)
     self.assertEqual(unique_funnel[0][1], 1)
     self.assertEqual(unique_funnel[1][1], 1)
Пример #4
0
 def test_decodeArrayOnlyCommaFail(self):
     input = "[,]"
     try:
         ujson.decode(input)
     except ValueError:
         pass
     else:
         assert False, "expected ValueError"
Пример #5
0
 def test_decodeArrayUnmatchedBracketFail(self):
     input = "[]]"
     try:
         ujson.decode(input)
     except ValueError:
         pass
     else:
         assert False, "expected ValueError"
Пример #6
0
 def test_decodeVeryTooBigValue(self):
     try:
         input = "18446744073709551616"
         ujson.decode(input)
     except ValueError:
         pass
     else:
         assert False, "expected ValueError"
Пример #7
0
 def test_decodeVeryTooSmallValue(self):
     try:
         input = "-90223372036854775809"
         ujson.decode(input)
     except ValueError:
         pass
     else:
         assert False, "expected ValueError"
Пример #8
0
 def test_decodeObjectDepthTooBig(self):
     input = '{' * (1024 * 1024)
     try:
         ujson.decode(input)
         assert False, "Expected exception!"
     except(ValueError):
         return
     assert False, "Wrong exception"
Пример #9
0
 def test_decodeWithTrailingNonWhitespaces(self):
     try:
         input = "{}\n\t a"
         ujson.decode(input)
     except ValueError:
         pass
     else:
         assert False, "expected ValueError"
Пример #10
0
 def test_decodeTooBigValue(self):
     try:
         input = "9223372036854775808"
         ujson.decode(input)
     except ValueError as e:
         pass
     else:
         assert False, "expected ValueError"
Пример #11
0
 def test_decodeStringUntermEscapeSequence(self):
     input = '"TESTING\\"'
     try:
         ujson.decode(input)
         assert False, "Expected exception!"
     except (ValueError):
         return
     assert False, "Wrong exception"
Пример #12
0
 def test_goodreads(self):
     def autogenerate_goodreads(*args, **kwargs):
         autogenerator = delta.Autogenerator(paths="books", includes="books/id")
         return [x.data for x in autogenerator(*args, **kwargs)]
     from ujson import decode
     old = decode(read("%s/goodreads/old.json" % DATAPATH))
     new = decode(read("%s/goodreads/new.json" % DATAPATH))
     self.assertEqual(autogenerate_goodreads(old, new), [])
Пример #13
0
 def test_decodeBrokenObjectStart(self):
     input = "{"
     try:
         ujson.decode(input)
         assert False, "Expected exception!"
     except(ValueError):
         return
     assert False, "Wrong exception"
Пример #14
0
 def test_decodeJibberish(self):
     input = "fdsa sda v9sa fdsa"
     try:
         ujson.decode(input)
         assert False, "Expected exception!"
     except(ValueError):
         return
     assert False, "Wrong exception"
Пример #15
0
 def test_decodeStringUnterminated(self):
     input = "\"TESTING"
     try:
         ujson.decode(input)
         assert False, "Expected exception!"
     except(ValueError):
         return
     assert False, "Wrong exception"
Пример #16
0
 def test_decodeStringBadEscape(self):
     input = "\"TESTING\\\""
     try:
         ujson.decode(input)
         assert False, "Expected exception!"
     except(ValueError):
         return
     assert False, "Wrong exception"
Пример #17
0
 def test_decodeNullBroken(self):
     input = "n"
     try:
         ujson.decode(input)
         assert False, "Expected exception!"
     except(ValueError):
         return
     assert False, "Wrong exception"
Пример #18
0
    def test_decodeDictWithNoColonOrValue(self):
        input = '{{{{"key"}}}}'
        try:
            ujson.decode(input)
            assert False, "Expected exception!"
        except (ValueError):
            return

        assert False, "Wrong exception"
Пример #19
0
    def test_decodeDictWithNoValue(self):
        input = "{{{{\"key\":}}}}"
        try:
            ujson.decode(input)
            assert False, "Expected exception!"
        except(ValueError):
            return

        assert False, "Wrong exception"
Пример #20
0
 def test_decodeBigEscape(self):
     for x in range(10):
         if six.PY3:
             base = '\u00e5'.encode('utf-8')
             quote = "\"".encode()
         else:
             base = "\xc3\xa5"
             quote = "\""
         input = quote + (base * 1024 * 1024 * 2) + quote
         ujson.decode(input)
Пример #21
0
    def test_encodeLongNegConversion(self):
        input = -9223372036854775808
        output = ujson.encode(input)

        outputjson = json.loads(output)
        outputujson = ujson.decode(output)

        self.assertEqual(input, json.loads(output))
        self.assertEqual(output, json.dumps(input))
        self.assertEqual(input, ujson.decode(output))
Пример #22
0
    def test_decodeBrokenListLeakTest(self):
        input = '[[[true'
        for x in xrange(1000):
            try:
                ujson.decode(input)
                assert False, "Expected exception!"
            except(ValueError):
                continue

            assert False, "Wrong exception"
Пример #23
0
    def test_decodeBrokenDictKeyTypeLeakTest(self):
        input = '{{1337:""}}'
        for x in xrange(1000):
            try:
                ujson.decode(input)
                assert False, "Expected exception!"
            except(ValueError) as e:
                continue

            assert False, "Wrong exception"
Пример #24
0
 def test_hooks_exceptionHandling(self):
     class TestHookException(Exception):
         pass
     
     call_counters = {
         'pre_encode_hook': 0,
         'string_hook': 0,
         'object_hook': 0,
     }
     
     def pre_encode_hook(_unused_obj):
         call_counters['pre_encode_hook'] += 1
         raise TestHookException()
     
     def string_hook(_unused_obj):
         call_counters['string_hook'] += 1
         raise TestHookException()
     
     def object_hook(_unused_obj):
         call_counters['object_hook'] += 1
         raise TestHookException()
     
     input = {
         'foo': 1,
         'bar': {
             'a': 'a',
             'b': 'b',
         },
     }
     json = """
     {
         "foo": 1,
         "bar": {
             "a": "a",
             "b": "b"
         }
     }
     """
     
     with self.assertRaises(TestHookException):
         ujson.encode(input, pre_encode_hook=pre_encode_hook)
     
     with self.assertRaises(TestHookException):
         ujson.decode(json, string_hook=string_hook)
     
     with self.assertRaises(TestHookException):
         ujson.decode(json, object_hook=object_hook)
     
     # Test not only that the exception is raised, but also that the hook
     # is called only once. I.e. that the low-level code detects the error
     # and stops the iteration process after the first call.    
     self.assertEqual(call_counters['pre_encode_hook'], 1)
     self.assertEqual(call_counters['string_hook'], 1)
     self.assertEqual(call_counters['object_hook'], 1)
Пример #25
0
 def test_decodeTooSmallValue(self):
     if ujson.bigint_supported:
         for i in range(30):
             input = -90223372036854775809 - i
             obj = ujson.decode('%s' % input)
             self.assertEqual(input, obj)
         for i in range(30):
             input = -41255008296960273580 - i
             obj = ujson.decode('%s' % input)
             self.assertEqual(input, obj)
     else:
       input = "-90223372036854775809"
       self.assertRaises(ValueError, ujson.decode, input)
Пример #26
0
 def test_messages_since(self):
     conn = self._make_one()
     name = conn.create_queue()
     # add test message
     r1 = conn.post(url=name, data=u'Hello 1')
     key1 = ujson.decode(r1.text)[u'messages'][0][u'key']
     r2 = conn.post(url=name, data=u'Hello 2')
     key2 = ujson.decode(r2.text)[u'messages'][0][u'key']
     messages = conn.messages(name, since=key2)
     self.assertEqual(len(messages), 0)
     messages = conn.messages(name, since=key1)
     self.assertEqual(len(messages), 1)
     self.assertEqual(messages[0][u'body'], u'Hello 2')
Пример #27
0
    def test_doublePrecisionTest(self):
        input = 30.012345678901234
        output = ujson.encode(input, double_precision = 15)
        self.assertEqual(input, json.loads(output))
        self.assertEqual(input, ujson.decode(output))

        output = ujson.encode(input, double_precision = 9)
        self.assertEqual(round(input, 9), json.loads(output))
        self.assertEqual(round(input, 9), ujson.decode(output))

        output = ujson.encode(input, double_precision = 3)
        self.assertEqual(round(input, 3), json.loads(output))
        self.assertEqual(round(input, 3), ujson.decode(output))
Пример #28
0
def action():

    redisqueue = j.clients.credis.getRedisQueue("127.0.0.1", 9999, "logs")
    redisqueueEco = j.clients.credis.getRedisQueue("127.0.0.1", 9999, "eco")

    OSISclient = j.core.osis.client

    OSISclientLogger = j.core.osis.getClientForCategory(OSISclient, "system", "log")
    OSISclientEco = j.core.osis.getClientForCategory(OSISclient, "system", "eco")

    log = None
    path = "%s/apps/processmanager/loghandling/"%j.dirs.baseDir
    if j.system.fs.exists(path=path):
        loghandlingTE = j.core.taskletengine.get(path)
        log=redisqueue.get_nowait()
        # j.core.grid.logger.osis = OSISclientLogger
    else:
        loghandlingTE = None

    eco = None
    path = "%s/apps/processmanager/eventhandling"%j.dirs.baseDir
    if j.system.fs.exists(path=path):
        eventhandlingTE = j.core.taskletengine.get(path)
        eco=redisqueueEco.get_nowait()
    else:
        eventhandlingTE = None

    out=[]
    while log<>None:
        log2=json.decode(log)
        log3 = j.logger.getLogObjectFromDict(log2)
        log4= loghandlingTE.executeV2(logobj=log3)      
        if log4<>None:
            out.append(log4.__dict__)
        if len(out)>500:
            OSISclientLogger.set(out)
            out=[]
        log=redisqueue.get_nowait()
    if len(out)>0:
        OSISclientLogger.set(out)

    while eco<>None:
        eco2=json.decode(eco)
        eco2["epoch"] = int(time.time())
        eco3 = j.errorconditionhandler.getErrorConditionObject(ddict=eco2)        
        eco4= eventhandlingTE.executeV2(eco=eco3)
        if hasattr(eco4,"tb"):
            eco4.__dict__.pop("tb")        
        OSISclientEco.set(eco4.__dict__)
        eco=redisqueueEco.get_nowait()
Пример #29
0
    def test_encodeNullCharacter(self):
        input = "31337 \x00 1337"
        output = ujson.encode(input)
        self.assertEqual(input, json.loads(output))
        self.assertEqual(output, json.dumps(input))
        self.assertEqual(input, ujson.decode(output))

        input = "\x00"
        output = ujson.encode(input)
        self.assertEqual(input, json.loads(output))
        self.assertEqual(output, json.dumps(input))
        self.assertEqual(input, ujson.decode(output))

        self.assertEqual('"  \\u0000\\r\\n "', ujson.dumps(u"  \u0000\r\n "))
Пример #30
0
 def test_create(self):
     VISITOR_ID_1 = uuid.uuid4().hex
     EVENT_1 = "Event 1 %s" % uuid.uuid4().hex
     EVENT_2 = "Event 2 %s" % uuid.uuid4().hex
     yield self.post_event(VISITOR_ID_1, EVENT_1)
     yield self.post_event(VISITOR_ID_1, EVENT_2)
     events = yield self.get_event_dict()
     event_id_1 = events[EVENT_1]
     event_id_2 = events[EVENT_2]
     FUNNEL_NAME = uuid.uuid4().hex
     DESCRIPTION = uuid.uuid4().hex
     result = yield request(
         "POST",
         "%s/funnel/%s" % (self.url, FUNNEL_NAME),
         username=self.username,
         password=self.password,
         data=[
             ("description", DESCRIPTION),
             ("event_id",event_id_1),
             ("event_id",event_id_2)])
     self.assertEqual(result.code, 201)
     result = yield request(
         "GET",
         "%s/funnel/%s" % (self.url, FUNNEL_NAME),
         username=self.username,
         password=self.password)        
     self.assertEqual(result.code, 200)
     returned_description = ujson.decode(result.body)["description"]
     self.assertEqual(DESCRIPTION, returned_description)
     returned_event_ids = ujson.decode(result.body)["event_ids"]
     self.assertTrue(event_id_1 in returned_event_ids)
     self.assertTrue(event_id_2 in returned_event_ids)
     funnel = ujson.decode(result.body)["funnel"]
     unique_funnel = ujson.decode(result.body)["unique_funnel"]
     self.assertEqual(funnel[0][0], event_id_1)
     self.assertEqual(funnel[1][0], event_id_2)
     self.assertEqual(funnel[0][1], 1)
     self.assertEqual(funnel[1][1], 1)
     self.assertEqual(unique_funnel[0][0], event_id_1)
     self.assertEqual(unique_funnel[1][0], event_id_2)
     self.assertEqual(unique_funnel[0][1], 1)
     self.assertEqual(unique_funnel[1][1], 1)
     result = yield request(
         "DELETE",
         "%s/funnel/%s" % (self.url, FUNNEL_NAME),
         username=self.username,
         password=self.password)
     self.assertEqual(result.code, 200)
Пример #31
0
    def test_encodeDoubleNegConversion(self):
        input = -math.pi
        output = ujson.encode(input)

        self.assertEqual(round(input, 5), round(json.loads(output), 5))
        self.assertEqual(round(input, 5), round(ujson.decode(output), 5))
Пример #32
0
 def test_encodeStringConversion2(self):
     input = "A string \\ / \b \f \n \r \t"
     output = ujson.encode(input)
     self.assertEqual(input, json.loads(output))
     self.assertEqual(output, '"A string \\\\ \\/ \\b \\f \\n \\r \\t"')
     self.assertEqual(input, ujson.decode(output))
Пример #33
0
 def test_decodeFromUnicode(self):
     input = "{\"obj\": 31337}"
     dec1 = ujson.decode(input)
     dec2 = ujson.decode(str(input))
     self.assertEqual(dec1, dec2)
Пример #34
0
 def test_decodeNumericIntPos(self):
     input = "31337"
     self.assertEqual(31337, ujson.decode(input))
Пример #35
0
 def test_encodeLongConversion(self):
     input = 9223372036854775807
     output = ujson.encode(input)
     self.assertEqual(input, json.loads(output))
     self.assertEqual(output, json.dumps(input))
     self.assertEqual(input, ujson.decode(output))
Пример #36
0
 def test_decodeNumericIntExpe(self):
     input = "1337e40"
     output = ujson.decode(input)
     self.assertEqual(output, json.loads(input))
Пример #37
0
 def test_decodeArrayEmpty(self):
     input = "[]"
     obj = ujson.decode(input)
     self.assertEqual([], obj)
Пример #38
0
 def test_decodeArrayOneItem(self):
     input = "[31337]"
     ujson.decode(input)
Пример #39
0
 def test_decodeBigValue(self):
     input = "9223372036854775807"
     ujson.decode(input)
Пример #40
0
 def test_encodeArrayOfNestedArrays(self):
     input = [[[[]]]] * 20
     output = ujson.encode(input)
     self.assertEqual(input, json.loads(output))
     #self.assertEqual(output, json.dumps(input))
     self.assertEqual(input, ujson.decode(output))
Пример #41
0
 def test_encodeUnicodeConversion1(self):
     input = "Räksmörgås اسامة بن محمد بن عوض بن لادن"
     enc = ujson.encode(input)
     dec = ujson.decode(enc)
     self.assertEqual(enc, json_unicode(input))
     self.assertEqual(dec, json.loads(enc))
Пример #42
0
 def test_encodeFalseConversion(self):
     input = False
     output = ujson.encode(input)
     self.assertEqual(input, json.loads(output))
     self.assertEqual(output, json.dumps(input))
     self.assertEqual(input, ujson.decode(output))
Пример #43
0
 def test_encodeUnicodeConversion2(self):
     input = "\xe6\x97\xa5\xd1\x88"
     enc = ujson.encode(input)
     dec = ujson.decode(enc)
     self.assertEqual(enc, json_unicode(input))
     self.assertEqual(dec, json.loads(enc))
Пример #44
0
 def test_encodeControlEscaping(self):
     input = "\x19"
     enc = ujson.encode(input)
     dec = ujson.decode(enc)
     self.assertEqual(input, dec)
     self.assertEqual(enc, json_unicode(input))
Пример #45
0
 def test_decodeLongUnsignedValue(self):
     input = "18446744073709551615"
     ujson.decode(input)
Пример #46
0
 def test_decimalDecodeTestPrecise(self):
     sut = {'a': 4.56}
     encoded = ujson.encode(sut)
     decoded = ujson.decode(encoded, precise_float=True)
     self.assertEqual(sut, decoded)
Пример #47
0
 def test_decodeArrayDict(self):
     input = "{}"
     obj = ujson.decode(input)
     self.assertEqual({}, obj)
Пример #48
0
def format_json(json_data):
    actor_identities = {}  # Where we're going to store our list of actor ids
    actor_identities['items'] = []

    actor_quantity = len(json_data)  # Get the quantity of actors!
    #actor_quantity = 2 # For testing!

    widgets = [
        Percentage(),  # Setting how we wan the progress bar to look
        ' ',
        Bar(),
        ' ',
        ETA()
    ]

    scrape_range_ref = actor_quantity + 1
    pbar = ProgressBar(
        widgets=widgets,
        maxval=scrape_range_ref).start()  #Prepare the progress bar
    progress_iterator = 0

    for actor_number in range(
            actor_quantity):  # There are approx 979 pages we've scraped
        current_actor_data = json_data[
            actor_number]  # Storing the current page in memory
        current_actor_name = current_actor_data[
            'name']  # The actor's real name
        current_actor_roles = current_actor_data['movie_credits'][
            'cast']  # The roles the character played
        quantity_actor_roles = len(
            current_actor_roles)  # How many roles they played
        current_actor_role_synonyms = []  # Empty list for each actor
        current_actor_role_synonyms.append(
            current_actor_name
        )  # We want the entity synonym to include their real name, not just characters:movies

        for actor_role in range(quantity_actor_roles):

            if (len(current_actor_role_synonyms) > 98):
                continue  # Can't go over 99 synonyms per value

            current_target = current_actor_roles[
                actor_role]  # Simple reference

            if 'character' not in current_target:  # Make sure the character field exists!
                continue  # Skip if it doesn't exist!
            else:
                if 'title' not in current_target:  # Check that the title exists in json!
                    continue  # Skip if the movie title doesn't exist!
                else:
                    actor_character = current_target[
                        'character']  # Grab their character name
                    if (len(actor_character) < 2):
                        continue  # If the character's name is less than 2 characters long, skip (likely a blank field)
                    elif (actor_character.lower() == 'himself'):
                        continue  # If they know the actor's name, they don't need to l
                    elif (actor_character.lower() == 'herself'):
                        continue
                    elif (actor_character.lower() == 'self'):
                        continue
                    else:
                        actor_character = re.sub(
                            r'\([^()]*\)', '', actor_character
                        )  # Any parenthesised information (uncredited) (self) (himself) etc will be removed from character strings!
                        #actor_character = re.sub('".*?"', '', actor_character) # Removing any quotation marks in character name. Future improvement could match character_nickname:actor similar to handling / below
                        actor_character = re.sub('"', '', actor_character)
                        actor_movie = re.sub(
                            r'\([^()]*\)', '',
                            current_target['title'])  # Grab the movie name

                        if (
                                "/" in actor_character
                        ):  # If the actor plays multiple characters it'll be listed as "character secret identity / character super hero"
                            multiple_characters = actor_character.split(
                                "/")  # Split string into list of characters
                            for character in multiple_characters:
                                if (len(current_actor_role_synonyms) > 98):
                                    continue  # Can't go over 99 synonyms per value
                                character.strip()  # Remove whitespace
                                in_entity = character + " in " + actor_movie  # "character in movie"
                                #from_entity = character + " from " + actor_movie # "character from movie"
                                current_actor_role_synonyms.append(
                                    in_entity)  # Add the 'in' synonym
                                #current_actor_role_synonyms.append(from_entity) # Add the 'from' synonym
                        else:
                            actor_character.strip(
                            )  # Strip whitespace from left/right of the string
                            in_entity = actor_character + " in " + actor_movie  # 'in'
                            #from_entity = actor_character + " from " + actor_movie # 'from'
                            current_actor_role_synonyms.append(
                                in_entity)  # Add the 'in' synonym
                            #current_actor_role_synonyms.append(from_entity) # Add the 'from' synonym

        #if (len(current_actor_role_synonyms) > 95):
        #    print(len(current_actor_role_synonyms))

        text_to_json = ujson.dumps({
            "value": current_actor_name,
            "synonyms": current_actor_role_synonyms
        })  # Changing the text into json

        actor_identities['items'].append(
            ujson.decode(text_to_json))  # Append the synonyms to the list

        pbar.update(progress_iterator + 1)  # Display incremented progress
        progress_iterator += 1  # Iterate the progress bar for next iteration

    pbar.finish()  #Once we've complete the scraping, end the progress bar.
    return actor_identities['items']
Пример #49
0
 def test_decodeNumericIntExpeMinus(self):
     input = "1.337e-4"
     output = ujson.decode(input)
     self.assertEqual(output, json.loads(input))
Пример #50
0
        #if (len(current_actor_role_synonyms) > 95):
        #    print(len(current_actor_role_synonyms))

        text_to_json = ujson.dumps({
            "value": current_actor_name,
            "synonyms": current_actor_role_synonyms
        })  # Changing the text into json

        actor_identities['items'].append(
            ujson.decode(text_to_json))  # Append the synonyms to the list

        pbar.update(progress_iterator + 1)  # Display incremented progress
        progress_iterator += 1  # Iterate the progress bar for next iteration

    pbar.finish()  #Once we've complete the scraping, end the progress bar.
    return actor_identities['items']


if __name__ == '__main__':
    with open('popular_people.json') as data_file:
        actor_json_data = ujson.load(data_file)  # Load actor data in

    formatted_json = format_json(
        actor_json_data)  # Where the majority of the magic happens
    wrapped_json = ujson.decode(
        "[{\"entries\":" + ujson.encode(formatted_json) +
        ", \"name\": \"actors\"}]"
    )  # Wrapping the JSON with dialogflow's preferred formatting
    write_json_to_disk(wrapped_json)
Пример #51
0
 def test_numericIntFrcExp(self):
     input = "1.337E40"
     output = ujson.decode(input)
     self.assertEqual(output, json.loads(input))
Пример #52
0
 def test_decimalDecodeTest(self):
     sut = {'a': 4.56}
     encoded = ujson.encode(sut)
     decoded = ujson.decode(encoded)
     self.assertAlmostEqual(sut[u'a'], decoded[u'a'])
Пример #53
0
 def test_decodeNullCharacter(self):
     input = "\"31337 \\u0000 31337\""
     self.assertEqual(ujson.decode(input), json.loads(input))
Пример #54
0
 def test_encodeDecodeLongDecimal(self):
     sut = {'a': -528656961.4399388}
     encoded = ujson.dumps(sut)
     ujson.decode(encoded)
Пример #55
0
 def test_decodeNumericIntNeg(self):
     input = "-31337"
     self.assertEqual(-31337, ujson.decode(input))
Пример #56
0
 def test_decodeWithTrailingWhitespaces(self):
     input = "{}\n\t "
     ujson.decode(input)
Пример #57
0
 def helper(expected_output, **encode_kwargs):
     output = ujson.encode(input, **encode_kwargs)
     self.assertEqual(output, expected_output)
     if encode_kwargs.get('escape_forward_slashes', True):
         self.assertEqual(input, json.loads(output))
         self.assertEqual(input, ujson.decode(output))
Пример #58
0
 def test_decodeSmallValue(self):
     input = "-9223372036854775808"
     ujson.decode(input)
Пример #59
0
 def test_encodeDecimal(self):
     sut = decimal.Decimal("1337.1337")
     encoded = ujson.encode(sut, double_precision=100)
     decoded = ujson.decode(encoded)
     self.assertEqual(decoded, 1337.1337)
Пример #60
0
 def test_encodeArrayOfDoubles(self):
     input = [31337.31337, 31337.31337, 31337.31337, 31337.31337] * 10
     output = ujson.encode(input)
     self.assertEqual(input, json.loads(output))
     #self.assertEqual(output, json.dumps(input))
     self.assertEqual(input, ujson.decode(output))