From d3793a3f991087e0a1da5baa796492e1b43327b7 Mon Sep 17 00:00:00 2001 From: Konstantinos Tsakiltzidis Date: Tue, 2 Aug 2016 15:59:11 +0300 Subject: [PATCH] catch errors when calling _hist_get --- tests/test_tools.py | 10 ++++------ xonsh/history.py | 27 ++++++++++++++------------- xonsh/tools.py | 5 ++++- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/tests/test_tools.py b/tests/test_tools.py index 6709bde67..bf07e2cc6 100644 --- a/tests/test_tools.py +++ b/tests/test_tools.py @@ -1,10 +1,11 @@ # -*- coding: utf-8 -*- """Tests xonsh tools.""" +import builtins +import datetime as dt import os import pathlib -from tempfile import TemporaryDirectory import stat -import builtins +from tempfile import TemporaryDirectory import pytest @@ -1123,12 +1124,9 @@ def test_expandvars(inp, exp, xonsh_builtins): assert expandvars(inp) == exp -import time - - @pytest.mark.parametrize('inp, exp',[ (572392800.0, 572392800.0), - + (dt.datetime(2016, 8, 2, 13, 24), dt.datetime(2016, 8, 2, 13, 24).timestamp()), ]) def test_ensure_timestamp(inp, exp): obs = ensure_timestamp(inp) diff --git a/xonsh/history.py b/xonsh/history.py index 78d4ba821..a2172b901 100644 --- a/xonsh/history.py +++ b/xonsh/history.py @@ -453,22 +453,23 @@ def _hist_show(ns, *args, **kwargs): """Show the requested portion of shell history. Accepts same parameters with `_hist_get`. """ - commands = _hist_get(ns.session, - slices=ns.slices, - start_time=ns.start_time, - end_time=ns.end_time, - **kwargs) try: - if ns.reverse: - commands = reversed(list(commands)) - if not ns.numerate: - for c, _, _ in commands: - print(c) - else: - for c, _, i in commands: - print('{}: {}'.format(i, c)) + commands = _hist_get(ns.session, + slices=ns.slices, + start_time=ns.start_time, + end_time=ns.end_time, + **kwargs) except ValueError as err: print("history: error: {}".format(err), file=sys.stderr) + return + if ns.reverse: + commands = reversed(list(commands)) + if not ns.numerate: + for c, _, _ in commands: + print(c) + else: + for c, _, i in commands: + print('{}: {}'.format(i, c)) # Interface to History diff --git a/xonsh/tools.py b/xonsh/tools.py index 511ed7260..eabbc2fd6 100644 --- a/xonsh/tools.py +++ b/xonsh/tools.py @@ -1588,6 +1588,9 @@ def iglobpath(s, ignore_case=False, sort_result=None): def ensure_timestamp(t): - t = float(t) + try: + t = float(t) + except TypeError: + t = t.timestamp() return t