import unittest
from pathlib import Path
import json
import subprocess


class TestCLI(unittest.TestCase):
    def test_exec_vint_with_valid_file_on_project_root(self):
        valid_file = str(Path('test', 'fixture', 'cli', 'valid1.vim'))
        cmd = ['vint', valid_file]

        got_output = subprocess.check_output(cmd, universal_newlines=True)

        expected_output = ''
        self.assertEqual(got_output, expected_output)


    def test_exec_vint_with_invalid_file_on_project_root(self):
        invalid_file = str(Path('test', 'fixture', 'cli', 'invalid1.vim'))
        cmd = ['vint', invalid_file]

        with self.assertRaises(subprocess.CalledProcessError) as context_manager:
            subprocess.check_output(cmd, universal_newlines=True)

        got_output = context_manager.exception.output

        expected_output_pattern = '{file_path}:1:13:'.format(file_path=invalid_file)
        self.assertRegexpMatches(got_output, expected_output_pattern)


    def test_exec_vint_with_no_args(self):
        cmd = ['vint']

        with self.assertRaises(subprocess.CalledProcessError) as context_manager:
            subprocess.check_output(cmd, universal_newlines=True)

        got_output = context_manager.exception.output

        self.assertTrue(got_output.startswith('vint error:'))


    def test_exec_vint_with_unexistent_file(self):
        cmd = ['vint', '/path/to/unexistent']

        with self.assertRaises(subprocess.CalledProcessError) as context_manager:
            subprocess.check_output(cmd, universal_newlines=True)

        got_output = context_manager.exception.output

        self.assertTrue(got_output.startswith('vint error:'))


    def test_exec_vint_with_stat_flag(self):
        invalid_file = str(Path('test', 'fixture', 'cli', 'invalid1.vim'))
        cmd = ['vint', '--stat', invalid_file]

        with self.assertRaises(subprocess.CalledProcessError) as context_manager:
            subprocess.check_output(cmd, universal_newlines=True)

        got_output = context_manager.exception.output

        expected_output_pattern = '{file_path}:1:13:'.format(file_path=invalid_file)
        expected_stat_pattern = 'Total'
        self.assertRegexpMatches(got_output, expected_output_pattern)
        self.assertRegexpMatches(got_output, expected_stat_pattern)


    def test_exec_vint_with_json_flag(self):
        invalid_file = str(Path('test', 'fixture', 'cli', 'invalid1.vim'))
        cmd = ['vint', '--json', invalid_file]

        with self.assertRaises(subprocess.CalledProcessError) as context_manager:
            subprocess.check_output(cmd, universal_newlines=True)

        got_output = context_manager.exception.output

        self.assertIsInstance(json.loads(got_output), list)


    @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 = ['vint', '--color', invalid_file]

        with self.assertRaises(subprocess.CalledProcessError) as context_manager:
            subprocess.check_output(cmd, universal_newlines=True)

        got_output = context_manager.exception.output

        expected_output_pattern = '\\033\['
        self.assertRegexpMatches(got_output, expected_output_pattern)


if __name__ == '__main__':
    unittest.main()

@@ -100,16 +100,294 @@
 tCase):%0A
+    def assertRegex(self, string, pattern):%0A        assertRegexpMatches = getattr(self, 'assertRegexpMatches', None)%0A        if assertRegexpMatches:%0A            assertRegexpMatches(string, pattern)%0A            return%0A%0A        super(TestCLI, self).assertRegex(string, pattern)%0A%0A%0A
     def 
@@ -1194,32 +1194,24 @@
 .assertRegex
-pMatches
 (got_output,
@@ -1419,32 +1419,130 @@
 heck_output(cmd,
+%0A                                    stderr=subprocess.STDOUT,%0A                                   
  universal_newli
@@ -1599,32 +1599,82 @@
 ception.output%0A%0A
+        expected_output_pattern = r'%5Evint ERROR:'%0A
         self.ass
@@ -1668,36 +1668,37 @@
      self.assert
-True
+Regex
 (got_output.star
@@ -1696,34 +1696,33 @@
 tput
-.startswith('vint error:')
+, expected_output_pattern
 )%0A%0A%0A
@@ -1933,32 +1933,130 @@
 heck_output(cmd,
+%0A                                    stderr=subprocess.STDOUT,%0A                                   
  universal_newli
@@ -2113,32 +2113,82 @@
 ception.output%0A%0A
+        expected_output_pattern = r'%5Evint ERROR:'%0A
         self.ass
@@ -2190,20 +2190,21 @@
 f.assert
-True
+Regex
 (got_out
@@ -2210,34 +2210,33 @@
 tput
-.startswith('vint error:')
+, expected_output_pattern
 )%0A%0A%0A
@@ -2517,32 +2517,130 @@
 heck_output(cmd,
+%0A                                    stderr=subprocess.STDOUT,%0A                                   
  universal_newli
@@ -2850,32 +2850,24 @@
 .assertRegex
-pMatches
 (got_output,
@@ -2912,32 +2912,24 @@
 .assertRegex
-pMatches
 (got_output,
@@ -3236,32 +3236,130 @@
 heck_output(cmd,
+%0A                                    stderr=subprocess.STDOUT,%0A                                   
  universal_newli
@@ -3482,24 +3482,497 @@
 t), list)%0A%0A%0A
+    def test_exec_vint_with_verbose_flag(self):%0A        valid_file = str(Path('test', 'fixture', 'cli', 'valid1.vim'))%0A        cmd = %5B'vint', '--verbose', valid_file%5D%0A%0A        got_output = subprocess.check_output(cmd,%0A                                             universal_newlines=True,%0A                                             stderr=subprocess.STDOUT)%0A%0A        expected_output_pattern = r'%5Evint INFO:'%0A        self.assertRegex(got_output, expected_output_pattern)%0A%0A%0A
     @unittes
@@ -4458,24 +4458,16 @@
 ertRegex
-pMatches
 (got_out

Add test for --verbose