Ejemplo n.º 1
0
def _all_xonsh_parser(*args):
    """
    Returns all history as found in XONSH_DATA_DIR.

    return format: (name, start_time, index)
    """
    data_dir = builtins.__xonsh_env__.get('XONSH_DATA_DIR')
    data_dir = expanduser_abs_path(data_dir)

    files = [
        os.path.join(data_dir, f) for f in os.listdir(data_dir)
        if f.startswith('xonsh-') and f.endswith('.json')
    ]
    file_hist = []
    for f in files:
        try:
            json_file = LazyJSON(f, reopen=False)
            file_hist.append(json_file.load()['cmds'])
        except ValueError:
            # Invalid json file
            pass
    commands = [(c['inp'][:-1] if c['inp'].endswith('\n') else c['inp'],
                 c['ts'][0]) for commands in file_hist for c in commands if c]
    commands.sort(key=operator.itemgetter(1))
    return [(c, t, ind) for ind, (c, t) in enumerate(commands)]
Ejemplo n.º 2
0
def test_lazy_list_empty():
    x = []
    f = StringIO()
    ljdump(x, f)
    f.seek(0)
    lj = LazyJSON(f)
    assert 0 == len(lj)
    assert x == lj.load()
Ejemplo n.º 3
0
def test_lazy_list_empty():
    x = []
    f = StringIO()
    ljdump(x, f)
    f.seek(0)
    lj = LazyJSON(f)
    assert 0 == len(lj)
    assert x == lj.load()
Ejemplo n.º 4
0
def test_lazy_list_empty():
    x = []
    f = StringIO()
    dump(x, f)
    f.seek(0)
    lj = LazyJSON(f)
    assert_equal(0, len(lj))
    assert_equal(x, lj.load())
Ejemplo n.º 5
0
def test_lazy_list_empty():
    x = []
    f = StringIO()
    ljdump(x, f)
    f.seek(0)
    lj = LazyJSON(f)
    assert_equal(0, len(lj))
    assert_equal(x, lj.load())
Ejemplo n.º 6
0
def test_lazy_dict():
    f = StringIO()
    ljdump({"wakka": 42}, f)
    f.seek(0)
    lj = LazyJSON(f)
    assert ["wakka"] == list(lj.keys())
    assert 42 == lj["wakka"]
    assert 1 == len(lj)
    assert {"wakka": 42} == lj.load()
Ejemplo n.º 7
0
def test_lazy_dict():
    f = StringIO()
    dump({'wakka': 42}, f)
    f.seek(0)
    lj = LazyJSON(f)
    assert_equal(['wakka'], list(lj.keys()))
    assert_equal(42, lj['wakka'])
    assert_equal(1, len(lj))
    assert_equal({'wakka': 42}, lj.load())
Ejemplo n.º 8
0
def test_lazy_dict():
    f = StringIO()
    ljdump({"wakka": 42}, f)
    f.seek(0)
    lj = LazyJSON(f)
    assert ["wakka"] == list(lj.keys())
    assert 42 == lj["wakka"]
    assert 1 == len(lj)
    assert {"wakka": 42} == lj.load()
Ejemplo n.º 9
0
def test_lazy_dict():
    f = StringIO()
    dump({'wakka': 42}, f)
    f.seek(0)
    lj = LazyJSON(f)
    assert_equal(['wakka'], list(lj.keys()))
    assert_equal(42, lj['wakka'])
    assert_equal(1, len(lj))
    assert_equal({'wakka': 42}, lj.load())
Ejemplo n.º 10
0
def test_lazy_list_list_ints():
    x = [[0, 1], [6, 28], [496, 8128]]
    f = StringIO()
    dump(x, f)
    f.seek(0)
    lj = LazyJSON(f)
    assert_is_instance(lj[1], Node)
    assert_equal(28, lj[1][1])
    assert_equal([6, 28], lj[1].load())
    assert_equal(x, lj.load())
Ejemplo n.º 11
0
def test_lazy_list_str():
    x = ['I', 'have', 'seen', 'the', 'wind', 'blow']
    f = StringIO()
    dump(x, f)
    f.seek(0)
    lj = LazyJSON(f)
    assert_equal('the', lj[3])
    assert_equal(x[:2:-2], lj[:2:-2])
    assert_equal(x, [_ for _ in lj])
    assert_equal(x, lj.load())
