Пример #1
0
def test_dumps():
    gson = """
          {
              "test0": 4,
              "test1" : <0,1,2>,
              "test2" : { "nested": gaussian(0,1,draws=1) },
              "test3" : <"a", "b", uniform(0,1)>,
              ("test4", "test5") : (0, 1),
              ("test6", "test7") : 1,
              ("test8","test9") : <("d", "e"), ("f", "g")>,
              "testA": {"another_nested" : root.test5,
                        "parent_test" : parent.test5},
              "testB": this.test5,
              "testC": this.test2.nested,
              "test_with_underscores": 4,
              "testD": this.test_with_underscores,
              "testE": sin(4),
              "testF": sin(this.testE),
              "testG": 10,
              "testExpr": 2.2*this.testG + (10 / sin(this.testA.another_nested)),
              "testZ": 10
          }
          """

    gen = genson.loads(gson)

    print genson.dumps(gen)
    print genson.dumps(gen, pretty_print=True)
Пример #2
0
def test_lazy_getitem_args_kwargs():
    # -- construct a program document directly
    #    without passing through the parser
    prog = OrderedDict()
    prog['test0'] = 4
    prog['test1'] = foo.lazy(1)
    prog['test4'] = JSONFunction.ARGS[0]
    prog['test5'] = JSONFunction.KWARGS['aaa']

    wanted = dict(
            test0=4,
            test1=('first_arg', 'second_arg', 1, None),
            test4=33,
            test5='hello')

    print genson.dumps(prog, pretty_print=True)

    f = JSONFunction(prog)
    result = dict(f(33, aaa='hello'))
    #assert result == wanted
    assert_equal(result, wanted)