def test_json_conversion():
    from commonast import Node, Assign, Name, BinOp, Bytes, Num
    
    # Test json conversion
    roota = Assign([Name('foo')], BinOp('Add', Name('a'), Num(3)))
    rootb = Assign([Name('foo')], BinOp('Add', None, Num(3.2)))
    rootc = Assign([Name('foo')], BinOp('Add', Bytes(b'xx'), Num(4j)))  
    
    for node1 in (roota, rootb, rootc):
        js = node1.tojson()
        node2 = Node.fromjson(js)
        #
        assert js.count('BinOp') == 1
        assert js.count('Num') == 1
        #
        assert node2.target_nodes[0].name == node1.target_nodes[0].name
        assert node2.value_node.op == node1.value_node.op
        assert node2.value_node.left_node == node1.value_node.left_node
        assert node2.value_node.right_node.value == node1.value_node.right_node.value
        # In fact, we can do
        node1 == node2
    
    assert roota != rootb
    assert roota != rootc
    with raises(ValueError):
        roota == 5
    
    assert str(roota) == roota.tojson()
    assert len(repr(roota)) < 80
dataset/ETHPy150Open zoofIO/flexx/flexx/pyscript/tests/test_commonast.py/test_json_conversion/original