#4249 enable tests/test_lib for py2
Merged 15 days ago by tkopecek. Opened 3 months ago by julian8628.
julian8628/koji python2-test-lib  into  master

file modified
+4 -3
@@ -3820,13 +3820,14 @@ 

  

  

  def removeNonprintable(value):

+     # TODO: it's no more used in PY2

      # expects raw-encoded string, not unicode

      if six.PY2:

-         value = value.translate(None, NONPRINTABLE_CHARS)

+         return value.translate(None, NONPRINTABLE_CHARS)

      else:

          value = value.translate(NONPRINTABLE_CHARS_TABLE)

-     # remove broken unicode chars (some changelogs, etc.)

-     return value.encode('utf-8', errors='replace').decode()

+         # remove broken unicode chars (some changelogs, etc.)

+         return value.encode('utf-8', errors='replace').decode()

  

  

  def _fix_print(value):

file modified
+6 -3
@@ -803,9 +803,12 @@ 

      logger = logger or logging.getLogger('koji')

      try:

          st = os.lstat(path)

-     except FileNotFoundError:

-         logger.warning("No such file/dir %s for removal" % path)

-         return

+     except OSError as e:

+         # FileNotFoundError is N/A in py2

+         if e.errno == errno.ENOENT:

+             logger.warning("No such file/dir %s for removal" % path)

+             return

+         raise

      if not stat.S_ISDIR(st.st_mode):

          raise koji.GenericError("Not a directory: %s" % path)

      dev = st.st_dev

tests/test_hub/test_auth.py tests/test_lib/test_auth.py
file renamed
file was moved with no change to the file
empty or binary file added
tests/test_hub/test_db/test_bulkupdate_processor.py tests/test_hub/test_bulkupdate_processor.py
file renamed
file was moved with no change to the file
tests/test_hub/test_db/test_insert_processor.py tests/test_lib/test_insert_processor.py
file renamed
file was moved with no change to the file
tests/test_hub/test_db/test_query_processor.py tests/test_lib/test_query_processor.py
file renamed
file was moved with no change to the file
tests/test_hub/test_db/test_savepoint.py tests/test_lib/test_savepoint.py
file renamed
file was moved with no change to the file
tests/test_hub/test_db/test_update_processor.py tests/test_lib/test_update_processor.py
file renamed
file was moved with no change to the file
tests/test_hub/test_db/test_upsert_processor.py tests/test_hub/test_upsert_processor.py
file renamed
file was moved with no change to the file
@@ -234,6 +234,10 @@ 

  

      def test_MultiCallHack_weakref_validation(self):

          expected_exc = 'The session parameter must be a weak reference'

+         if six.PY2:

+             with self.assertRaisesRegexp(TypeError, expected_exc):

+                 koji.MultiCallHack(self.ksession)

+             return

          with self.assertRaisesRegex(TypeError, expected_exc):

              koji.MultiCallHack(self.ksession)

  

@@ -18,10 +18,10 @@ 

              if not fn.endswith('.data'):

                  continue

              path = os.path.join(datadir, fn)

-             with open(path, 'rt', encoding='utf-8') as fo:

+             with open(path, 'rt') as fo:

                  s = fo.read()

                  params = ast.literal_eval(s)

-             with open(path[:-5] + '.out', 'rt', encoding='utf-8') as fo:

+             with open(path[:-5] + '.out', 'rt') as fo:

                  expected = fo.read()

              output = koji.genMockConfig(**params)

              self.assertMultiLineEqual(output, expected)

@@ -7,11 +7,11 @@ 

  import unittest

  

  try:

-     import importlib

-     imp = None

- except ImportError:

      import imp

      importlib = None

+ except ImportError:

+     import importlib

+     imp = None

  

  import koji

  import koji.util

@@ -5,6 +5,8 @@ 

  import tempfile

  import unittest

  

+ import six

+ 

  import koji

  

  
@@ -31,6 +33,7 @@ 

          self.assertEqual(contents_signed, contents_spliced)

          self.assertNotEqual(contents_signed, contents_orig)

  

+     @unittest.skipIf(six.PY2, "Python 2 not supported")

      def test_splice_rpm_sighdr(self):

          contents_signed = open(self.signed, 'rb').read()

          sighdr = koji.rip_rpm_sighdr(self.signed)

file modified
+16 -4
@@ -316,9 +316,8 @@ 

  

      @patch('time.time')

      @patch('time.sleep')

-     @patch('signal.sigtimedwait')

      @patch('signal.pause')

-     def test_BaseTaskHandler_wait_timeout(self, pause, sigtimedwait, sleep, time):

+     def test_BaseTaskHandler_wait_timeout(self, pause, sleep, time):

          """Tests timeout behavior in the wait function"""

          temp_path = self.get_tmp_dir_path('TaskTest')

          obj = TaskTest(95, 'some_method', ['random_arg'], None, None, temp_path)
