From ebeb4bcdc0fd6c75e8d75a7d2f5514abe0aa0730 Mon Sep 17 00:00:00 2001 From: Anthony Scopatz Date: Sun, 23 Aug 2015 17:00:26 -0400 Subject: [PATCH] some more replay test fixes --- tests/test_replay.py | 9 ++++++--- xonsh/lazyjson.py | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/test_replay.py b/tests/test_replay.py index 245b23a03..64cfb49f8 100644 --- a/tests/test_replay.py +++ b/tests/test_replay.py @@ -12,7 +12,7 @@ from xonsh.shell import Shell from xonsh.replay import Replayer SHELL = Shell() - +HISTDIR = os.path.join(os.path.dirname(__file__), 'histories') def run_replay(re_file): with swap(builtins, '__xonsh_shell__', SHELL): @@ -27,6 +27,7 @@ def cleanup_replay(hist): if os.path.isfile(fname): os.remove(fname) + @contextmanager def a_replay(re_file): hist = run_replay(re_file) @@ -35,14 +36,16 @@ def a_replay(re_file): def test_echo(): - f = os.path.join('histories', 'echo.json') + f = os.path.join(HISTDIR, 'echo.json') with a_replay(f) as hist: yield assert_equal, 2, len(hist) + def test_reecho(): - f = os.path.join('histories', 'echo.json') + f = os.path.join(HISTDIR, 'echo.json') with a_replay(f) as hist: yield assert_equal, 2, len(hist) + if __name__ == '__main__': nose.runmodule() diff --git a/xonsh/lazyjson.py b/xonsh/lazyjson.py index fbf7298eb..bfa226b60 100644 --- a/xonsh/lazyjson.py +++ b/xonsh/lazyjson.py @@ -1,5 +1,6 @@ """Implements a lazy JSON file class that wraps around json data.""" from __future__ import print_function, unicode_literals +import io import weakref from contextlib import contextmanager from collections import Mapping, Sequence @@ -218,7 +219,7 @@ class LazyJSON(Node): def close(self): """Close the file handle, if appropriate.""" - if not self.reopen: + if not self.reopen and isinstance(self._f, io.IOBase): self._f.close() @contextmanager