Exemplo n.º 1
0
def test_treecrawler_raw_output():
    """Outputs a list of tuples.
    1st element is the parent node.
    2nd elemeent is a list of child nodes.
    """
    result = node_visitor(TEST_DATA, arrays=False)
    assert sorted(result) == RAW_OUTPUT
Exemplo n.º 2
0
def get_nodes(d, wildcard=WILDCARD):
    """Given JSON data; generate a sequence of nodes.

    Returns namedtuples Node(keys, val, dtype) sorted on keys where ...
        * `keys` are unique keystrings
        * `val` is the node's value
        * `dtype` is the JSON data type.
    """
    visited = node_visitor(d, arrays=True, element_ch=wildcard)
    nodes = (i for i in visited if i.keys is not None)
    result = (Node(tuple(i.keys), i.val, i.dtype) for i in nodes)
    return result
Exemplo n.º 3
0
def test_treecrawler_with_element_char():
    result = set(node_visitor(FORECAST_SEQUENCE, get_keys, element_ch='*'))
    assert sorted(result) == FORECAST_SEQUENCE_KEYS_WITH_WILDCARD
Exemplo n.º 4
0
def test_treecrawler_without_array_crawler():
    result = set(node_visitor(FORECAST, get_keys, arrays=False))
    assert sorted(result) == FORECAST_MAPPING_KEYS + ['forecast']
Exemplo n.º 5
0
def test_treecrawler_sequence():
    result = set(node_visitor(FORECAST_SEQUENCE, get_keys, arrays=True))
    assert sorted(result) == FORECAST_SEQUENCE_KEYS
Exemplo n.º 6
0
def test_treecrawler_mapping():
    result = set(node_visitor(FORECAST_MAPPING, get_keys, arrays=True))
    assert sorted(result) == FORECAST_MAPPING_KEYS
Exemplo n.º 7
0
def test_treecrawler_primitive_without_objects():
    assert sorted(set(node_visitor('', get_keys, objects=False))) == ['']
Exemplo n.º 8
0
def test_treecrawler_primitive():
    assert sorted(set(node_visitor('', get_keys))) == ['']
Exemplo n.º 9
0
def test_node_type_object():
    data = json.loads('{}')
    result = list(node_visitor(data))
    assert result[0].dtype == 'object'
Exemplo n.º 10
0
def test_node_type_float():
    data = json.loads('null')
    result = list(node_visitor(data, arrays=False))
    assert result[0].dtype == 'null'
Exemplo n.º 11
0
def test_node_type_true():
    data = json.loads('true')
    result = list(node_visitor(data))
    assert result[0].dtype == 'boolean'
Exemplo n.º 12
0
def test_node_type_float():
    data = json.loads('0.1')
    result = list(node_visitor(data))
    assert result[0].dtype == 'number (real)'
Exemplo n.º 13
0
def test_node_type_long():
    data = json.loads('100000000')
    result = list(node_visitor(data))
    assert result[0].dtype == 'number (int)'
Exemplo n.º 14
0
def test_node_type_text():
    data = u""
    result = list(node_visitor(data))
    assert result[0].dtype == 'string'
Exemplo n.º 15
0
def test_node_type_string():
    data = json.loads('""')
    result = list(node_visitor(data))
    assert result[0].dtype == 'string'
Exemplo n.º 16
0
def test_node_type_array():
    data = json.loads('[]')
    result = list(node_visitor(data))
    assert result[0].dtype == 'array'
Exemplo n.º 17
0
 def valmap(keys, seq):
     for key in keys or node_visitor(seq, lambda x: x.keys, arrays=True):
         seq = map(partial(set_item, key, funct), seq)
     return list(seq)
Exemplo n.º 18
0
def test_treecrawler():
    result = set(node_visitor(FORECAST, get_keys, element_ch='*'))
    assert sorted(result) == FORECAST_KEYS