@@ -326,11 +325,18 @@ 

          obj.session = MagicMock()

          obj.session.host.taskWait.return_value = [[], [99, 100, 101]]

          time.side_effect = list(range(0, 4000, 60))

+         if six.PY3:

+             sigtimedwait = patch('signal.sigtimedwait').start()

+ 

          try:

              obj.wait([99, 100, 101], timeout=3600)

              raise Exception('A GenericError was not raised.')

          except koji.GenericError as e:

              self.assertEqual(e.args[0][:24], 'Subtasks timed out after')

+ 

+         if six.PY3:

+             sigtimedwait.stop()

+ 

          obj.session.host.taskSetWait.assert_called_once_with(95, [99, 100, 101])

          obj.session.cancelTaskChildren.assert_called_once_with(95)

          obj.session.getTaskResult.assert_not_called()
@@ -338,9 +344,8 @@ 

  

      @patch('time.time')

      @patch('time.sleep')

-     @patch('signal.sigtimedwait')

      @patch('signal.pause')

-     def test_BaseTaskHandler_wait_avoid_timeout(self, pause, sigtimedwait, sleep, time):

+     def test_BaseTaskHandler_wait_avoid_timeout(self, pause, sleep, time):

          """Tests that timeout does not happen if tasks finish in time"""

          temp_path = self.get_tmp_dir_path('TaskTest')

          obj = TaskTest(95, 'some_method', ['random_arg'], None, None, temp_path)
@@ -355,8 +360,15 @@ 

          # and then report all done

          taskWait_returns.append([[99, 100, 101], []])

          obj.session.host.taskWait.side_effect = taskWait_returns

+ 

+         if six.PY3:

+             sigtimedwait = patch('signal.sigtimedwait').start()

+ 

          obj.wait([99, 100, 101], timeout=3600)

  

+         if six.PY3:

+             sigtimedwait.stop()

+ 

          obj.session.host.taskSetWait.assert_called_once_with(95, [99, 100, 101])

          obj.session.cancelTaskChildren.assert_not_called()

          pause.assert_not_called()

file modified
+5 -2
@@ -739,7 +739,7 @@ 

  

      def _read_conf(self, cfile):

          path = os.path.dirname(__file__)

-         with open(path + cfile, 'rt', encoding='utf-8') as conf_file:

+         with open(path + cfile, 'rt') as conf_file:

              if six.PY2:

                  config = six.moves.configparser.SafeConfigParser()

                  config.readfp(conf_file)
@@ -1496,7 +1496,10 @@ 

          rmtree_nofork.assert_called_once()

          self.assertEqual(rmtree_nofork.call_args[0][0], path)

          _exit.assert_called_once()

-         logger = rmtree_nofork.call_args.kwargs['logger']

+         if mock.__package__ == 'unittest':

+             logger = rmtree_nofork.call_args.kwargs['logger']

+         else:

+             logger = rmtree_nofork.call_args[1]['logger']

  

      @mock.patch('tempfile.mkstemp')  # avoid stray temp file

      @mock.patch('koji.util._rmtree_nofork')

@@ -1,10 +1,16 @@ 

  # coding=utf-8

  from __future__ import absolute_import

- from six.moves import range

- import unittest

+ 

  import re

+ import sys

+ import unittest

+ try:

+     from unittest.mock import ANY

+ except ImportError:

+     from mock import ANY

  

  from six.moves import xmlrpc_client

+ 

  from koji import xmlrpcplus

  

  
@@ -98,6 +104,9 @@ 

                       'RegexNameInternal.compiled': re.compile('^[A-Za-z0-9/_.+-]+$')}

          dist_data_output = ({'MaxNameLengthInternal': 15,

                               'RegexNameInternal.compiled': "re.compile('^[A-Za-z0-9/_.+-]+$')"},)

+         if sys.version_info < (3, 7):

+             dist_data_output[0]['RegexNameInternal.compiled'] = ANY

+ 

          dict_data = (dict_data,)

          enc = xmlrpcplus.dumps(dict_data, methodresponse=1)

          params, method = xmlrpc_client.loads(enc)

file modified
+1 -1
@@ -57,7 +57,7 @@ 

      {envbindir}/coverage2 erase

  commands =

      {envbindir}/coverage2 run --source . -m pytest {posargs:\

-         tests/test_builder tests/test_cli \

+         tests/test_builder tests/test_cli tests/test_lib \

          tests/test_plugins/test_runroot_builder.py \

          tests/test_plugins/test_save_failed_tree_builder.py \

          tests/test_plugins/test_runroot_cli.py \

2 places in main code are changed
- py2 error in koji.removeNonprintable is fixed
- FileNotFoundError is replaced by OSError koji.util.rmtree for py2

fixes: #4248

Commit d1c0d77 fixes this pull-request

Pull-Request has been merged by tkopecek

15 days ago