Ejemplo n.º 12
0
def test_lazy_list_ints():
    x = [0, 1, 6, 28, 496, 8128]
    f = StringIO()
    dump(x, f)
    f.seek(0)
    lj = LazyJSON(f)
    assert_equal(28, lj[3])
    assert_equal(x[:2:-2], lj[:2:-2])
    assert_equal(x, [_ for _ in lj])
    assert_equal(x, lj.load())
Ejemplo n.º 13
0
def test_lazy_list_str():
    x = ["I", "have", "seen", "the", "wind", "blow"]
    f = StringIO()
    ljdump(x, f)
    f.seek(0)
    lj = LazyJSON(f)
    assert "the" == lj[3]
    assert x[:2:-2] == lj[:2:-2]
    assert x == [_ for _ in lj]
    assert x == lj.load()
Ejemplo n.º 14
0
def test_lazy_list_list_ints():
    x = [[0, 1], [6, 28], [496, 8128]]
    f = StringIO()
    ljdump(x, f)
    f.seek(0)
    lj = LazyJSON(f)
    assert isinstance(lj[1], LJNode)
    assert 28 == lj[1][1]
    assert [6 == 28], lj[1].load()
    assert x == lj.load()
Ejemplo n.º 15
0
def test_lazy_list_ints():
    x = [0, 1, 6, 28, 496, 8128]
    f = StringIO()
    ljdump(x, f)
    f.seek(0)
    lj = LazyJSON(f)
    assert 28 == lj[3]
    assert x[:2:-2] == lj[:2:-2]
    assert x == [_ for _ in lj]
    assert x == lj.load()
Ejemplo n.º 16
0
def test_lazy_list_list_ints():
    x = [[0, 1], [6, 28], [496, 8128]]
    f = StringIO()
    ljdump(x, f)
    f.seek(0)
    lj = LazyJSON(f)
    assert isinstance(lj[1], LJNode)
    assert 28 == lj[1][1]
    assert [6 == 28], lj[1].load()
    assert x == lj.load()
Ejemplo n.º 17
0
def test_lazy_list_str():
    x = ["I", "have", "seen", "the", "wind", "blow"]
    f = StringIO()
    ljdump(x, f)
    f.seek(0)
    lj = LazyJSON(f)
    assert "the" == lj[3]
    assert x[:2:-2] == lj[:2:-2]
    assert x == [_ for _ in lj]
    assert x == lj.load()
Ejemplo n.º 18
0
def test_lazy_list_ints():
    x = [0, 1, 6, 28, 496, 8128]
    f = StringIO()
    dump(x, f)
    f.seek(0)
    lj = LazyJSON(f)
    assert_equal(28, lj[3])
    assert_equal(x[:2:-2], lj[:2:-2])
    assert_equal(x, [_ for _ in lj])
    assert_equal(x, lj.load())
Ejemplo n.º 19
0
def test_lazy_list_str():
    x = ['I', 'have', 'seen', 'the', 'wind', 'blow']
    f = StringIO()
    ljdump(x, f)
    f.seek(0)
    lj = LazyJSON(f)
    assert 'the' == lj[3]
    assert x[:2:-2] == lj[:2:-2]
    assert x == [_ for _ in lj]
    assert x == lj.load()
Ejemplo n.º 20
0
def test_lazy_list_ints():
    x = [0, 1, 6, 28, 496, 8128]
    f = StringIO()
    ljdump(x, f)
    f.seek(0)
    lj = LazyJSON(f)
    assert 28 == lj[3]
    assert x[:2:-2] == lj[:2:-2]
    assert x == [_ for _ in lj]
    assert x == lj.load()
Ejemplo n.º 21
0
def test_lazy_list_str():
    x = ['I', 'have', 'seen', 'the', 'wind', 'blow']
    f = StringIO()
    ljdump(x, f)
    f.seek(0)
    lj = LazyJSON(f)
    assert 'the' ==  lj[3]
    assert x[:2:-2] ==  lj[:2:-2]
    assert x ==  [_ for _ in lj]
    assert x ==  lj.load()
Ejemplo n.º 22
0
def test_lazy_list_str():
    x = ['I', 'have', 'seen', 'the', 'wind', 'blow']
    f = StringIO()
    dump(x, f)
    f.seek(0)
    lj = LazyJSON(f)
    assert_equal('the', lj[3])
    assert_equal(x[:2:-2], lj[:2:-2])
    assert_equal(x, [_ for _ in lj])
    assert_equal(x, lj.load())
