# encoding: utf-8

from __future__ import unicode_literals

from argparse import ArgumentError, ArgumentParser, ArgumentTypeError

import pytest

from pathvalidate.argparse import filename, filepath


class Test_argparse_filename_validator(object):
    @pytest.mark.parametrize(["value"], [["abc"], ["abc.txt"]])
    def test_normal(self, value):
        parser = ArgumentParser()
        parser.add_argument("filename", type=filename)

        assert parser.parse_args([value])
        assert filename(value)

    @pytest.mark.parametrize(["value"], [["foo/abc"], ["a?c"], ["COM1"], ["a" * 8000]])
    def test_exception(self, value):
        parser = ArgumentParser()
        parser.add_argument("filename", type=filename)

        try:
            parser.parse_args([value])
        except SystemExit as e:
            assert isinstance(e.__context__, ArgumentError)
        else:
            raise RuntimeError()

        with pytest.raises(ArgumentTypeError):
            filename(value)


class Test_argparse_filepath_validator(object):
    @pytest.mark.parametrize(["value"], [["foo/abc"], ["foo/abc.txt"]])
    def test_normal(self, value):
        parser = ArgumentParser()
        parser.add_argument("filepath", type=filepath)

        assert parser.parse_args([value])
        assert filepath(value)

    @pytest.mark.parametrize(["value"], [["foo/a?c"], ["COM1"], ["a" * 8000]])
    def test_exception(self, value):
        parser = ArgumentParser()
        parser.add_argument("filepath", type=filepath)

        try:
            parser.parse_args([value])
        except SystemExit as e:
            assert isinstance(e.__context__, ArgumentError)
        else:
            raise RuntimeError()

        with pytest.raises(ArgumentTypeError):
            filepath(value)

@@ -53,16 +53,27 @@
 terals%0A%0A
+import sys%0A
 from arg
@@ -722,32 +722,73 @@
 type=filename)%0A%0A
+        if sys.version_info%5B0%5D %3E= 3:%0A    
         try:%0A   
@@ -776,32 +776,36 @@
            try:%0A
+    
             pars
@@ -827,32 +827,36 @@
 value%5D)%0A        
+    
 except SystemExi
@@ -867,32 +867,36 @@
  e:%0A            
+   
+ 
 assert isinstanc
@@ -927,38 +927,46 @@
 tError)%0A        
+    
 else:%0A
+    
             rais
@@ -983,32 +983,36 @@
 rror()%0A%0A        
+    
 with pytest.rais
@@ -1026,32 +1026,36 @@
 mentTypeError):%0A
+    
             file
@@ -1584,32 +1584,73 @@
 type=filepath)%0A%0A
+        if sys.version_info%5B0%5D %3E= 3:%0A    
         try:%0A   
@@ -1638,32 +1638,36 @@
            try:%0A
+    
             pars
@@ -1689,32 +1689,36 @@
 value%5D)%0A        
+ 
+   
 except SystemExi
@@ -1717,32 +1717,36 @@
 ystemExit as e:%0A
+    
             asse
@@ -1789,38 +1789,46 @@
 tError)%0A        
+    
 else:%0A
+    
             rais

Fix test cases for Python 2