import unittest, sys

from HARK.validators import non_empty

class ValidatorsTests(unittest.TestCase):
    '''
    Tests for validator decorators which validate function arguments
    '''

    def test_non_empty(self):
        @non_empty('list_a')
        def foo(list_a, list_b):
            pass

        try:
            foo([1], [])
        except Exception:
            self.fail()
            
        if sys.version[0] == '2':
            with self.assertRaisesRegexp(
                TypeError,
                'Expected non-empty argument for parameter list_a',
            ):
                foo([], [1])
        else:            
            with self.assertRaisesRegex(
                TypeError,
                'Expected non-empty argument for parameter list_a',
            ):
                foo([], [1])

        @non_empty('list_a', 'list_b')
        def foo(list_a, list_b):
            pass

        with self.assertRaisesRegex(
            TypeError,
            'Expected non-empty argument for parameter list_b',
        ):
            foo([1], [])
        with self.assertRaisesRegex(
            TypeError,
            'Expected non-empty argument for parameter list_a',
        ):
            foo([], [1])

import unittest, sys

from HARK.validators import non_empty

class ValidatorsTests(unittest.TestCase):
    '''
    Tests for validator decorators which validate function arguments
    '''

    def test_non_empty(self):
        @non_empty('list_a')
        def foo(list_a, list_b):
            pass

        try:
            foo([1], [])
        except Exception:
            self.fail()
            
        if sys.version[0] == '2':
            with self.assertRaisesRegexp(
                TypeError,
                'Expected non-empty argument for parameter list_a',
            ):
                foo([], [1])
        else:            
            with self.assertRaisesRegex(
                TypeError,
                'Expected non-empty argument for parameter list_a',
            ):
                foo([], [1])

        @non_empty('list_a', 'list_b')
        def foo(list_a, list_b):
            pass

        if sys.version[0] == '2':
            with self.assertRaisesRegexp(
                TypeError,
                'Expected non-empty argument for parameter list_b',
            ):
                foo([1], [])
            with self.assertRaisesRegexp(
                TypeError,
                'Expected non-empty argument for parameter list_a',
            ):
                foo([], [1])
        else:   
            with self.assertRaisesRegex(
                TypeError,
                'Expected non-empty argument for parameter list_b',
            ):
                foo([1], [])
            with self.assertRaisesRegex(
                TypeError,
                'Expected non-empty argument for parameter list_a',
            ):
                foo([], [1])

Fix other tests with same regexp issue
Fix other tests with same regexp issue
  import unittest, sys
  
  from HARK.validators import non_empty
  
  class ValidatorsTests(unittest.TestCase):
      '''
      Tests for validator decorators which validate function arguments
      '''
  
      def test_non_empty(self):
          @non_empty('list_a')
          def foo(list_a, list_b):
              pass
  
          try:
              foo([1], [])
          except Exception:
              self.fail()
              
          if sys.version[0] == '2':
              with self.assertRaisesRegexp(
                  TypeError,
                  'Expected non-empty argument for parameter list_a',
              ):
                  foo([], [1])
          else:            
              with self.assertRaisesRegex(
                  TypeError,
                  'Expected non-empty argument for parameter list_a',
              ):
                  foo([], [1])
  
          @non_empty('list_a', 'list_b')
          def foo(list_a, list_b):
              pass
  
+         if sys.version[0] == '2':
-         with self.assertRaisesRegex(
+             with self.assertRaisesRegexp(
-             TypeError,
+                 TypeError,
-             'Expected non-empty argument for parameter list_b',
+                 'Expected non-empty argument for parameter list_b',
-         ):
+             ):
-             foo([1], [])
+                 foo([1], [])
-         with self.assertRaisesRegex(
+             with self.assertRaisesRegexp(
-             TypeError,
+                 TypeError,
-             'Expected non-empty argument for parameter list_a',
+                 'Expected non-empty argument for parameter list_a',
-         ):
+             ):
-             foo([], [1])
+                 foo([], [1])
+         else:   
+             with self.assertRaisesRegex(
+                 TypeError,
+                 'Expected non-empty argument for parameter list_b',
+             ):
+                 foo([1], [])
+             with self.assertRaisesRegex(
+                 TypeError,
+                 'Expected non-empty argument for parameter list_a',
+             ):
+                 foo([], [1])
  
Fix other tests with same regexp issue
## Code Before:
import unittest, sys

from HARK.validators import non_empty

class ValidatorsTests(unittest.TestCase):
    '''
    Tests for validator decorators which validate function arguments
    '''

    def test_non_empty(self):
        @non_empty('list_a')
        def foo(list_a, list_b):
            pass

        try:
            foo([1], [])
        except Exception:
            self.fail()
            
        if sys.version[0] == '2':
            with self.assertRaisesRegexp(
                TypeError,
                'Expected non-empty argument for parameter list_a',
            ):
                foo([], [1])
        else:            
            with self.assertRaisesRegex(
                TypeError,
                'Expected non-empty argument for parameter list_a',
            ):
                foo([], [1])

        @non_empty('list_a', 'list_b')
        def foo(list_a, list_b):
            pass

        with self.assertRaisesRegex(
            TypeError,
            'Expected non-empty argument for parameter list_b',
        ):
            foo([1], [])
        with self.assertRaisesRegex(
            TypeError,
            'Expected non-empty argument for parameter list_a',
        ):
            foo([], [1])

## Instruction:
Fix other tests with same regexp issue
## Code After:
import unittest, sys

from HARK.validators import non_empty

class ValidatorsTests(unittest.TestCase):
    '''
    Tests for validator decorators which validate function arguments
    '''

    def test_non_empty(self):
        @non_empty('list_a')
        def foo(list_a, list_b):
            pass

        try:
            foo([1], [])
        except Exception:
            self.fail()
            
        if sys.version[0] == '2':
            with self.assertRaisesRegexp(
                TypeError,
                'Expected non-empty argument for parameter list_a',
            ):
                foo([], [1])
        else:            
            with self.assertRaisesRegex(
                TypeError,
                'Expected non-empty argument for parameter list_a',
            ):
                foo([], [1])

        @non_empty('list_a', 'list_b')
        def foo(list_a, list_b):
            pass

        if sys.version[0] == '2':
            with self.assertRaisesRegexp(
                TypeError,
                'Expected non-empty argument for parameter list_b',
            ):
                foo([1], [])
            with self.assertRaisesRegexp(
                TypeError,
                'Expected non-empty argument for parameter list_a',
            ):
                foo([], [1])
        else:   
            with self.assertRaisesRegex(
                TypeError,
                'Expected non-empty argument for parameter list_b',
            ):
                foo([1], [])
            with self.assertRaisesRegex(
                TypeError,
                'Expected non-empty argument for parameter list_a',
            ):
                foo([], [1])