Ejemplo n.º 23
0
def test_lazy_list_list_ints():
    x = [[0, 1], [6, 28], [496, 8128]]
    f = StringIO()
    dump(x, f)
    f.seek(0)
    lj = LazyJSON(f)
    assert_is_instance(lj[1], Node)
    assert_equal(28, lj[1][1])
    assert_equal([6, 28], lj[1].load())
    assert_equal(x, lj.load())
Ejemplo n.º 24
0
def test_lazy_dict_dict_int():
    x = {'wakka': {'jawaka': 42}}
    f = StringIO()
    dump(x, f)
    f.seek(0)
    lj = LazyJSON(f)
    assert_equal(['wakka'], list(lj.keys()))
    assert_is_instance(lj['wakka'], Node)
    assert_equal(42, lj['wakka']['jawaka'])
    assert_equal(1, len(lj))
    assert_equal(x, lj.load())
Ejemplo n.º 25
0
def test_lazy_dict_dict_int():
    x = {"wakka": {"jawaka": 42}}
    f = StringIO()
    ljdump(x, f)
    f.seek(0)
    lj = LazyJSON(f)
    assert ["wakka"] == list(lj.keys())
    assert isinstance(lj["wakka"], LJNode)
    assert 42 == lj["wakka"]["jawaka"]
    assert 1 == len(lj)
    assert x == lj.load()
Ejemplo n.º 26
0
def test_lazy_dict_dict_int():
    x = {'wakka': {'jawaka': 42}}
    f = StringIO()
    ljdump(x, f)
    f.seek(0)
    lj = LazyJSON(f)
    assert ['wakka'] == list(lj.keys())
    assert isinstance(lj['wakka'], LJNode)
    assert 42 == lj['wakka']['jawaka']
    assert 1 == len(lj)
    assert x == lj.load()
Ejemplo n.º 27
0
def test_lazy_dict_dict_int():
    x = {'wakka': {'jawaka': 42}}
    f = StringIO()
    ljdump(x, f)
    f.seek(0)
    lj = LazyJSON(f)
    assert ['wakka'] ==  list(lj.keys())
    assert isinstance(lj['wakka'], LJNode)
    assert 42 ==  lj['wakka']['jawaka']
    assert 1 ==  len(lj)
    assert x ==  lj.load()
Ejemplo n.º 28
0
def test_lazy_dict_dict_int():
    x = {"wakka": {"jawaka": 42}}
    f = StringIO()
    ljdump(x, f)
    f.seek(0)
    lj = LazyJSON(f)
    assert ["wakka"] == list(lj.keys())
    assert isinstance(lj["wakka"], LJNode)
    assert 42 == lj["wakka"]["jawaka"]
    assert 1 == len(lj)
    assert x == lj.load()
Ejemplo n.º 29
0
def test_lazy_dict_dict_int():
    x = {'wakka': {'jawaka': 42}}
    f = StringIO()
    dump(x, f)
    f.seek(0)
    lj = LazyJSON(f)
    assert_equal(['wakka'], list(lj.keys()))
    assert_is_instance(lj['wakka'], Node)
    assert_equal(42, lj['wakka']['jawaka'])
    assert_equal(1, len(lj))
    assert_equal(x, lj.load())
Ejemplo n.º 30
0
def _all_xonsh_parser(**kwargs):
    """
    Returns all history as found in XONSH_DATA_DIR.

    return format: (cmd, start_time, index)
    """
    ind = 0
    for f in _get_history_files():
        try:
            json_file = LazyJSON(f, reopen=False)
        except ValueError:
            # Invalid json file
            continue
        commands = json_file.load()['cmds']
        for c in commands:
            yield (c['inp'].rstrip(), c['ts'][0], ind)
            ind += 1
Ejemplo n.º 31
0
def _all_xonsh_parser(**kwargs):
    """
    Returns all history as found in XONSH_DATA_DIR.

    return format: (cmd, start_time, index)
    """
    ind = 0
    for f in _get_history_files():
        try:
            json_file = LazyJSON(f, reopen=False)
        except ValueError:
            # Invalid json file
            continue
        commands = json_file.load()['cmds']
        for c in commands:
            yield (c['inp'].rstrip(), c['ts'][0], ind)
            ind += 1
