Skip to content

Commit

Permalink
Update test runner for more resilience (#1491)
Browse files Browse the repository at this point in the history
- Autodetects vim versions, but asserts that they are as expected
- not fail silently on issues with sending data to Vim.

Code by @mymedia2, superseeds #1474.
  • Loading branch information
SirVer authored Oct 2, 2022
1 parent 1914ef2 commit b78f4b1
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 20 deletions.
6 changes: 3 additions & 3 deletions test/test_ContextSnippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ class ContextSnippets_Before(_VimTest):
endsnippet
"""
}
word = 'Süßölgefäß'
keys = "adup" + EX + '\n' + word + 'dup' + EX
wanted = "adup" + EX + '\n' + word +'[' + word + ']'
word = "Süßölgefäß"
keys = "adup" + EX + "\n" + word + "dup" + EX
wanted = "adup" + EX + "\n" + word + "[" + word + "]"


class ContextSnippets_UseContext(_VimTest):
Expand Down
9 changes: 6 additions & 3 deletions test/test_Fixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,13 @@ def _before_test(self):
class PassThroughNonexecutedTrigger(_VimTest):
snippets = ("text", "Expand me!", "", "")
keys = (
"tex" + EX + # this should be passed through
"more\n" +
"text" + EX # this should be expanded
"tex"
+ EX
+ "more\n" # this should be passed through
+ "text"
+ EX # this should be expanded
)
wanted = "tex" + EX + "more\nExpand me!"


# End: #1184
4 changes: 2 additions & 2 deletions test/test_Interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ class TabStop_Shell_ShebangPython(_VimTest):
snippets = (
"test",
"""Hallo ${1:now `#!/usr/bin/env %s
print "Hallo Welt"
print("Hallo Welt")
`} end"""
% (os.environ.get("PYTHON", "python2"),),
% os.environ.get("PYTHON", "python3"),
)
keys = "test" + EX + JF + "and more"
wanted = "Hallo now Hallo Welt endand more"
Expand Down
13 changes: 5 additions & 8 deletions test/vim_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def wait_until_file_exists(file_path, times=None, interval=0.01):


def _read_text_file(filename):
"""Reads the contens of a text file."""
"""Reads the content of a text file."""
with open(filename, "r", encoding="utf-8") as to_read:
return to_read.read()

Expand All @@ -39,11 +39,6 @@ def is_process_running(pid):
return True


def silent_call(cmd):
"""Calls 'cmd' and returns the exit value."""
return subprocess.call(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE)


def create_directory(dirname):
"""Creates 'dirname' and its parents if it does not exist."""
try:
Expand Down Expand Up @@ -174,9 +169,11 @@ def _send(self, s):
s = s.replace(";", r"\;")

if len(s) == 1:
silent_call(["tmux", "send-keys", "-t", self.session, hex(ord(s))])
subprocess.check_call(
["tmux", "send-keys", "-t", self.session, hex(ord(s))]
)
else:
silent_call(["tmux", "send-keys", "-t", self.session, "-l", s])
subprocess.check_call(["tmux", "send-keys", "-t", self.session, "-l", s])

def send_to_terminal(self, s):
return self._send(s)
Expand Down
21 changes: 17 additions & 4 deletions test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,27 @@ def main():

all_test_suites = unittest.defaultTestLoader.discover(start_dir="test")

vim = None
vim_flavor = "vim"
has_nvim = subprocess.check_output(
[options.vim, "-e", "-s", "-c", "verbose echo has('nvim')", "+q"],
stderr=subprocess.STDOUT,
)
if has_nvim == b"0":
vim_flavor = "vim"
elif has_nvim == b"1":
vim_flavor = "neovim"
else:
assert 0, "Unexpected output, has_nvim=%r" % has_nvim

if options.interface == "tmux":
assert vim_flavor == "vim", (
"Interface is tmux, but vim_flavor is %s" % vim_flavor
)
vim = VimInterfaceTmux(options.vim, options.session)
vim_flavor = "vim"
else:
assert vim_flavor == "neovim", (
"Interface is TmuxNeovim, but vim_flavor is %s" % vim_flavor
)
vim = VimInterfaceTmuxNeovim(options.vim, options.session)
vim_flavor = "neovim"

if not options.clone_plugins and platform.system() == "Windows":
raise RuntimeError(
Expand Down

0 comments on commit b78f4b1

Please sign in to comment.