From 2ab17b6ccaf48e136889d5097e8afff16e791d07 Mon Sep 17 00:00:00 2001 From: Aaron Schrab Date: Wed, 8 Aug 2012 19:11:20 -0400 Subject: [PATCH] Move getting buffer data into interface class Put the code that instructs vim to write its buffer to a temporary file and then reads that file into a python string into the VimInterface class. This will allow that to be done by code outside of tests. --- test.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/test.py b/test.py index 8d6ab56..35ea68c 100755 --- a/test.py +++ b/test.py @@ -74,6 +74,21 @@ class VimInterface: self.send(c) time.sleep(sleeptime) + def get_buffer_data(self): + handle, fn = tempfile.mkstemp(prefix="UltiSnips_Test",suffix=".txt") + os.close(handle) + os.unlink(fn) + + self.send(":w! %s\n" % fn) + + # Read the output, chop the trailing newline + tries = 50 + while tries: + if os.path.exists(fn): + return open(fn,"r").read()[:-1] + time.sleep(.05) + tries -= 1 + class VimInterfaceScreen(VimInterface): def __init__(self, session): self.session = session @@ -266,20 +281,7 @@ class _VimTest(unittest.TestCase): self._options_off() - handle, fn = tempfile.mkstemp(prefix="UltiSnips_Test",suffix=".txt") - os.close(handle) - os.unlink(fn) - - self.send(":w! %s\n" % fn) - - # Read the output, chop the trailing newline - tries = 50 - while tries: - if os.path.exists(fn): - self.output = open(fn,"r").read()[:-1] - break - time.sleep(.05) - tries -= 1 + self.output = self.vim.get_buffer_data() ########################################################################### # BEGINNING OF TEST #