Ejemplo n.º 32
0
def _all_xonsh_parser(**kwargs):
    """
    Returns all history as found in XONSH_DATA_DIR.

    return format: (cmd, start_time, index)
    """
    data_dir = builtins.__xonsh_env__.get('XONSH_DATA_DIR')
    data_dir = expanduser_abs_path(data_dir)

    files = [os.path.join(data_dir, f) for f in os.listdir(data_dir)
             if f.startswith('xonsh-') and f.endswith('.json')]
    ind = 0
    for f in files:
        try:
            json_file = LazyJSON(f, reopen=False)
        except ValueError:
            # Invalid json file
            pass
        commands = json_file.load()['cmds']
        for c in commands:
            yield (c['inp'].rstrip(), c['ts'][0], ind)
            ind += 1
Ejemplo n.º 33
0
def _all_xonsh_parser(**kwargs):
    """
    Returns all history as found in XONSH_DATA_DIR.

    return format: (cmd, start_time, index)
    """
    data_dir = builtins.__xonsh_env__.get('XONSH_DATA_DIR')
    data_dir = expanduser_abs_path(data_dir)

    files = [os.path.join(data_dir, f) for f in os.listdir(data_dir)
             if f.startswith('xonsh-') and f.endswith('.json')]
    ind = 0
    for f in files:
        try:
            json_file = LazyJSON(f, reopen=False)
        except ValueError:
            # Invalid json file
            pass
        commands = json_file.load()['cmds']
        for c in commands:
            yield (c['inp'].rstrip(), c['ts'][0], ind)
            ind += 1
Ejemplo n.º 34
0
def _all_xonsh_parser(**kwargs):
    """
    Returns all history as found in XONSH_DATA_DIR.

    return format: (name, start_time, index)
    """
    data_dir = builtins.__xonsh_env__.get('XONSH_DATA_DIR')
    data_dir = expanduser_abs_path(data_dir)

    files = [os.path.join(data_dir, f) for f in os.listdir(data_dir)
             if f.startswith('xonsh-') and f.endswith('.json')]
    file_hist = []
    for f in files:
        try:
            json_file = LazyJSON(f, reopen=False)
            file_hist.append(json_file.load()['cmds'])
        except ValueError:
            # Invalid json file
            pass
    commands = [(c['inp'][:-1] if c['inp'].endswith('\n') else c['inp'],
                 c['ts'][0])
                for commands in file_hist for c in commands if c]
    commands.sort(key=operator.itemgetter(1))
    return [(c, t, ind) for ind, (c, t) in enumerate(commands)]
Ejemplo n.º 35
0
def test_lazy_str():
    f = StringIO()
    dump('wakka', f)
    f.seek(0)
    lj = LazyJSON(f)
    assert_equal('wakka', lj.load())
Ejemplo n.º 36
0
def test_lazy_str():
    f = StringIO()
    dump('wakka', f)
    f.seek(0)
    lj = LazyJSON(f)
    assert_equal('wakka', lj.load())
Ejemplo n.º 37
0
def test_lazy_int():
    f = StringIO()
    dump(42, f)
    f.seek(0)
    lj = LazyJSON(f)
    assert_equal(42, lj.load())
Ejemplo n.º 38
0
def test_lazy_int():
    f = StringIO()
    dump(42, f)
    f.seek(0)
    lj = LazyJSON(f)
    assert_equal(42, lj.load())
Ejemplo n.º 39
0
def test_lazy_int():
    f = StringIO()
    ljdump(42, f)
    f.seek(0)
    lj = LazyJSON(f)
    assert 42 == lj.load()
Ejemplo n.º 40
0
def test_lazy_str():
    f = StringIO()
    ljdump("wakka", f)
    f.seek(0)
    lj = LazyJSON(f)
    assert "wakka" == lj.load()
Ejemplo n.º 41
0
def test_lazy_str():
    f = StringIO()
    ljdump('wakka', f)
    f.seek(0)
    lj = LazyJSON(f)
    assert 'wakka' == lj.load()
Ejemplo n.º 42
0
def test_lazy_str():
    f = StringIO()
    ljdump('wakka', f)
    f.seek(0)
    lj = LazyJSON(f)
    assert 'wakka' ==  lj.load()
Ejemplo n.º 43
0
def test_lazy_str():
    f = StringIO()
    ljdump("wakka", f)
    f.seek(0)
    lj = LazyJSON(f)
    assert "wakka" == lj.load()
Ejemplo n.º 44
0
def test_lazy_int():
    f = StringIO()
    ljdump(42, f)
    f.seek(0)
    lj = LazyJSON(f)
    assert 42 == lj.load()