File test-sys-executable.patch of Package python-vim-vint
From e02e67ddfbeebb76dafeff684e261873423b21f2 Mon Sep 17 00:00:00 2001
From: John Vandenberg <jayvdb@gmail.com>
Date: Mon, 25 Feb 2019 09:06:03 +0700
Subject: [PATCH] Create vint.__main__
Allow vint to be run using python -m vint, which
allows the CLI tests to run without the bin/vint,
and without vint being installed.
---
test/acceptance/test_cli.py | 21 +++++++++++----------
test/acceptance/test_cli_vital.py | 4 +++-
vint/__main__.py | 15 +++++++++++++++
3 files changed, 29 insertions(+), 11 deletions(-)
create mode 100644 vint/__main__.py
diff --git a/test/acceptance/test_cli.py b/test/acceptance/test_cli.py
index 46d639b..b20a587 100644
--- a/test/acceptance/test_cli.py
+++ b/test/acceptance/test_cli.py
@@ -2,6 +2,7 @@
from pathlib import Path
import json
import subprocess
+import sys
class TestCLI(unittest.TestCase):
@@ -16,7 +17,7 @@ def assertRegex(self, string, pattern):
def assertReturnedStdoutEqual(self, expected_stdout, cmd):
got_stdout = '(no stdout)'
-
+ cmd = [sys.executable, '-m'] + cmd
try:
got_stdout = subprocess.check_output(cmd, universal_newlines=True)
except subprocess.CalledProcessError as err:
@@ -29,7 +30,7 @@ def assertReturnedStdoutEqual(self, expected_stdout, cmd):
def test_exec_vint_with_valid_file_on_project_root(self):
valid_file = str(Path('test', 'fixture', 'cli', 'valid1.vim'))
- cmd = ['bin/vint', valid_file]
+ cmd = ['vint', valid_file]
expected_output = ''
@@ -38,7 +39,7 @@ def test_exec_vint_with_valid_file_on_project_root(self):
def test_exec_vint_with_valid_file_encoded_cp932_on_project_root(self):
valid_file = str(Path('test', 'fixture', 'cli', 'valid-cp932.vim'))
- cmd = ['bin/vint', valid_file]
+ cmd = ['vint', valid_file]
expected_output = ''
@@ -47,7 +48,7 @@ def test_exec_vint_with_valid_file_encoded_cp932_on_project_root(self):
def test_exec_vint_with_invalid_file_on_project_root(self):
invalid_file = str(Path('test', 'fixture', 'cli', 'invalid1.vim'))
- cmd = ['bin/vint', invalid_file]
+ cmd = [sys.executable, '-m', 'vint', invalid_file]
with self.assertRaises(subprocess.CalledProcessError) as context_manager:
subprocess.check_output(cmd, universal_newlines=True)
@@ -59,7 +60,7 @@ def test_exec_vint_with_invalid_file_on_project_root(self):
def test_exec_vint_with_no_args(self):
- cmd = ['bin/vint']
+ cmd = [sys.executable, '-m', 'vint']
with self.assertRaises(subprocess.CalledProcessError) as context_manager:
subprocess.check_output(cmd,
@@ -73,7 +74,7 @@ def test_exec_vint_with_no_args(self):
def test_exec_vint_with_unexistent_file(self):
- cmd = ['bin/vint', '/path/to/unexistent']
+ cmd = [sys.executable, '-m', 'vint', '/path/to/unexistent']
with self.assertRaises(subprocess.CalledProcessError) as context_manager:
subprocess.check_output(cmd,
@@ -88,7 +89,7 @@ def test_exec_vint_with_unexistent_file(self):
def test_exec_vint_with_stat_flag(self):
invalid_file = str(Path('test', 'fixture', 'cli', 'invalid1.vim'))
- cmd = ['bin/vint', '--stat', invalid_file]
+ cmd = [sys.executable, '-m', 'vint', '--stat', invalid_file]
with self.assertRaises(subprocess.CalledProcessError) as context_manager:
subprocess.check_output(cmd,
@@ -105,7 +106,7 @@ def test_exec_vint_with_stat_flag(self):
def test_exec_vint_with_json_flag(self):
invalid_file = str(Path('test', 'fixture', 'cli', 'invalid1.vim'))
- cmd = ['bin/vint', '--json', invalid_file]
+ cmd = [sys.executable, '-m', 'vint', '--json', invalid_file]
with self.assertRaises(subprocess.CalledProcessError) as context_manager:
# We should not capture STRERR because coverage plugin use it.
@@ -120,7 +121,7 @@ def test_exec_vint_with_json_flag(self):
def test_exec_vint_with_verbose_flag(self):
valid_file = str(Path('test', 'fixture', 'cli', 'valid1.vim'))
- cmd = ['bin/vint', '--verbose', valid_file]
+ cmd = [sys.executable, '-m', 'vint', '--verbose', valid_file]
got_output = subprocess.check_output(cmd,
universal_newlines=True,
@@ -133,7 +134,7 @@ def test_exec_vint_with_verbose_flag(self):
@unittest.skip('Does drone.io not like ANSI color?')
def test_exec_vint_with_color_flag(self):
invalid_file = str(Path('test', 'fixture', 'cli', 'invalid1.vim'))
- cmd = ['bin/vint', '--color', invalid_file]
+ cmd = [sys.executable, '-m', 'vint', '--color', invalid_file]
with self.assertRaises(subprocess.CalledProcessError) as context_manager:
subprocess.check_output(cmd, universal_newlines=True)
diff --git a/test/acceptance/test_cli_vital.py b/test/acceptance/test_cli_vital.py
index f8bca7d..151ade3 100644
--- a/test/acceptance/test_cli_vital.py
+++ b/test/acceptance/test_cli_vital.py
@@ -1,10 +1,12 @@
import unittest
from pathlib import Path
import subprocess
+import sys
class TestVintDoNotDiedWhenLintingVital(unittest.TestCase):
def assertVintStillAlive(self, cmd):
+ cmd = [sys.executable, '-m'] + cmd
try:
got_output = subprocess.check_output(cmd,
stderr=subprocess.STDOUT,
@@ -19,7 +21,7 @@ def assertVintStillAlive(self, cmd):
def test_survive_after_linting(self):
vital_dir = str(Path('test', 'fixture', 'cli', 'vital.vim'))
- cmd = ['bin/vint', vital_dir]
+ cmd = ['vint', vital_dir]
self.assertVintStillAlive(cmd)
diff --git a/vint/__main__.py b/vint/__main__.py
new file mode 100644
index 0000000..11f9c87
--- /dev/null
+++ b/vint/__main__.py
@@ -0,0 +1,15 @@
+from vint.bootstrap import (
+ init_logger,
+ init_linter,
+ init_cli,
+)
+
+
+def main():
+ init_logger()
+ init_linter()
+ init_cli()
+
+
+if __name__ == '__main__':
+ main()