#831 Use unittest2 for rhel6 compatibility
Merged 5 years ago by mikem. Opened 6 years ago by tkopecek.
tkopecek/koji issue830  into  master

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

              break

          except koji.ParameterError as e:

              if not err:

-                 err = e.message

+                 err = e.args[0]

      else:

          raise koji.ParameterError("Invalid signature for %s: %s" % (method, err))

  

file modified
+34 -36
@@ -251,39 +251,38 @@ 

          self.logger.info('New runroot')

          self.logger.info("Runroot mounts: %s" % mounts)

          fn = '%s/tmp/runroot_mounts' % rootdir

-         fslog = open(fn, 'a')

-         logfile = "%s/do_mounts.log" % self.workdir

-         uploadpath = self.getUploadDir()

-         error = None

-         for dev, path, type, opts in mounts:

-             if not path.startswith('/'):

-                 raise koji.GenericError("invalid mount point: %s" % path)

-             mpoint = "%s%s" % (rootdir, path)

-             if opts is None:

-                 opts = []

-             else:

-                 opts = opts.split(',')

-             if 'bind' in opts:

-                 #make sure dir exists

-                 if not os.path.isdir(dev):

-                     error = koji.GenericError("No such directory or mount: %s" % dev)

+         with open(fn, 'a') as fslog:

+             logfile = "%s/do_mounts.log" % self.workdir

+             uploadpath = self.getUploadDir()

+             error = None

+             for dev, path, type, opts in mounts:

+                 if not path.startswith('/'):

+                     raise koji.GenericError("invalid mount point: %s" % path)

+                 mpoint = "%s%s" % (rootdir, path)

+                 if opts is None:

+                     opts = []

+                 else:

+                     opts = opts.split(',')

+                 if 'bind' in opts:

+                     #make sure dir exists

+                     if not os.path.isdir(dev):

+                         error = koji.GenericError("No such directory or mount: %s" % dev)

+                         break

+                     type = 'none'

+                 if 'bg' in opts:

+                     error = koji.GenericError("bad config: background mount not allowed")

                      break

-                 type = 'none'

-             if 'bg' in opts:

-                 error = koji.GenericError("bad config: background mount not allowed")

-                 break

-             opts = ','.join(opts)

-             cmd = ['mount', '-t', type, '-o', opts, dev, mpoint]

-             self.logger.info("Mount command: %r" % cmd)

-             koji.ensuredir(mpoint)

-             status = log_output(self.session, cmd[0], cmd, logfile, uploadpath, logerror=True, append=True)

-             if not isSuccess(status):

-                 error = koji.GenericError("Unable to mount %s: %s" \

-                         % (mpoint, parseStatus(status, cmd)))

-                 break

-             fslog.write("%s\n" % mpoint)

-             fslog.flush()

-         fslog.close()

+                 opts = ','.join(opts)

+                 cmd = ['mount', '-t', type, '-o', opts, dev, mpoint]

+                 self.logger.info("Mount command: %r" % cmd)

+                 koji.ensuredir(mpoint)

+                 status = log_output(self.session, cmd[0], cmd, logfile, uploadpath, logerror=True, append=True)

+                 if not isSuccess(status):

+                     error = koji.GenericError("Unable to mount %s: %s" \

+                             % (mpoint, parseStatus(status, cmd)))

+                     break

+                 fslog.write("%s\n" % mpoint)

+                 fslog.flush()

          if error is not None:

              self.undo_mounts(rootdir, fatal=False)

              raise error
@@ -293,10 +292,9 @@ 

          mounts = set()

          fn = '%s/tmp/runroot_mounts' % rootdir

          if os.path.exists(fn):

-             fslog = open(fn, 'r')

-             for line in fslog.readlines():

-                 mounts.add(line.strip())

-             fslog.close()

+             with open(fn, 'r') as fslog:

+                 for line in fslog.readlines():

+                     mounts.add(line.strip())

          #also, check /proc/mounts just in case

          mounts |= set(scan_mounts(rootdir))

          mounts = sorted(mounts)

@@ -4,8 +4,10 @@ 

  import os

  import smtplib

  import tempfile

- import unittest

- 

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  import koji

  import koji.util

  from .loadkojid import kojid

@@ -3,8 +3,11 @@ 

  import mock

  import rpm

  import tempfile

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  import koji

- 

  from .loadkojid import kojid

  from six.moves import range

  

@@ -1,8 +1,10 @@ 

  from __future__ import absolute_import

  import inspect

  import mock

- import unittest

- 

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  import koji

  import koji.tasks

  

@@ -0,0 +1,30 @@ 

+ [image-build]

+ name = fedora-server-docker

+ version = 26

+ target = f26-candidate

+ install_tree = https://alt.fedoraproject.org/pub/alt/releases/26/Cloud/$arch/os/

+ arches = x86_64,ppc,arm64

+ can_fail=ppc,arm64

+ 

+ format = qcow2,rhevm-ova,vsphere-ova

+ distro = Fedora-26

+ repo = https://alt.fedoraproject.org/pub/alt/releases/26/Cloud/$arch/os/

+ disk_size = 20

+ 

+ ksversion = DEVEL

+ kickstart = fedora-26-server-docker.ks

+ ksurl = git://git.fedorahosted.org/git/spin-kickstarts.git?fedora26#68c40eb7

+ specfile = git://git.fedorahosted.org/git/spin-kickstarts.git?spec_templates/fedora26#68c40eb7

+ 

+ [ova-options]

+ vsphere_product_version=26

+ rhevm_description=Fedora Cloud 26

+ vsphere_product_vendor_name=Fedora Project

+ ovf_memory_mb=6144

+ rhevm_default_display_type=1

+ vsphere_product_name=Fedora Cloud 26

+ ovf_cpu_count=4

+ rhevm_os_descriptor=Fedora-26

+ 

+ [factory-parameters]

+ factory_test_ver=1.0

@@ -1,7 +1,10 @@ 

  import mock

  import shutil

  import tempfile

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  from koji_cli.lib import activate_session

  

@@ -1,12 +1,13 @@ 

  from __future__ import absolute_import

  

- 

  import mock

  import os

  import six

  import sys

- import unittest

- 

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  from koji_cli.commands import handle_add_group

  
@@ -108,7 +109,10 @@ 

          session.getTag.assert_not_called()

          session.getTagGroups.assert_not_called()

          session.groupListAdd.assert_not_called()

-         self.assertEqual(cm.exception.code, 2)

+         if isinstance(cm.exception, int):

+             self.assertEqual(cm.exception, 2)

+         else:

+             self.assertEqual(cm.exception.code, 2)

  

      @mock.patch('sys.stdout', new_callable=six.StringIO)

      @mock.patch('koji_cli.commands.activate_session')

@@ -1,6 +1,10 @@ 

  from __future__ import absolute_import

  import mock

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

+ 

  from koji_cli.commands import handle_add_group_pkg

  from . import utils

  

@@ -1,6 +1,10 @@ 

  from __future__ import absolute_import

  import mock

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

+ 

  from koji_cli.commands import handle_add_group_req

  from . import utils

  

@@ -3,7 +3,10 @@ 

  import os

  import six

  import sys

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  from koji_cli.commands import handle_add_host

  
@@ -125,7 +128,10 @@ 

          activate_session_mock.assert_not_called()

          session.hasHost.assert_not_called()

          session.addHost.assert_not_called()

-         self.assertEqual(cm.exception.code, 2)

+         if isinstance(cm.exception, int):

+             self.assertEqual(cm.exception, 2)

+         else:

+             self.assertEqual(cm.exception.code, 2)

  

      @mock.patch('sys.stdout', new_callable=six.StringIO)

      @mock.patch('koji_cli.commands.activate_session')

@@ -4,7 +4,10 @@ 

  import os

  import six

  import sys

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  from koji_cli.commands import handle_add_host_to_channel

  
@@ -193,7 +196,10 @@ 

          session.getChannel.assert_not_called()

          session.listChannels.assert_not_called()

          session.addHostToChannel.assert_not_called()

-         self.assertEqual(cm.exception.code, 2)

+         if isinstance(cm.exception, int):

+             self.assertEqual(cm.exception, 2)

+         else:

+             self.assertEqual(cm.exception.code, 2)

  

  

  if __name__ == '__main__':

@@ -1,7 +1,10 @@ 

  from __future__ import absolute_import

  import koji

  import mock

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  from six.moves import StringIO

  

  from koji_cli.commands import handle_add_notification

@@ -4,7 +4,10 @@ 

  import os

  import six

  import sys

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  from mock import call

  
@@ -172,7 +175,10 @@ 

          self.assertEqual(session.mock_calls,

                           [call.getUser(owner),

                            call.getTag(tag)])

-         self.assertEqual(cm.exception.code, 1)

+         if isinstance(cm.exception, int):

+             self.assertEqual(cm.exception, 1)

+         else:

+             self.assertEqual(cm.exception.code, 1)

  

      @mock.patch('sys.stdout', new_callable=six.StringIO)

      @mock.patch('sys.stderr', new_callable=six.StringIO)
@@ -210,7 +216,10 @@ 

          session.getTag.assert_not_called()

          session.listPackages.assert_not_called()

          session.packageListAdd.assert_not_called()

-         self.assertEqual(cm.exception.code, 2)

+         if isinstance(cm.exception, int):

+             self.assertEqual(cm.exception, 2)

+         else:

+             self.assertEqual(cm.exception.code, 2)

  

      @mock.patch('sys.stdout', new_callable=six.StringIO)

      @mock.patch('sys.stderr', new_callable=six.StringIO)
@@ -244,7 +253,10 @@ 

          session.getTag.assert_not_called()

          session.listPackages.assert_not_called()

          session.packageListAdd.assert_not_called()

-         self.assertEqual(cm.exception.code, 2)

+         if isinstance(cm.exception, int):

+             self.assertEqual(cm.exception, 2)

+         else:

+             self.assertEqual(cm.exception.code, 2)

  

  

  if __name__ == '__main__':

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

  from __future__ import absolute_import

  import mock

  import six

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

+ 

  from koji_cli.commands import handle_add_tag

  from . import utils

  

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

  from __future__ import absolute_import

  import mock

  import six

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

+ 

  from koji_cli.commands import handle_add_user

  from . import utils

  

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

  from __future__ import absolute_import

  import mock

  import six

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

+ 

  from koji_cli.commands import handle_add_volume

  from . import utils

  

@@ -3,9 +3,12 @@ 

  import os

  import six

  import sys

- import unittest

- import koji

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

+ import koji

  from koji_cli.commands import handle_assign_task

  

  
@@ -102,7 +105,10 @@ 

          activate_session_mock.assert_not_called()

          session.hasHost.assert_not_called()

          session.addHost.assert_not_called()

-         self.assertEqual(cm.exception.code, 2)

+         if isinstance(cm.exception, int):

+             self.assertEqual(cm.exception, 2)

+         else:

+             self.assertEqual(cm.exception.code, 2)

  

  

  if __name__ == '__main__':

@@ -1,6 +1,10 @@ 

  from __future__ import absolute_import

  import mock

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

+ 

  from koji_cli.commands import handle_block_group_pkg

  from . import utils

  

@@ -1,6 +1,10 @@ 

  from __future__ import absolute_import

  import mock

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

+ 

  from koji_cli.commands import handle_block_group_req

  from . import utils

  

@@ -3,7 +3,10 @@ 

  import os

  import six

  import sys

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  from mock import call

  
@@ -178,7 +181,10 @@ 

          session.getTag.assert_not_called()

          session.listPackages.assert_not_called()

          session.packageListBlock.assert_not_called()

-         self.assertEqual(cm.exception.code, 2)

+         if isinstance(cm.exception, int):

+             self.assertEqual(cm.exception, 2)

+         else:

+             self.assertEqual(cm.exception.code, 2)

  

  

  if __name__ == '__main__':

file modified
+28 -7
@@ -3,7 +3,10 @@ 

  import os

  import six

  import sys

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  from koji_cli.commands import handle_build, _progress_callback

  
@@ -162,7 +165,10 @@ 

          self.session.build.assert_not_called()

          self.session.logout.assert_not_called()

          watch_tasks_mock.assert_not_called()

-         self.assertEqual(cm.exception.code, 2)

+         if isinstance(cm.exception, int):

+             self.assertEqual(cm.exception, 2)

+         else:

+             self.assertEqual(cm.exception.code, 2)

  

      @mock.patch('sys.stdout', new_callable=six.StringIO)

      @mock.patch('sys.stderr', new_callable=six.StringIO)
@@ -218,7 +224,10 @@ 

          self.session.build.assert_not_called()

          self.session.logout.assert_not_called()

          watch_tasks_mock.assert_not_called()

-         self.assertEqual(cm.exception.code, 0)

+         if isinstance(cm.exception, int):

+             self.assertEqual(cm.exception, 0)

+         else:

+             self.assertEqual(cm.exception.code, 0)

  

      @mock.patch('sys.stdout', new_callable=six.StringIO)

      @mock.patch('sys.stderr', new_callable=six.StringIO)
@@ -264,7 +273,10 @@ 

          self.session.build.assert_not_called()

          self.session.logout.assert_not_called()

          watch_tasks_mock.assert_not_called()

-         self.assertEqual(cm.exception.code, 2)

+         if isinstance(cm.exception, int):

+             self.assertEqual(cm.exception, 2)

+         else:

+             self.assertEqual(cm.exception.code, 2)

  

      @mock.patch('sys.stdout', new_callable=six.StringIO)

      @mock.patch('koji_cli.commands.activate_session')
@@ -354,7 +366,10 @@ 

          self.session.build.assert_not_called()

          self.session.logout.assert_not_called()

          watch_tasks_mock.assert_not_called()

-         self.assertEqual(cm.exception.code, 2)

+         if isinstance(cm.exception, int):

+             self.assertEqual(cm.exception, 2)

+         else:

+             self.assertEqual(cm.exception.code, 2)

  

      @mock.patch('sys.stderr', new_callable=six.StringIO)

      @mock.patch('koji_cli.commands.activate_session')
@@ -402,7 +417,10 @@ 

          self.session.build.assert_not_called()

          self.session.logout.assert_not_called()

          watch_tasks_mock.assert_not_called()

-         self.assertEqual(cm.exception.code, 2)

+         if isinstance(cm.exception, int):

+             self.assertEqual(cm.exception, 2)

+         else:

+             self.assertEqual(cm.exception.code, 2)

  

      @mock.patch('sys.stderr', new_callable=six.StringIO)

      @mock.patch('koji_cli.commands.activate_session')
@@ -450,7 +468,10 @@ 

          self.session.build.assert_not_called()

          self.session.logout.assert_not_called()

          watch_tasks_mock.assert_not_called()

-         self.assertEqual(cm.exception.code, 2)

+         if isinstance(cm.exception, int):

+             self.assertEqual(cm.exception, 2)

+         else:

+             self.assertEqual(cm.exception.code, 2)

  

      @mock.patch('sys.stdout', new_callable=six.StringIO)

      @mock.patch('koji_cli.commands.activate_session')

file modified
+12 -6
@@ -1,8 +1,11 @@ 

  from __future__ import absolute_import

+ import json

  import mock

  import six

- import unittest

- import json

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  from koji_cli.commands import handle_call

  from . import utils
@@ -118,13 +121,16 @@ 

          }

  

          for mod, msg in module.items():

-             with mock.patch('koji_cli.commands.%s' % mod, new=None), \

-                  self.assertRaises(SystemExit) as cm:

-                 handle_call(options, session, arguments)

+             with mock.patch('koji_cli.commands.%s' % mod, new=None):

+                 with self.assertRaises(SystemExit) as cm:

+                     handle_call(options, session, arguments)

              expected = self.format_error_message(msg)

              self.assert_console_message(stderr, expected)

              activate_session_mock.assert_not_called()

-             self.assertEqual(cm.exception.code, 2)

+             if isinstance(cm.exception, int):

+                 self.assertEqual(cm.exception, 2)

+             else:

+                 self.assertEqual(cm.exception.code, 2)

  

      def test_handle_call_help(self):

          """Test handle_call help message"""

@@ -4,7 +4,10 @@ 

  import os

  import six

  import sys

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  from koji_cli.commands import handle_chain_build

  
@@ -119,7 +122,10 @@ 

          self.session.chainBuild.assert_not_called()

          self.session.logout.assert_not_called()

          watch_tasks_mock.assert_not_called()

-         self.assertEqual(cm.exception.code, 2)

+         if isinstance(cm.exception, int):

+             self.assertEqual(cm.exception, 2)

+         else:

+             self.assertEqual(cm.exception.code, 2)

  

      @mock.patch('sys.stdout', new_callable=six.StringIO)

      @mock.patch('sys.stderr', new_callable=six.StringIO)
@@ -163,7 +169,10 @@ 

          self.session.chainBuild.assert_not_called()

          self.session.logout.assert_not_called()

          watch_tasks_mock.assert_not_called()

-         self.assertEqual(cm.exception.code, 0)

+         if isinstance(cm.exception, int):

+             self.assertEqual(cm.exception, 0)

+         else:

+             self.assertEqual(cm.exception.code, 0)

  

      @mock.patch('sys.stderr', new_callable=six.StringIO)

      @mock.patch('koji_cli.commands.activate_session')
@@ -212,7 +221,10 @@ 

          self.session.chainBuild.assert_not_called()

          self.session.logout.assert_not_called()

          watch_tasks_mock.assert_not_called()

-         self.assertEqual(cm.exception.code, 2)

+         if isinstance(cm.exception, int):

+             self.assertEqual(cm.exception, 2)

+         else:

+             self.assertEqual(cm.exception.code, 2)

  

      @mock.patch('sys.stderr', new_callable=six.StringIO)

      @mock.patch('koji_cli.commands.activate_session')
@@ -271,7 +283,10 @@ 

          self.session.chainBuild.assert_not_called()

          self.session.logout.assert_not_called()

          watch_tasks_mock.assert_not_called()

-         self.assertEqual(cm.exception.code, 2)

+         if isinstance(cm.exception, int):

+             self.assertEqual(cm.exception, 2)

+         else:

+             self.assertEqual(cm.exception.code, 2)

  

      @mock.patch('sys.stdout', new_callable=six.StringIO)

      @mock.patch('koji_cli.commands.activate_session')
@@ -453,7 +468,10 @@ 

  If there are no dependencies, use the build command instead

  """ % (progname, progname)

              self.assertMultiLineEqual(actual, expected)

-             self.assertEqual(cm.exception.code, 2)

+             if isinstance(cm.exception, int):

+                 self.assertEqual(cm.exception, 2)

+             else:

+                 self.assertEqual(cm.exception.code, 2)

  

      @mock.patch('sys.stdout', new_callable=six.StringIO)

      @mock.patch('koji_cli.commands.activate_session')

@@ -1,7 +1,10 @@ 

  from __future__ import absolute_import

  import mock

  import six

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  from mock import call

  from koji_cli.commands import handle_disable_host

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

  from __future__ import absolute_import

  import mock

  import six

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

+ 

  from koji_cli.commands import handle_disable_user

  from . import utils

  

@@ -1,9 +1,13 @@ 

  from __future__ import absolute_import

  from __future__ import print_function

+ import copy

  import mock

  import six

- import unittest

- import copy

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

+ 

  

  from koji_cli.commands import handle_dist_repo

  from . import utils

@@ -3,7 +3,10 @@ 

  import six

  import shutil

  import tempfile

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  from koji_cli.lib import download_file, _download_progress

  
@@ -45,7 +48,11 @@ 

          actual = self.stdout.getvalue()

          expected = 'Downloading: %s\n' % self.tempdir

          self.assertMultiLineEqual(actual, expected)

-         self.assertEqual(cm.exception.args, (21, 'Is a directory'))

+         if isinstance(cm.exception, tuple):

+             self.assertEqual(cm.exception[0], 21)

+             self.assertEqual(cm.exception[1], 'Is a directory')

+         else:

+             self.assertEqual(cm.exception.args, (21, 'Is a directory'))

          self.requests_get.assert_called_once()

  

      @mock_open()

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

          out_file = six.StringIO()

          self.custom_open['kojilogs/x86_64-123456/volume1/file1.log'] = out_file

  

-         with mock.patch('koji_cli.commands.open', new=self.mock_builtin_open):

+         if six.PY2:

+             target = '__builtin__.open'

+         else:

+             target = 'builtins.open'

+         with mock.patch(target, new=self.mock_builtin_open):

              anon_handle_download_logs(self.options, self.session, [str(task_id)])

  

          self.session.getTaskInfo.assert_called_once_with(task_id)

@@ -4,7 +4,10 @@ 

  import os

  import six

  import sys

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  from koji_cli.commands import anon_handle_download_task

  
@@ -204,7 +207,10 @@ 

          self.session.getTaskChildren.assert_not_called()

          self.list_task_output_all_volumes.assert_called_once_with(self.session, task_id)

          self.download_file.assert_not_called()

-         self.assertEqual(cm.exception.code, 1)

+         if isinstance(cm.exception, int):

+             self.assertEqual(cm.exception, 1)

+         else:

+             self.assertEqual(cm.exception.code, 1)

  

      def test_handle_download_parent_not_finished(self):

          task_id = 123333
@@ -237,7 +243,10 @@ 

          self.session.getTaskChildren.assert_not_called()

          self.list_task_output_all_volumes.assert_called_once_with(self.session, task_id)

          self.download_file.assert_not_called()

-         self.assertEqual(cm.exception.code, 1)

+         if isinstance(cm.exception, int):

+             self.assertEqual(cm.exception, 1)

+         else:

+             self.assertEqual(cm.exception.code, 1)

  

      def test_handle_download_child_not_finished(self):

          task_id = 123333
@@ -268,7 +277,10 @@ 

          self.session.getTaskChildren.assert_called_once_with(task_id)

          self.list_task_output_all_volumes.assert_called_once_with(self.session, 22222)

          self.download_file.assert_not_called()

-         self.assertEqual(cm.exception.code, 1)

+         if isinstance(cm.exception, int):

+             self.assertEqual(cm.exception, 1)

+         else:

+             self.assertEqual(cm.exception.code, 1)

  

      def test_handle_download_invalid_file_name(self):

          task_id = 123333
@@ -295,7 +307,10 @@ 

          self.session.getTaskChildren.assert_not_called()

          self.list_task_output_all_volumes.assert_called_once_with(self.session, task_id)

          self.download_file.assert_not_called()

-         self.assertEqual(cm.exception.code, 1)

+         if isinstance(cm.exception, int):

+             self.assertEqual(cm.exception, 1)

+         else:

+             self.assertEqual(cm.exception.code, 1)

  

      def test_handle_download_help(self):

          args = ['--help']
@@ -321,7 +336,10 @@ 

          actual = self.stderr.getvalue()

          expected = ''

          self.assertEqual(actual, expected)

-         self.assertEqual(cm.exception.code, 0)

+         if isinstance(cm.exception, int):

+             self.assertEqual(cm.exception, 0)

+         else:

+             self.assertEqual(cm.exception.code, 0)

  

      def test_handle_download_no_task_id(self):

          args = []
@@ -340,7 +358,10 @@ 

  %s: error: Please specify a task ID

  """ % (progname, progname)

          self.assertEqual(actual, expected)

-         self.assertEqual(cm.exception.code, 2)

+         if isinstance(cm.exception, int):

+             self.assertEqual(cm.exception, 2)

+         else:

+             self.assertEqual(cm.exception.code, 2)

  

      def test_handle_download_multi_task_id(self):

          args = ["123", "456"]
@@ -359,7 +380,10 @@ 

  %s: error: Only one task ID may be specified

  """ % (progname, progname)

          self.assertEqual(actual, expected)

-         self.assertEqual(cm.exception.code, 2)

+         if isinstance(cm.exception, int):

+             self.assertEqual(cm.exception, 2)

+         else:

+             self.assertEqual(cm.exception.code, 2)

  

  

  if __name__ == '__main__':

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

  import os

  import six

  import sys

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

+ 

  from mock import call

  

  from koji_cli.commands import handle_edit_host
@@ -171,7 +175,10 @@ 

          session.getHost.assert_not_called()

          session.editHost.assert_not_called()

          session.multiCall.assert_not_called()

-         self.assertEqual(cm.exception.code, 2)

+         if isinstance(cm.exception, int):

+             self.assertEqual(cm.exception, 2)

+         else:

+             self.assertEqual(cm.exception.code, 2)

  

      @mock.patch('sys.stdout', new_callable=six.StringIO)

      @mock.patch('koji_cli.commands.activate_session')

@@ -1,7 +1,10 @@ 

  from __future__ import absolute_import

  import koji

  import mock

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  from six.moves import StringIO

  

  from koji_cli.commands import handle_edit_notification

@@ -3,8 +3,10 @@ 

  import os

  import six

  import sys

- import unittest

- 

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  from koji_cli.commands import handle_edit_tag

  
@@ -137,7 +139,10 @@ 

          # Finally, assert that things were called as we expected.

          activate_session_mock.assert_not_called()

          session.editTag2.assert_not_called()

-         self.assertEqual(cm.exception.code, 0)

+         if isinstance(cm.exception, int):

+             self.assertEqual(cm.exception, 2)

+         else:

+             self.assertEqual(cm.exception.code, 0)

  

      @mock.patch('sys.stdout', new_callable=six.StringIO)

      @mock.patch('sys.stderr', new_callable=six.StringIO)
@@ -167,7 +172,10 @@ 

          # Finally, assert that things were called as we expected.

          activate_session_mock.assert_not_called()

          session.editTag2.assert_not_called()

-         self.assertEqual(cm.exception.code, 2)

+         if isinstance(cm.exception, int):

+             self.assertEqual(cm.exception, 2)

+         else:

+             self.assertEqual(cm.exception.code, 2)

  

  

  if __name__ == '__main__':

@@ -1,7 +1,10 @@ 

  from __future__ import absolute_import

  import mock

  import six

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  from mock import call

  from koji_cli.commands import handle_enable_host

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

  from __future__ import absolute_import

  import mock

  import six

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

+ 

  from koji_cli.commands import handle_enable_user

  from . import utils

  

@@ -1,7 +1,10 @@ 

  from __future__ import absolute_import

  import mock

  import six

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  from koji_cli.commands import handle_grant_cg_access

  from . import utils

@@ -1,7 +1,10 @@ 

  from __future__ import absolute_import

  import mock

  import six

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  from koji_cli.commands import handle_grant_permission

  from . import utils

file modified
+5 -2
@@ -2,9 +2,12 @@ 

  from __future__ import absolute_import

  import mock

  import six

- import unittest

- import koji

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

+ import koji

  from koji_cli.commands import handle_moshimoshi, _printable_unicode

  from . import utils

  

@@ -2,16 +2,20 @@ 

  import mock

  import six

  import os

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

+ 

  import koji

  

  from koji_cli.commands import handle_image_build, _build_image_oz

  from . import utils

  

+ ConfigParser = six.moves.configparser.ConfigParser

  

  TASK_OPTIONS = {

      "background": None,

-     "config": "build-image-config.conf",

      "disk_size": "20",

      "distro": "Fedora-26",

      "factory_parameter": [
@@ -53,6 +57,13 @@ 

      "wait": None,

  }

  

+ def mock_open():

+     """Return the right patch decorator for open"""

+     if six.PY2:

+         return mock.patch('__builtin__.open')

+     else:

+         return mock.patch('builtins.open')

+ 

  

  class Options(object):

      def __init__(self, init_dict):
@@ -208,30 +219,10 @@ 

      # Show long diffs in error output...

      maxDiff = None

  

-     def mock_os_path_exists(self, filepath):

-         if filepath in self.custom_os_path_exists:

-             return self.custom_os_path_exists[filepath]

-         return self.os_path_exists(filepath)

- 

-     def mock_builtin_open(self, filepath, *args):

-         if filepath in self.custom_open:

-             return self.custom_open[filepath]

-         return self.builtin_open(filepath, *args)

- 

      def setUp(self):

-         self.os_path_exists = os.path.exists

-         self.custom_os_path_exists = {}

- 

-         self.builtin_open = None

-         if six.PY2:

-             self.builtin_open = __builtins__['open']

-         else:

-             import builtins

-             self.builtin_open = builtins.open

-         self.custom_open = {}

- 

          self.options = mock.MagicMock()

          self.session = mock.MagicMock()

+         self.configparser = mock.patch('six.moves.configparser.ConfigParser').start()

  

          self.error_format = """Usage: %s image-build [options] <name> <version> <target> <install-tree-url> <arch> [<arch>...]

         %s image-build --config FILE
@@ -241,80 +232,43 @@ 

  %s: error: {message}

  """ % (self.progname, self.progname, self.progname)

  

+     def tearDown(self):

+         mock.patch.stopall()

+ 

      @mock.patch('koji_cli.commands._build_image_oz')

      def test_handle_image_build_with_config(self, build_image_oz_mock):

          """Test handle_image_build argument with --config cases"""

  

          # Case 1, config file not exist case

-         config_file = "build-image-config.conf"

-         expected = "%s not found!" % config_file

- 

          self.assert_system_exit(

                  handle_image_build,

                  self.options,

                  self.session,

-                 ['--config', config_file],

-                 stderr=self.format_error_message(expected),

+                 ['--config', '/nonexistent-file-755684354'],

+                 stderr=self.format_error_message('/nonexistent-file-755684354 not found!'),

                  activate_session=None)

  

          # Case 2, no image-build section in config file

-         self.custom_os_path_exists[config_file] = True

-         self.custom_open[config_file] = six.StringIO('')

  

          expected = "single section called [%s] is required" % "image-build"

  

-         with mock.patch('os.path.exists', new=self.mock_os_path_exists), \

-                 mock.patch('koji_cli.commands.open', new=self.mock_builtin_open):

-             self.assert_system_exit(

-                 handle_image_build,

-                 self.options,

-                 self.session,

-                 ['--config', config_file],

-                 stderr=self.format_error_message(expected),

-                 activate_session=None)

- 

-         fake_config = """

- [image-build]

- name = fedora-server-docker

- version = 26

- target = f26-candidate

- install_tree = https://alt.fedoraproject.org/pub/alt/releases/26/Cloud/$arch/os/

- arches = x86_64,ppc,arm64

- can_fail=ppc,arm64

- 

- format = qcow2,rhevm-ova,vsphere-ova

- distro = Fedora-26

- repo = https://alt.fedoraproject.org/pub/alt/releases/26/Cloud/$arch/os/

- disk_size = 20

- 

- ksversion = DEVEL

- kickstart = fedora-26-server-docker.ks

- ksurl = git://git.fedorahosted.org/git/spin-kickstarts.git?fedora26#68c40eb7

- specfile = git://git.fedorahosted.org/git/spin-kickstarts.git?spec_templates/fedora26#68c40eb7

- 

- [ova-options]

- vsphere_product_version=26

- rhevm_description=Fedora Cloud 26

- vsphere_product_vendor_name=Fedora Project

- ovf_memory_mb=6144

- rhevm_default_display_type=1

- vsphere_product_name=Fedora Cloud 26

- ovf_cpu_count=4

- rhevm_os_descriptor=Fedora-26

- 

- [factory-parameters]

- factory_test_ver=1.0

- """

-         self.custom_open[config_file] = six.StringIO(fake_config)

- 

-         with mock.patch('os.path.exists', new=self.mock_os_path_exists), \

-                 mock.patch('koji_cli.commands.open', new=self.mock_builtin_open):

-             handle_image_build(

-                 self.options,

-                 self.session,

-                 ['--config', config_file])

+         self.configparser.return_value = ConfigParser()

+         self.assert_system_exit(

+             handle_image_build,

+             self.options,

+             self.session,

+             ['--config', '/dev/null'],

+             stderr=self.format_error_message(expected),

+             activate_session=None)

+ 

+         config_file = os.path.join(os.path.dirname(__file__), 'data/image-build-config.conf')

+         handle_image_build(

+             self.options,

+             self.session,

+             ['--config', config_file])

  

          args, kwargs = build_image_oz_mock.call_args

+         TASK_OPTIONS['config'] = config_file

          self.assertDictEqual(TASK_OPTIONS, args[1].__dict__)

  

      @mock.patch('koji_cli.commands.activate_session')

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

  from __future__ import absolute_import

  import mock

  import six

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

+ 

  import koji

  

  from koji_cli.commands import handle_image_build_indirection, _build_image_indirection
@@ -145,10 +149,10 @@ 

              setattr(self.task_opts, r, None)

              expected = "Missing the following required options: "

              expected += "--" + r.replace('_', '-') + "\n"

-             with self.assertRaises(koji.GenericError) as cm, \

-                     mock.patch('sys.stdout', new_callable=six.StringIO) as stdout:

-                 _build_image_indirection(

-                     self.options, self.task_opts, self.session, [])

+             with self.assertRaises(koji.GenericError) as cm:

+                 with  mock.patch('sys.stdout', new_callable=six.StringIO) as stdout:

+                     _build_image_indirection(

+                         self.options, self.task_opts, self.session, [])

              self.assert_console_message(stdout, expected)

              self.assertEqual(

                  str(cm.exception), "Missing required options specified above")

file modified
+31 -23
@@ -1,13 +1,21 @@ 

  from __future__ import absolute_import

  import mock

- import six

- import unittest

- import koji

  import os

+ import six

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

+ import koji

  from koji_cli.commands import handle_import

  from . import utils

  

+ def md5_to_bytes(s):

+     if six.PY2:

+         return bytearray.fromhex(unicode(s))

+     else:

+         return bytearray.fromhex(s)

  

  class TestImport(utils.CliTestCase):

  
@@ -46,7 +54,7 @@ 

          self.srpm_header = {

              'sourcepackage': 1,

              'name': 'bash',

-             'sigmd5': bytearray.fromhex(self.md5),

+             'sigmd5': md5_to_bytes(self.md5),

              'epoch': None,

              'version': '4.4.12',

              'release': '5.fc26',
@@ -57,7 +65,7 @@ 

          self.rpm_header = {

              'sourcepackage': None,

              'name': 'bash',

-             'sigmd5': bytearray.fromhex(self.md5),

+             'sigmd5': md5_to_bytes(self.md5),

              'epoch': None,

              'version': '4.4.12',

              'release': '5.fc26',
@@ -86,14 +94,14 @@ 

          fake_srv_path = kwargs.get('srv_path', '/path/to/server/import')

          upload_rpm_mock = kwargs.get('upload_rpm_mock', session.uploadWrapper)

  

-         with mock.patch('koji.get_header_fields') as get_header_fields_mock, \

-                 mock.patch('koji_cli.commands._unique_path') as unique_path_mock, \

-                 mock.patch('koji_cli.commands.activate_session') as activate_session_mock, \

-                 mock.patch('sys.stdout', new_callable=six.StringIO) as stdout, \

-                 upload_rpm_mock:

-             get_header_fields_mock.return_value = rpm_header

-             unique_path_mock.return_value = fake_srv_path

-             handle_import(options, session, arguments)

+         with mock.patch('koji.get_header_fields') as get_header_fields_mock:

+             with mock.patch('koji_cli.commands._unique_path') as unique_path_mock:

+                 with mock.patch('koji_cli.commands.activate_session') as activate_session_mock:

+                     with mock.patch('sys.stdout', new_callable=six.StringIO) as stdout:

+                         with upload_rpm_mock:

+                             get_header_fields_mock.return_value = rpm_header

+                             unique_path_mock.return_value = fake_srv_path

+                             handle_import(options, session, arguments)

  

          # check output message

          self.assert_console_message(stdout, expected)
@@ -128,11 +136,11 @@ 

          expected = kwargs.get('expected', None)

          rpm_header = kwargs.get('rpm_header', {})

  

-         with mock.patch('koji.get_header_fields') as get_header_fields_mock, \

-                 mock.patch('koji_cli.commands.activate_session') as activate_session_mock, \

-                 mock.patch('sys.stdout', new_callable=six.StringIO) as stdout:

-             get_header_fields_mock.return_value = rpm_header

-             handle_import(options, session, arguments)

+         with mock.patch('koji.get_header_fields') as get_header_fields_mock:

+             with mock.patch('koji_cli.commands.activate_session') as activate_session_mock:

+                 with mock.patch('sys.stdout', new_callable=six.StringIO) as stdout:

+                     get_header_fields_mock.return_value = rpm_header

+                     handle_import(options, session, arguments)

  

          # check output message

          self.assert_console_message(stdout, expected)
@@ -300,11 +308,11 @@ 

              'payloadhash': self.md5

          }

          expected = "Build %s state is %s. Skipping import\n" % (nvr, 'FAILED')

-         with mock.patch('koji.get_header_fields') as get_header_fields_mock, \

-                 mock.patch('koji_cli.commands.activate_session') as activate_session_mock, \

-                 mock.patch('sys.stdout', new_callable=six.StringIO) as stdout:

-             get_header_fields_mock.return_value = self.srpm_header

-             handle_import(options, session, arguments)

+         with mock.patch('koji.get_header_fields') as get_header_fields_mock:

+             with mock.patch('koji_cli.commands.activate_session') as activate_session_mock:

+                 with mock.patch('sys.stdout', new_callable=six.StringIO) as stdout:

+                     get_header_fields_mock.return_value = self.srpm_header

+                     handle_import(options, session, arguments)

          activate_session_mock.assert_called_with(session, options)

          self.assert_console_message(stdout, expected)

  

@@ -174,32 +174,32 @@ 

          # is matched return the value we expected.

          self.custom_os_path_exists['/real/path/filename'] = False

  

-         with mock.patch(utils.get_builtin_open()), \

-                 mock.patch('os.path.exists', new=self.mock_os_path_exists), \

-                 mock.patch('koji_cli.commands.json') as json_mock:

- 

-             # Case 3. metafile doesn't have output section

-             json_mock.load.return_value = {}

-             expected = "Metadata contains no output\n"

-             self.assert_system_exit(

-                 handle_import_cg,

-                 options,

-                 session,

-                 arguments,

-                 stdout=expected,

-                 exit_code=1)

- 

-             # Case 4. path not exist

-             file_path = '%(relpath)s/%(filename)s' % metadata['output'][1]

-             json_mock.load.return_value = metadata

-             expected = self.format_error_message(

-                 "No such file: %s" % file_path)

-             self.assert_system_exit(

-                 handle_import_cg,

-                 options,

-                 session,

-                 arguments,

-                 stderr=expected)

+         with mock.patch(utils.get_builtin_open()):

+             with mock.patch('os.path.exists', new=self.mock_os_path_exists):

+                 with mock.patch('koji_cli.commands.json') as json_mock:

+ 

+                     # Case 3. metafile doesn't have output section

+                     json_mock.load.return_value = {}

+                     expected = "Metadata contains no output\n"

+                     self.assert_system_exit(

+                         handle_import_cg,

+                         options,

+                         session,

+                         arguments,

+                         stdout=expected,

+                         exit_code=1)

+ 

+                     # Case 4. path not exist

+                     file_path = '%(relpath)s/%(filename)s' % metadata['output'][1]

+                     json_mock.load.return_value = metadata

+                     expected = self.format_error_message(

+                         "No such file: %s" % file_path)

+                     self.assert_system_exit(

+                         handle_import_cg,

+                         options,

+                         session,

+                         arguments,

+                         stderr=expected)

  

      def test_handle_import_cg_help(self):

          """Test handle_import_cg help message"""

@@ -4,7 +4,10 @@ 

  import os

  import six

  import sys

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  try:

      import libcomps
@@ -15,6 +18,8 @@ 

  except ImportError:

      yumcomps = None

  

+ from nose.plugins.skip import SkipTest

+ 

  import koji_cli.commands

  from koji_cli.commands import handle_import_comps, _import_comps,\

                                _import_comps_alt
@@ -213,11 +218,15 @@ 

          session.getTag.assert_not_called()

          session.getTagGroups.assert_not_called()

          session.groupListAdd.assert_not_called()

-         self.assertEqual(cm.exception.code, 2)

+         if isinstance(cm.exception, int):

+             self.assertEqual(cm.exception, 2)

+         else:

+             self.assertEqual(cm.exception.code, 2)

  

-     @unittest.skipIf(libcomps is None, "No libcomps")

      @mock.patch('sys.stdout', new_callable=six.StringIO)

      def test_import_comps_libcomps(self, stdout):

+         if libcomps is None:

+             raise SkipTest('no libcomps')

          comps_file = os.path.dirname(__file__) + '/data/comps-example.xml'

          stdout_file = os.path.dirname(

              __file__) + '/data/comps-example.libcomps.out'
@@ -230,9 +239,10 @@ 

              calls_file,

              stdout)

  

-     @unittest.skipIf(libcomps is None, "No libcomps")

      @mock.patch('sys.stdout', new_callable=six.StringIO)

      def test_import_comps_sample_libcomps(self, stdout):

+         if libcomps is None:

+             raise SkipTest('no libcomps')

          comps_file = os.path.dirname(__file__) + '/data/comps-sample.xml'

          stdout_file = os.path.dirname(

              __file__) + '/data/comps-sample.libcomps.out'
@@ -245,11 +255,12 @@ 

              calls_file,

              stdout)

  

-     @unittest.skipIf(yumcomps is None, "No yum.comps")

      @mock.patch('sys.stdout', new_callable=six.StringIO)

      @mock.patch('koji_cli.commands.libcomps', new=None)

      @mock.patch('koji_cli.commands.yumcomps', create=True, new=yumcomps)

      def test_import_comps_yumcomps(self, stdout):

+         if yumcomps is None:

+             raise SkipTest('no yum.comps')

          comps_file = os.path.dirname(__file__) + '/data/comps-example.xml'

          stdout_file = os.path.dirname(

              __file__) + '/data/comps-example.yumcomps.out'
@@ -262,11 +273,12 @@ 

              calls_file,

              stdout)

  

-     @unittest.skipIf(yumcomps is None, "No yum.comps")

      @mock.patch('sys.stdout', new_callable=six.StringIO)

      @mock.patch('koji_cli.commands.libcomps', new=None)

      @mock.patch('koji_cli.commands.yumcomps', create=True, new=yumcomps)

      def test_import_comps_sample_yumcomps(self, stdout):

+         if yumcomps is None:

+             raise SkipTest('no yum.comps')

          comps_file = os.path.dirname(__file__) + '/data/comps-sample.xml'

          stdout_file = os.path.dirname(

              __file__) + '/data/comps-sample.yumcomps.out'

@@ -1,11 +1,14 @@ 

  from __future__ import absolute_import

+ import base64

+ import copy

+ import hashlib

  import mock

- import six

- import unittest

  import random

- import hashlib

- import copy

- import base64

+ import six

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  from mock import call

  from koji_cli.commands import handle_import_sig

@@ -1,7 +1,10 @@ 

  from __future__ import absolute_import

  import mock

  import six

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  from koji_cli.commands import anon_handle_list_api

  from . import utils

@@ -1,6 +1,9 @@ 

  from __future__ import absolute_import

  import mock

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  from six.moves import StringIO

  

  import koji

@@ -2,7 +2,10 @@ 

  import mock

  import os

  import six

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  from . import loadcli

  cli = loadcli.cli

@@ -1,8 +1,11 @@ 

  from __future__ import absolute_import

  import mock

  import six

- import unittest

  import time

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  from koji_cli.commands import anon_handle_list_groups

  from . import utils

@@ -1,5 +1,8 @@ 

  import mock

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  from six.moves import StringIO

  

  import koji
@@ -37,8 +40,8 @@ 

          self.maxDiff=None

          self.assertMultiLineEqual(actual, expected)

          activate_session_mock.assert_called_once_with(self.session, self.options)

-         self.session.getTag.assert_has_calls((mock.call(1), mock.call(1)))

-         self.session.getPackage.assert_has_calls((mock.call(11), mock.call(11)))

+         self.session.getTag.assert_has_calls([mock.call(1), mock.call(1)])

+         self.session.getPackage.assert_has_calls([mock.call(11), mock.call(11)])

          self.session.getUser.assert_not_called()

          self.session.getBuildNotifications.assert_called_once_with(None)

  
@@ -67,8 +70,8 @@ 

          self.maxDiff=None

          self.assertMultiLineEqual(actual, expected)

          activate_session_mock.assert_called_once_with(self.session, self.options)

-         self.session.getTag.assert_has_calls((mock.call(1), mock.call(1)))

-         self.session.getPackage.assert_has_calls((mock.call(11), mock.call(11)))

+         self.session.getTag.assert_has_calls([mock.call(1), mock.call(1)])

+         self.session.getPackage.assert_has_calls([mock.call(11), mock.call(11)])

          self.session.getUser.assert_called_once_with('random_name')

          self.session.getBuildNotifications.assert_called_once_with(321)

  

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

  from __future__ import absolute_import

  import mock

  import six

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

+ 

  from koji_cli.commands import handle_list_permissions

  from . import utils

  

@@ -1,6 +1,9 @@ 

  import mock

  import six

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  import koji

  from koji_cli.lib import _list_tasks

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

  from __future__ import absolute_import

  import mock

  import six

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

+ 

  from koji_cli.commands import handle_list_volumes

  from . import utils

  

@@ -1,7 +1,10 @@ 

  from __future__ import absolute_import

  import mock

  import os

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  from . import loadcli

  cli = loadcli.cli

@@ -5,7 +5,10 @@ 

  import os

  import six

  import sys

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  from koji_cli.commands import handle_maven_build

  
@@ -122,7 +125,10 @@ 

          self.session.mavenBuild.assert_not_called()

          self.session.logout.assert_not_called()

          watch_tasks_mock.assert_not_called()

-         self.assertEqual(cm.exception.code, 2)

+         if isinstance(cm.exception, int):

+             self.assertEqual(cm.exception, 2)

+         else:

+             self.assertEqual(cm.exception.code, 2)

  

      @mock.patch('sys.stdout', new_callable=six.StringIO)

      @mock.patch('sys.stderr', new_callable=six.StringIO)
@@ -162,7 +168,10 @@ 

          self.session.mavenBuild.assert_not_called()

          self.session.logout.assert_not_called()

          watch_tasks_mock.assert_not_called()

-         self.assertEqual(cm.exception.code, 2)

+         if isinstance(cm.exception, int):

+             self.assertEqual(cm.exception, 2)

+         else:

+             self.assertEqual(cm.exception.code, 2)

  

      @mock.patch('sys.stdout', new_callable=six.StringIO)

      @mock.patch('sys.stderr', new_callable=six.StringIO)
@@ -230,7 +239,10 @@ 

          self.session.mavenBuild.assert_not_called()

          self.session.logout.assert_not_called()

          watch_tasks_mock.assert_not_called()

-         self.assertEqual(cm.exception.code, 0)

+         if isinstance(cm.exception, int):

+             self.assertEqual(cm.exception, 2)

+         else:

+             self.assertEqual(cm.exception.code, 0)

  

      @mock.patch('sys.stderr', new_callable=six.StringIO)

      @mock.patch('koji_cli.commands.activate_session')
@@ -271,7 +283,10 @@ 

          self.session.mavenBuild.assert_not_called()

          self.session.logout.assert_not_called()

          watch_tasks_mock.assert_not_called()

-         self.assertEqual(cm.exception.code, 2)

+         if isinstance(cm.exception, int):

+             self.assertEqual(cm.exception, 2)

+         else:

+             self.assertEqual(cm.exception.code, 2)

  

      @mock.patch('sys.stderr', new_callable=six.StringIO)

      @mock.patch('koji_cli.commands.activate_session')
@@ -316,7 +331,10 @@ 

          self.session.mavenBuild.assert_not_called()

          self.session.logout.assert_not_called()

          watch_tasks_mock.assert_not_called()

-         self.assertEqual(cm.exception.code, 2)

+         if isinstance(cm.exception, int):

+             self.assertEqual(cm.exception, 2)

+         else:

+             self.assertEqual(cm.exception.code, 2)

  

      @mock.patch('sys.stderr', new_callable=six.StringIO)

      @mock.patch('koji_cli.commands.activate_session')
@@ -361,7 +379,10 @@ 

          self.session.mavenBuild.assert_not_called()

          self.session.logout.assert_not_called()

          watch_tasks_mock.assert_not_called()

-         self.assertEqual(cm.exception.code, 2)

+         if isinstance(cm.exception, int):

+             self.assertEqual(cm.exception, 2)

+         else:

+             self.assertEqual(cm.exception.code, 2)

  

      @mock.patch('sys.stderr', new_callable=six.StringIO)

      @mock.patch('sys.stdout', new_callable=six.StringIO)
@@ -467,7 +488,10 @@ 

              build_opts.inis, scratch=scratch, section=section)

          maven_opts_mock.assert_not_called()

          self.session.mavenBuild.assert_not_called()

-         self.assertEqual(cm.exception.code, 2)

+         if isinstance(cm.exception, int):

+             self.assertEqual(cm.exception, 2)

+         else:

+             self.assertEqual(cm.exception.code, 2)

  

          stdout.seek(0)

          stdout.truncate()
@@ -495,7 +519,10 @@ 

              build_opts.inis, scratch=scratch, section=section)

          maven_opts_mock.assert_not_called()

          self.session.mavenBuild.assert_not_called()

-         self.assertEqual(cm.exception.code, 2)

+         if isinstance(cm.exception, int):

+             self.assertEqual(cm.exception, 2)

+         else:

+             self.assertEqual(cm.exception.code, 2)

  

      @mock.patch('sys.stderr', new_callable=six.StringIO)

      @mock.patch('koji_cli.commands.activate_session')
@@ -547,7 +574,10 @@ 

          self.session.mavenBuild.assert_not_called()

          self.session.logout.assert_not_called()

          watch_tasks_mock.assert_not_called()

-         self.assertEqual(cm.exception.code, 2)

+         if isinstance(cm.exception, int):

+             self.assertEqual(cm.exception, 2)

+         else:

+             self.assertEqual(cm.exception.code, 2)

  

      @mock.patch('sys.stdout', new_callable=six.StringIO)

      @mock.patch('koji_cli.commands.activate_session')

@@ -1,7 +1,10 @@ 

  from __future__ import absolute_import

  import mock

  import six

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  from koji_cli.commands import handle_maven_chain

  from . import utils

@@ -1,7 +1,10 @@ 

  from __future__ import absolute_import

  import mock

  import six

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  from koji_cli.commands import anon_handle_mock_config

  from . import utils

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

  from __future__ import absolute_import

  import mock

  import six

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

+ 

  from koji_cli.commands import handle_move_build

  from . import utils

  

@@ -1,9 +1,12 @@ 

  from __future__ import absolute_import

  from __future__ import print_function

+ import copy

  import mock

  import six

- import unittest

- import copy

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  from koji_cli.commands import handle_regen_repo

  from . import utils

@@ -3,7 +3,10 @@ 

  import os

  import six

  import sys

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  from koji_cli.commands import handle_remove_channel

  
@@ -120,7 +123,10 @@ 

          activate_session_mock.assert_not_called()

          session.getChannel.assert_not_called()

          session.removeChannel.assert_not_called()

-         self.assertEqual(cm.exception.code, 2)

+         if isinstance(cm.exception, int):

+             self.assertEqual(cm.exception, 2)

+         else:

+             self.assertEqual(cm.exception.code, 2)

  

  

  if __name__ == '__main__':

@@ -3,7 +3,10 @@ 

  import os

  import six

  import sys

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  from koji_cli.commands import handle_remove_host_from_channel

  
@@ -134,7 +137,10 @@ 

          session.getHost.assert_not_called()

          session.listChannels.assert_not_called()

          session.removeHostFromChannel.assert_not_called()

-         self.assertEqual(cm.exception.code, 2)

+         if isinstance(cm.exception, int):

+             self.assertEqual(cm.exception, 2)

+         else:

+             self.assertEqual(cm.exception.code, 2)

  

  

  if __name__ == '__main__':

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

  from __future__ import absolute_import

  import koji

  import mock

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

+ 

  from six.moves import StringIO

  

  from koji_cli.commands import handle_remove_notification

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

  import os

  import six

  import sys

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

+ 

  from mock import call

  

  
@@ -218,7 +222,10 @@ 

          session.getTag.assert_not_called()

          session.listPackages.assert_not_called()

          session.packageListRemove.assert_not_called()

-         self.assertEqual(cm.exception.code, 2)

+         if isinstance(cm.exception, int):

+             self.assertEqual(cm.exception, 2)

+         else:

+             self.assertEqual(cm.exception.code, 2)

  

  

  if __name__ == '__main__':

@@ -3,7 +3,10 @@ 

  import os

  import six

  import sys

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  from koji_cli.commands import handle_rename_channel

  
@@ -96,7 +99,11 @@ 

          activate_session_mock.assert_not_called()

          session.getChannel.assert_not_called()

          session.renameChannel.assert_not_called()

-         self.assertEqual(cm.exception.code, 2)

+         if isinstance(cm.exception, int):

+             # python 2.6.6

+             self.assertEqual(cm.exception, 2)

+         else:

+             self.assertEqual(cm.exception.code, 2)

  

  

  if __name__ == '__main__':

@@ -1,9 +1,12 @@ 

  from __future__ import absolute_import

  import mock

  import six

- import unittest

- import koji

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

+ import koji

  from koji_cli.commands import handle_restart_hosts

  from . import utils

  

@@ -2,7 +2,10 @@ 

  from __future__ import print_function

  import mock

  import six

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  from koji_cli.commands import handle_resubmit

  from . import utils

@@ -1,7 +1,10 @@ 

  from __future__ import absolute_import

  import mock

  import six

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  from koji_cli.commands import handle_revoke_cg_access

  from . import utils

@@ -1,7 +1,10 @@ 

  from __future__ import absolute_import

  import mock

  import six

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  from koji_cli.commands import handle_revoke_permission

  from . import utils

@@ -1,7 +1,9 @@ 

  from __future__ import absolute_import

- import unittest

- 

  import mock

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  from koji_cli.lib import _running_in_bg

  

@@ -1,7 +1,10 @@ 

  from __future__ import absolute_import

  import mock

  import six

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  from koji_cli.commands import anon_handle_search

  from . import utils

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

  from __future__ import absolute_import

  import mock

  import six

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

+ 

  from koji_cli.commands import handle_set_build_volume

  from . import utils

  

@@ -1,7 +1,10 @@ 

  from __future__ import absolute_import

  import mock

  import six

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  from koji_cli.commands import handle_set_pkg_arches

  from . import utils

@@ -1,7 +1,10 @@ 

  from __future__ import absolute_import

  import mock

  import six

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  from koji_cli.commands import handle_set_pkg_owner

  from . import utils

@@ -1,7 +1,10 @@ 

  from __future__ import absolute_import

  import mock

  import six

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  from koji_cli.commands import handle_set_task_priority

  from . import utils

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

  from __future__ import absolute_import

  import mock

  import six

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

+ 

  from koji_cli.commands import handle_tag_build

  from . import utils

  

@@ -1,11 +1,14 @@ 

  from __future__ import absolute_import, print_function

+ import collections

  import mock

  import six

- import unittest

- import koji

- import collections

  import time

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

+ import koji

  from koji_cli.commands import anon_handle_taskinfo, \

      _printTaskInfo, _parseTaskParams

  
@@ -423,9 +426,9 @@ 

  

  """ % tuple('/mnt/koji/work/tasks/2/2/' + k for k in task_output.keys())

  

-         with mock.patch('sys.stdout', new_callable=six.StringIO) as stdout, \

-                 mock.patch('time.localtime', new=time.gmtime):

-             _printTaskInfo(session, 1, '/mnt/koji')

+         with mock.patch('sys.stdout', new_callable=six.StringIO) as stdout:

+             with mock.patch('time.localtime', new=time.gmtime):

+                 _printTaskInfo(session, 1, '/mnt/koji')

          self.assert_console_message(stdout, expected)

  

      @mock.patch('koji_cli.commands.list_task_output_all_volumes')
@@ -563,9 +566,9 @@ 

    Host: kojibuilder

  

  """

-         with mock.patch('sys.stdout', new_callable=six.StringIO) as stdout, \

-                 mock.patch('time.localtime', new=time.gmtime):

-             _printTaskInfo(session, 1, '/mnt/koji')

+         with mock.patch('sys.stdout', new_callable=six.StringIO) as stdout:

+             with mock.patch('time.localtime', new=time.gmtime):

+                 _printTaskInfo(session, 1, '/mnt/koji')

          self.assert_console_message(stdout, expected)

  

      def test_printTaskInfo_no_task(self):

@@ -1,6 +1,10 @@ 

  from __future__ import absolute_import

  import mock

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

+ 

  from koji_cli.commands import handle_unblock_group_pkg

  from . import utils

  

@@ -1,6 +1,10 @@ 

  from __future__ import absolute_import

  import mock

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

+ 

  from koji_cli.commands import handle_unblock_group_req

  from . import utils

  

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

  from __future__ import absolute_import

  import mock

  import six

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

+ 

  

  from koji_cli.commands import handle_unblock_pkg

  from . import utils

@@ -1,5 +1,9 @@ 

  from __future__ import absolute_import

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

+ 

  from six.moves import range

  

  from koji_cli.lib import _unique_path

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

  from __future__ import absolute_import

  import mock

  import six

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

+ 

  

  from koji_cli.lib import _format_size, _format_secs, _progress_callback

  

@@ -1,9 +1,12 @@ 

  from __future__ import absolute_import

  from __future__ import print_function

+ import copy

  import mock

  import six

- import unittest

- import copy

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  from koji_cli.commands import anon_handle_wait_repo

  from . import utils

@@ -4,7 +4,10 @@ 

  import os

  import six

  import sys

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  from mock import call

  from six.moves import range

@@ -1,7 +1,10 @@ 

  from __future__ import absolute_import

  import mock

  import six

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  from koji_cli.commands import handle_wrapper_rpm

  from . import utils

@@ -1,11 +1,14 @@ 

  from __future__ import absolute_import

+ import hashlib

  import mock

  import six

- import unittest

- import koji

- import hashlib

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  from mock import call

+ import koji

  from koji_cli.commands import handle_write_signed_rpm

  from . import utils

  

file modified
+17 -9
@@ -1,9 +1,13 @@ 

  from __future__ import print_function

+ import mock

  import os

- import sys

  import six

- import mock

- import unittest

+ import sys

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

+ 

  

  

  """
@@ -174,16 +178,20 @@ 

          stdout_patch = mock.patch('sys.stdout', new_callable=six.StringIO)

          stderr_patch = mock.patch('sys.stderr', new_callable=six.StringIO)

  

-         with session_patch as session, \

-                 stdout_patch as stdout, \

-                 stderr_patch as stderr, \

-                 self.assertRaises(SystemExit) as cm:

-             callableObj(*test_args, **test_kwargs)

+         with session_patch as session:

+             with stdout_patch as stdout:

+                 with stderr_patch as stderr:

+                     with self.assertRaises(SystemExit) as cm:

+                         callableObj(*test_args, **test_kwargs)

          session.assert_called_once()

          self.assert_console_message(stdout, **message['stdout'])

          self.assert_console_message(stderr, **message['stderr'])

          assert_function()

-         self.assertEqual(cm.exception.code, exit_code)

+         if isinstance(cm.exception, int):

+             # python 2.6.6

+             self.assertEqual(cm.exception, exit_code)

+         else:

+             self.assertEqual(cm.exception.code, exit_code)

  

      @mock.patch('koji_cli.commands.activate_session')

      def assert_help(self, callableObj, message, activate_session_mock):

file modified
+7 -2
@@ -1,12 +1,16 @@ 

  import os

  import subprocess

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  # docs version lives in docs/source/conf.py

  TOPDIR = os.path.dirname(__file__) + '/..'

  SPHINX_CONF = TOPDIR + '/docs/source/conf.py'

  

  import imp

+ import os

  sphinx_conf = imp.load_source('sphinx_conf', SPHINX_CONF)

  

  
@@ -18,7 +22,8 @@ 

      def get_koji_version(self):

          spec = self.get_spec()

          cmd = ['rpm', '-q', '--specfile', spec, '--qf', '%{version}\\n']

-         output = subprocess.check_output(cmd)

+         popen = subprocess.Popen(cmd, stdout=subprocess.PIPE)

+         output = popen.stdout.read()

          # rpm outputs a line for each subpackage

          version = output.splitlines()[0]

          return version

@@ -1,4 +1,7 @@ 

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  import mock

  

  import koji

@@ -1,5 +1,8 @@ 

  import mock

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  import koji

  import kojihub

@@ -1,5 +1,8 @@ 

- import unittest

  import mock

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  import koji

  import kojihub

@@ -1,5 +1,8 @@ 

- import unittest

  import mock

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  import koji

  import kojihub

@@ -1,6 +1,8 @@ 

  import copy

- import unittest

- 

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  from nose.tools import eq_

  

  import kojihub

@@ -1,7 +1,10 @@ 

- import unittest

  import mock

  import os

  import shutil

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  import koji

  import kojihub

@@ -1,6 +1,8 @@ 

  import mock

- import unittest

- 

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  import koji

  import koji.policy

  import kojihub

@@ -5,8 +5,10 @@ 

  import os.path

  import shutil

  import tempfile

- import unittest

- 

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  import koji

  import koji.util

  import kojihub
@@ -160,9 +162,9 @@ 

              return old_ip(table, *a, **kw)

          def my_ga(archive_id, **kw):

              return share['archiveinfo']

-         with mock.patch('kojihub.InsertProcessor', new=my_ip), \

-                     mock.patch('kojihub.get_archive', new=my_ga):

-             return orig_import_archive_internal(*a, **kw)

+         with mock.patch('kojihub.InsertProcessor', new=my_ip):

+             with mock.patch('kojihub.get_archive', new=my_ga):

+                 return orig_import_archive_internal(*a, **kw)

  

      def set_up_callbacks(self):

          new_callbacks = copy.deepcopy(koji.plugin.callbacks)

@@ -5,8 +5,10 @@ 

  import os.path

  import shutil

  import tempfile

- import unittest

- 

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  import koji

  import koji.util

  import kojihub
@@ -94,9 +96,9 @@ 

              return mock.MagicMock()

          def my_ga(archive_id, **kw):

              return share['archiveinfo']

-         with mock.patch('kojihub.InsertProcessor', new=my_ip), \

-                     mock.patch('kojihub.get_archive', new=my_ga):

-             orig_import_archive_internal(*a, **kw)

+         with mock.patch('kojihub.InsertProcessor', new=my_ip):

+             with mock.patch('kojihub.get_archive', new=my_ga):

+                 orig_import_archive_internal(*a, **kw)

  

      def set_up_callbacks(self):

          new_callbacks = copy.deepcopy(koji.plugin.callbacks)

@@ -2,8 +2,10 @@ 

  import mock

  import shutil

  import tempfile

- import unittest

- 

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  import koji

  import kojihub

  

@@ -1,5 +1,8 @@ 

  import mock

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  import kojihub

  import time

  from koji import GenericError

@@ -1,6 +1,8 @@ 

  import mock

- import unittest

- 

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  import koji

  import kojihub

  

@@ -1,5 +1,7 @@ 

- 

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  import json

  import mock

  import os

@@ -1,5 +1,8 @@ 

- import unittest

  import mock

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  import koji

  import kojihub

@@ -1,6 +1,8 @@ 

  import mock

- import unittest

- 

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  import koji

  import kojihub

  

@@ -1,8 +1,10 @@ 

  from __future__ import absolute_import

  import mock

  import os

- import unittest

- 

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  import koji

  import kojihub

  

@@ -1,6 +1,8 @@ 

  import mock

- import unittest

- 

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  import koji

  import kojihub

  import koji.db

@@ -1,5 +1,8 @@ 

- import unittest

  import mock

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  import koji

  import kojihub

@@ -2,8 +2,10 @@ 

  import os

  import shutil

  import tempfile

- import unittest

- 

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  import koji

  import kojihub

  

@@ -1,5 +1,8 @@ 

- import unittest

  import mock

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  import kojihub

  

@@ -1,5 +1,8 @@ 

- import unittest

  import mock

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  import koji

  import kojihub

@@ -1,6 +1,8 @@ 

  import mock

- import unittest

- 

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  import koji

  import kojihub

  

@@ -1,13 +1,25 @@ 

  import os

  import mock

  import shutil

- import unittest

+ import tempfile

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

+ 

  import kojihub

  from koji import GenericError

  

  

  class TestGetUploadPath(unittest.TestCase):

  

+     def setUp(self):

+         self.topdir = tempfile.mkdtemp()

+         mock.patch('koji.pathinfo._topdir', new=self.topdir).start()

+ 

+     def tearDown(self):

+         shutil.rmtree(self.topdir)

+         mock.patch.stopall()

  

      def test_get_upload_path_invalid_filename(self):

          with self.assertRaises(GenericError):
@@ -26,14 +38,12 @@ 

              kojihub.get_upload_path(reldir='tasks/1/should_be_number', name='error', create=True)

  

      @mock.patch('kojihub.context')

-     @mock.patch('koji.pathinfo.work')

      @mock.patch('kojihub.Host')

-     def test_get_upload_path_invalid_upload_dir_owner(self, host, work, context):

-         work.return_value = '/tmp'

+     def test_get_upload_path_invalid_upload_dir_owner(self, host, context):

          cursor = mock.MagicMock()

          context.cnx.cursor.return_value = cursor

          reldir = 'fake/1/1'

-         fullpath = '{0}/{1}'.format(work.return_value, reldir)

+         fullpath = '%s/work/%s' % (self.topdir, reldir)

          os.makedirs(fullpath)

  

          with open('{0}/.user'.format(fullpath), 'wb') as f:
@@ -42,12 +52,8 @@ 

          with self.assertRaises(GenericError):

              kojihub.get_upload_path(reldir=reldir, name='error', create=True)

  

-         shutil.rmtree('/tmp/fake')

- 

-     @mock.patch('koji.pathinfo.work')

      @mock.patch('kojihub.Host')

-     def test_get_upload_path_invalid_upload_no_dir_owner(self, host, work):

-         work.return_value = '/tmp'

+     def test_get_upload_path_invalid_upload_no_dir_owner(self, host):

          dir = kojihub.get_upload_path(reldir='tasks/1/1', name='error', create=False)

-         assert dir == '/tmp/tasks/1/1/error'

+         assert dir == '%s/work/tasks/1/1/error' % self.topdir

  

@@ -1,6 +1,8 @@ 

  import mock

- import unittest

- 

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  import koji

  import kojihub

  

@@ -1,4 +1,8 @@ 

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

+ 

  import kojihub

  from koji import GenericError

  from koji.util import md5_constructor, adler32_constructor

@@ -1,6 +1,8 @@ 

  import mock

- import unittest

- 

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  import koji

  import kojihub

  

@@ -2,7 +2,10 @@ 

  import mock

  import shutil

  import tempfile

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  import koji

  import kojihub

@@ -1,13 +1,15 @@ 

- import unittest

  import mock

  import os

  import shutil

  import tempfile

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  import kojihub

  

  

- 

  class TestImportImageInternal(unittest.TestCase):

      def setUp(self):

          self.tempdir = tempfile.mkdtemp()

@@ -1,5 +1,8 @@ 

- import unittest

  import mock

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  import kojihub

  

@@ -1,6 +1,8 @@ 

- import unittest

- 

  import mock

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  import koji

  import kojihub

@@ -1,5 +1,8 @@ 

- import unittest

  import mock

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  import kojihub

  

@@ -1,5 +1,8 @@ 

- import unittest

  import mock

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  import koji

  import kojihub

@@ -1,5 +1,8 @@ 

- import unittest

  import mock

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  import koji

  import kojihub

@@ -1,5 +1,8 @@ 

- import unittest

  import mock

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  import kojihub

  

@@ -1,5 +1,8 @@ 

- import unittest

  import mock

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  import kojihub

  

@@ -1,5 +1,8 @@ 

- import unittest

  import mock

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  import koji

  import kojihub

@@ -1,5 +1,8 @@ 

- import unittest

  import mock

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  import kojihub

  

@@ -1,5 +1,8 @@ 

  import mock

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  import koji

  import kojihub

@@ -1,5 +1,8 @@ 

  import mock

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  import koji

  import kojihub

@@ -1,5 +1,8 @@ 

- import unittest

  import mock

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  import kojihub

  

@@ -1,5 +1,8 @@ 

- import unittest

  import mock

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  import koji

  import kojihub

@@ -1,6 +1,9 @@ 

  import copy

- import unittest

  import mock

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  import koji

  import kojihub

@@ -1,5 +1,8 @@ 

- import unittest

  import mock

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  import koji

  import kojihub

@@ -2,7 +2,10 @@ 

  import mock

  import shutil

  import tempfile

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  import koji

  import kojihub

@@ -1,6 +1,9 @@ 

  import mock

- import unittest

  import xmlrpclib

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  import koji

  import kojihub

@@ -1,5 +1,8 @@ 

- import unittest

  import mock

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  import kojihub

  

@@ -1,5 +1,8 @@ 

  import mock

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  import koji

  import kojihub

@@ -1,9 +1,11 @@ 

- from __future__ import absolute_import

- from __future__ import print_function

- import unittest

+ from __future__ import absolute_import, with_statement

  import mock

  import os

  import datetime

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  import koji

  from kojihub import _write_maven_repo_metadata
@@ -29,10 +31,10 @@ 

          artifacts.add(('0', '1', '1.3.11'))

  

          now = datetime.datetime.now()

-         with mock.patch('kojihub.open', create=True) as openf_mock, \

-                 mock.patch('datetime.datetime') as datetime_mock:

-             datetime_mock.now.return_value = now

-             _write_maven_repo_metadata(destdir, artifacts)

+         with mock.patch('kojihub.open', create=True) as openf_mock:

+             with mock.patch('datetime.datetime') as datetime_mock:

+                 datetime_mock.now.return_value = now

+                 _write_maven_repo_metadata(destdir, artifacts)

  

          openf_mock.assert_called_with(

              os.path.join(destdir, 'maven-metadata.xml'), 'w')

file modified
+4 -1
@@ -1,6 +1,9 @@ 

- import unittest

  import mock

  import six

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  import kojihub

  

@@ -1,7 +1,10 @@ 

  from __future__ import absolute_import

  import mock

  import time

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  import koji

  

@@ -1,4 +1,8 @@ 

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

+ 

  import koji.util

  

  class TestApplyArgspec(unittest.TestCase):

@@ -1,7 +1,10 @@ 

  from __future__ import absolute_import

  import mock

- import unittest

  import six

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  import koji

  

@@ -1,5 +1,8 @@ 

  import datetime

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  import koji.util

  from koji.xmlrpcplus import DateTime

@@ -5,9 +5,13 @@ 

  

  from __future__ import absolute_import

  import koji

- import six

- import unittest

  import mock

+ import six

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

+ 

  

  class FixEncodingTestCase(unittest.TestCase):

      """Main test case container"""

@@ -1,6 +1,10 @@ 

  from __future__ import absolute_import

  import datetime

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

+ 

  import six.moves.xmlrpc_client as xmlrpc_client

  

  from koji import formatTime, formatTimeLong

@@ -1,7 +1,10 @@ 

  import ast

  import os

  import os.path

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  import koji

  

@@ -1,6 +1,9 @@ 

  from __future__ import absolute_import

- import unittest

  import optparse

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  import koji

  

@@ -1,9 +1,11 @@ 

  from __future__ import absolute_import

  

- import os

- import unittest

- 

  import mock

+ import os

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  import koji

  

@@ -6,7 +6,10 @@ 

  import mock

  import os

  import rpm

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  import koji

  

@@ -1,7 +1,10 @@ 

  import copy

  import datetime

  import mock

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  import koji

  import koji.util

@@ -1,6 +1,4 @@ 

  from __future__ import absolute_import

- import unittest

- 

  import koji

  import sys

  import threading
@@ -8,6 +6,11 @@ 

  from six.moves import range

  import six

  

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

+ 

  # XXX remove skip when Fedora bug is fixed

  @unittest.skipIf(six.PY3, "coverage bug Fedora, see rhbz#1452339")

  class ProfilesTestCase(unittest.TestCase):

file modified
+76 -73
@@ -1,16 +1,19 @@ 

  # coding=utf-8

  from __future__ import absolute_import

+ import calendar

  import mock

- import unittest

- from mock import call, patch

- from datetime import datetime

- 

+ import optparse

  import os

- import time

  import resource

- import optparse

- import calendar

  import six.moves.configparser

+ import time

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

+ 

+ from mock import call, patch

+ from datetime import datetime

  import koji

  import koji.util

  
@@ -450,27 +453,27 @@ 

      def test_tsort(self):

          # success, one path

          parts = {

-             'p1': {'p2', 'p3'},

-             'p2': {'p3'},

+             'p1': set(['p2', 'p3']),

+             'p2': set(['p3']),

              'p3': set()

          }

          self.assertEqual(koji.util.tsort(parts),

-                          [{'p3'}, {'p2'}, {'p1'}])

+                          [set(['p3']), set(['p2']), set(['p1'])])

          # success, multi-path

          parts = {

-             'p1': {'p2'},

-             'p2': {'p4'},

-             'p3': {'p4'},

+             'p1': set(['p2']),

+             'p2': set(['p4']),

+             'p3': set(['p4']),

              'p4': set(),

              'p5': set()

          }

          self.assertEqual(koji.util.tsort(parts),

-                          [{'p4', 'p5'}, {'p2', 'p3'}, {'p1'}])

+                          [set(['p4', 'p5']), set(['p2', 'p3']), set(['p1'])])

          # failed, missing child 'p4'

          parts = {

-             'p1': {'p2'},

-             'p2': {'p3'},

-             'p3': {'p4'}

+             'p1': set(['p2']),

+             'p2': set(['p3']),

+             'p3': set(['p4'])

          }

          with self.assertRaises(ValueError) as cm:

              koji.util.tsort(parts)
@@ -478,9 +481,9 @@ 

  

          # failed, circular

          parts = {

-             'p1': {'p2'},

-             'p2': {'p3'},

-             'p3': {'p1'}

+             'p1': set(['p2']),

+             'p2': set(['p3']),

+             'p3': set(['p1'])

          }

          with self.assertRaises(ValueError) as cm:

              koji.util.tsort(parts)
@@ -624,17 +627,17 @@ 

  

      def test_isSuccess(self):

          """Test isSuccess function"""

-         with mock.patch('os.WIFEXITED') as m_exit, \

-                 mock.patch('os.WEXITSTATUS') as m_exitst:

-             # True case

-             m_exit.return_value, m_exitst.return_value = True, 0

-             self.assertTrue(koji.util.isSuccess(0))

- 

-             # False cases

-             m_exit.return_value, m_exitst.return_value = True, 1

-             self.assertFalse(koji.util.isSuccess(0))

-             m_exit.return_value, m_exitst.return_value = False, 255

-             self.assertFalse(koji.util.isSuccess(0))

+         with mock.patch('os.WIFEXITED') as m_exit:

+             with mock.patch('os.WEXITSTATUS') as m_exitst:

+                 # True case

+                 m_exit.return_value, m_exitst.return_value = True, 0

+                 self.assertTrue(koji.util.isSuccess(0))

+ 

+                 # False cases

+                 m_exit.return_value, m_exitst.return_value = True, 1

+                 self.assertFalse(koji.util.isSuccess(0))

+                 m_exit.return_value, m_exitst.return_value = False, 255

+                 self.assertFalse(koji.util.isSuccess(0))

  

      def test_call_with_argcheck(self):

          """Test call_wit_argcheck function"""
@@ -899,7 +902,7 @@ 

                 }

  

          # create a resource token <--> id lookup table

-         rlimit_lookup = {getattr(resource, k): k for k in options}

+         rlimit_lookup = dict([(getattr(resource, k), k) for k in options])

  

          def _getrlimit(res):

              return (options.get(rlimit_lookup[res], None), 0)
@@ -907,47 +910,47 @@ 

          def _setrlimit(res, limits):

              results[rlimit_lookup[res]] = str(limits[0])

  

-         results = {k: '' for k, v in options.items()}

-         with mock.patch('resource.setrlimit') as m_set, \

-                 mock.patch('resource.getrlimit') as m_get:

-             m_get.side_effect = ValueError('resource.getrlimit-value-error')

-             six.assertRaisesRegex(self, ValueError, 'resource.getrlimit-value-error',

-                                   koji.util.setup_rlimits, options, logger)

- 

-             m_get.side_effect = _getrlimit

- 

-             # logger.error test

-             koji.util.setup_rlimits({'RLIMIT_AS': 'abcde'}, logger)

-             logger.error.assert_called_with('Invalid resource limit: %s=%s',

-                                             'RLIMIT_AS',

-                                             'abcde')

- 

-             koji.util.setup_rlimits({'RLIMIT_AS': '1 2 3 4 5'}, logger)

-             logger.error.assert_called_with('Invalid resource limit: %s=%s',

-                                             'RLIMIT_AS',

-                                             '1 2 3 4 5')

- 

-             # exception and logger.error test

-             m_set.side_effect = ValueError('resource.setrlimit-value-error')

-             koji.util.setup_rlimits({'RLIMIT_AS': '0'}, logger)

-             logger.error.assert_called_with('Unable to set %s: %s',

-                                             'RLIMIT_AS',

-                                             m_set.side_effect)

- 

-             # run setrlimit test, the results should be equal to options

-             m_set.side_effect = _setrlimit

- 

-             # make some noise in options

-             test_opt = dict(options)

-             test_opt.update({

-                 'RLIMIT_CUSTOM':  'fake_rlimit_key',

-                 'DBName':         'koji',

-                 'DBUser':         'koji',

-                 'KojiDir':        '/mnt/koji',

-                 'KojiDebug':      True})

- 

-             koji.util.setup_rlimits(test_opt, logger)

-             six.assertCountEqual(self, results, options)

+         results = dict([(k, '') for k in options])

+         with mock.patch('resource.setrlimit') as m_set:

+             with mock.patch('resource.getrlimit') as m_get:

+                 m_get.side_effect = ValueError('resource.getrlimit-value-error')

+                 six.assertRaisesRegex(self, ValueError, 'resource.getrlimit-value-error',

+                                       koji.util.setup_rlimits, options, logger)

+ 

+                 m_get.side_effect = _getrlimit

+ 

+                 # logger.error test

+                 koji.util.setup_rlimits({'RLIMIT_AS': 'abcde'}, logger)

+                 logger.error.assert_called_with('Invalid resource limit: %s=%s',

+                                                 'RLIMIT_AS',

+                                                 'abcde')

+ 

+                 koji.util.setup_rlimits({'RLIMIT_AS': '1 2 3 4 5'}, logger)

+                 logger.error.assert_called_with('Invalid resource limit: %s=%s',

+                                                 'RLIMIT_AS',

+                                                 '1 2 3 4 5')

+ 

+                 # exception and logger.error test

+                 m_set.side_effect = ValueError('resource.setrlimit-value-error')

+                 koji.util.setup_rlimits({'RLIMIT_AS': '0'}, logger)

+                 logger.error.assert_called_with('Unable to set %s: %s',

+                                                 'RLIMIT_AS',

+                                                 m_set.side_effect)

+ 

+                 # run setrlimit test, the results should be equal to options

+                 m_set.side_effect = _setrlimit

+ 

+                 # make some noise in options

+                 test_opt = dict(options)

+                 test_opt.update({

+                     'RLIMIT_CUSTOM':  'fake_rlimit_key',

+                     'DBName':         'koji',

+                     'DBUser':         'koji',

+                     'KojiDir':        '/mnt/koji',

+                     'KojiDebug':      True})

+ 

+                 koji.util.setup_rlimits(test_opt, logger)

+                 six.assertCountEqual(self, results, options)

  

      def test_adler32_constructor(self):

          """Test adler32_constructor function"""

@@ -1,5 +1,8 @@ 

  # coding=utf-8

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  from six.moves import xmlrpc_client

  from koji import xmlrpcplus

@@ -1,6 +1,9 @@ 

  from __future__ import absolute_import

  import mock

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  import koji

  import koji.auth

@@ -1,11 +1,13 @@ 

  from __future__ import absolute_import

  

  import base64

- import six

- import unittest

- 

  # This is python-mock, not the rpm mock tool we know and love

  import mock

+ import six

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  import koji

  

@@ -1,5 +1,8 @@ 

  from __future__ import absolute_import

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  from nose.tools import raises

  

@@ -1,7 +1,10 @@ 

  import mock

  import shutil

  import tempfile

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  import koji.tasks

  

@@ -1,16 +1,20 @@ 

  from __future__ import absolute_import

  import random

  import shutil

+ import six

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

+ 

  from os import path, makedirs

  from tempfile import gettempdir

- from unittest import TestCase

  from mock import patch, MagicMock, Mock, call

  

  import koji

  from koji.tasks import BaseTaskHandler, FakeTask, ForkTask, SleepTask, \

                         WaitTestTask, scan_mounts, umount_all, \

                         safe_rmtree

- import six

  

  

  def get_fake_mounts_file():
@@ -68,7 +72,7 @@ 

      Methods = ['some_method']

  

  

- class TasksTestCase(TestCase):

+ class TasksTestCase(unittest.TestCase):

  

      def tearDown(self):

          temp_dir_root = get_temp_dir_root()
@@ -700,7 +704,7 @@ 

          # will be skipped as 'canfail'

          obj.session.getTaskResult.assert_has_calls([call(3)])

  

- class TestSafeRmtree(TestCase):

+ class TestSafeRmtree(unittest.TestCase):

      @patch('os.path.exists', return_value=True)

      @patch('os.path.isfile', return_value=True)

      @patch('os.path.islink', return_value=False)

@@ -1,9 +1,13 @@ 

  import six

- import unittest

- from mock import patch, MagicMock

  import protonmsg

- from koji.context import context

  import tempfile

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

+ 

+ from mock import patch, MagicMock

+ from koji.context import context

  from ConfigParser import SafeConfigParser

  

  class TestProtonMsg(unittest.TestCase):

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

  from __future__ import absolute_import

  import copy

- import unittest

  import mock

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

+ 

  import six.moves.configparser

  

  # inject builder data
@@ -12,6 +16,13 @@ 

  import koji

  import runroot

  

+ def mock_open():

+     """Return the right patch decorator for open"""

+     if six.PY2:

+         return mock.patch('__builtin__.open')

+     else:

+         return mock.patch('builtins.open')

+ 

  

  CONFIG1 = {

          'paths': {
@@ -95,7 +106,7 @@ 

          options.workdir = '/tmp/nonexistentdirectory'

          with self.assertRaises(koji.GenericError) as cm:

              runroot.RunRootTask(123, 'runroot', {}, session, options)

-         self.assertEqual(cm.exception.message,

+         self.assertEqual(cm.exception.args[0],

              "bad config: missing options in path0 section")

  

      @mock.patch('ConfigParser.SafeConfigParser')
@@ -108,7 +119,7 @@ 

          options.workdir = '/tmp/nonexistentdirectory'

          with self.assertRaises(koji.GenericError) as cm:

              runroot.RunRootTask(123, 'runroot', {}, session, options)

-         self.assertEqual(cm.exception.message,

+         self.assertEqual(cm.exception.args[0],

              "bad config: all paths (default_mounts, safe_roots, path_subs) needs to be absolute: ")

  

      @mock.patch('ConfigParser.SafeConfigParser')
@@ -178,10 +189,10 @@ 

          self.assertEqual(self.t._get_path_params('/mnt/archive', 'rw'),

              ('archive.org:/vol/archive/', '/mnt/archive', 'nfs', 'rw,hard,intr,nosuid,nodev,noatime,tcp'))

  

+     @mock_open()

      @mock.patch('os.path.isdir')

-     @mock.patch('runroot.open')

      @mock.patch('runroot.log_output')

-     def test_do_mounts(self, log_output, file_mock, is_dir):

+     def test_do_mounts(self, log_output, is_dir, open_mock):

          log_output.return_value = 0 # successful mount

  

          # no mounts, don't do anything
@@ -192,7 +203,7 @@ 

          # mountpoint has no absolute_path

          with self.assertRaises(koji.GenericError) as cm:

              self.t.do_mounts('rootdir', [('nfs:nfs', 'relative_path', 'nfs', '')])

-         self.assertEqual(cm.exception.message,

+         self.assertEqual(cm.exception.args[0],

                  "invalid mount point: relative_path")

  

          # cover missing opts
@@ -215,7 +226,7 @@ 

          mounts = [self.t._get_path_params('/mnt/archive')]

          with self.assertRaises(koji.GenericError) as cm:

              self.t.do_mounts('rootdir', mounts)

-         self.assertEqual(cm.exception.message,

+         self.assertEqual(cm.exception.args[0],

              'Unable to mount rootdir/mnt/archive: mount -t nfs -o'

              ' ro,hard,intr,nosuid,nodev,noatime,tcp archive.org:/vol/archive/'

              ' rootdir/mnt/archive was killed by signal 1')
@@ -239,7 +250,7 @@ 

          is_dir.return_value = False

          with self.assertRaises(koji.GenericError) as cm:

              self.t.do_mounts('rootdir', [mount])

-         self.assertEqual(cm.exception.message,

+         self.assertEqual(cm.exception.args[0],

              "No such directory or mount: archive.org:/vol/archive/")

  

          # bg option forbidden
@@ -249,7 +260,7 @@ 

          is_dir.return_value = False

          with self.assertRaises(koji.GenericError) as cm:

              self.t.do_mounts('rootdir', [mount])

-         self.assertEqual(cm.exception.message,

+         self.assertEqual(cm.exception.args[0],

              "bad config: background mount not allowed")

  

      def test_do_extra_mounts(self):
@@ -279,19 +290,20 @@ 

          self.t.do_mounts.assert_not_called()

  

  

+     @mock_open()

      @mock.patch('runroot.scan_mounts')

      @mock.patch('os.unlink')

      @mock.patch('commands.getstatusoutput')

      @mock.patch('os.path.exists')

-     def test_undo_mounts(self, path_exists, getstatusoutput, os_unlink, scan_mounts):

+     def test_undo_mounts(self, path_exists, getstatusoutput, os_unlink, scan_mounts, m_open):

          self.t.logger = mock.MagicMock()

          scan_mounts.return_value = ['mount_1', 'mount_2']

  

          # correct

          getstatusoutput.return_value = (0, 'ok')

          path_exists.return_value = True

-         with mock.patch('runroot.open', mock.mock_open(read_data = 'mountpoint')):

-             self.t.undo_mounts('rootdir')

+         m_open.return_value.__enter__.return_value.readlines.return_value = ['mountpoint']

+         self.t.undo_mounts('rootdir')

          self.t.logger.assert_has_calls([

              mock.call.debug('Unmounting runroot mounts'),

              mock.call.info("Unmounting (runroot): ['mountpoint', 'mount_2', 'mount_1']"),
@@ -302,11 +314,10 @@ 

          os_unlink.reset_mock()

          getstatusoutput.return_value = (1, 'error')

          path_exists.return_value = True

-         with mock.patch('runroot.open', mock.mock_open(read_data = 'mountpoint')):

-             with self.assertRaises(koji.GenericError) as cm:

-                 self.t.undo_mounts('rootdir')

-             self.assertEqual(cm.exception.message,

-                 'Unable to unmount: mountpoint: error, mount_2: error, mount_1: error')

+         with self.assertRaises(koji.GenericError) as cm:

+             self.t.undo_mounts('rootdir')

+         self.assertEqual(cm.exception.args[0],

+             'Unable to unmount: mountpoint: error, mount_2: error, mount_1: error')

  

          os_unlink.assert_not_called()

  

@@ -1,7 +1,10 @@ 

  from __future__ import absolute_import

  import mock

  import six

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  import koji

  from . import load_plugin

@@ -1,5 +1,8 @@ 

- import unittest

  import mock

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  import koji

  import runroot_hub

@@ -2,7 +2,10 @@ 

  import mock

  import os

  import sys

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  # alter pythonpath to not load hub plugin

  sys.path = [os.path.join(os.path.dirname(__file__), '../../plugins/builder')] + sys.path

@@ -1,6 +1,9 @@ 

  import mock

  import six

- import unittest

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  import koji

  

file modified
+5 -5
@@ -1,11 +1,11 @@ 

- import mock

- import unittest

- 

  import logging

+ import mock

  import shutil

  import tempfile

- 

- from pprint import pprint

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

  

  import koji

  import koji.daemon

@@ -1,11 +1,15 @@ 

  from __future__ import absolute_import

  from __future__ import print_function

- import unittest

  import mock

  import koji

  import copy

  import datetime

  

+ try:

+     import unittest2 as unittest

+ except ImportError:

+     import unittest

+ 

  from mock import call

  from .loadwebindex import webidx

  

rebased onto 427843692cf4b96637a0fdb33bf5b84b2e2ad2f2

6 years ago

Recent tests need updating. I've rebased again and applied those fixes here:

https://github.com/mikem23/koji-playground/commits/pagure/pr/831

This leaves a few broken tests on el6, at least when I try.

With a few more updates on that branch I can get the tests to pass

PYTHONPATH=hub/.:plugins/hub/.:plugins/builder/.:plugins/cli/.:cli/.:www/lib /usr/bin/nosetests

Though I do get a deprecation warning:

/usr/lib/python2.6/site-packages/unittest2/case.py:326: DeprecationWarning: Use of a TestResult without an addSkip method is deprecated
  self._addSkip(result, skip_why)

And now that is fixed on the playground branch too...

I'm planning to merge this for 1.16, but I'm holding off until tomorrow in the event that any other merges add a unit test that needs the import updated.

rebased onto 2cacce39700abfe50839ed5a0b34d80e01485166

5 years ago

rebased onto 2287368

5 years ago

I need these changes to get the tests to succeed in an el6 env:
https://github.com/mikem23/koji-playground/commits/pagure/pr/831

If those look ok, I can merge in the morning.

Yes, works for me. It worked for me before, as I've used same env as jenkins have, which means some packages updated via pip.

2 new commits added

  • avoid skipIf in import-comps unit test
  • more unit test fixes
5 years ago

Commit 7e5a8a5 fixes this pull-request

Pull-Request has been merged by mikem

5 years ago
Changes Summary 162
+1 -1
file changed
koji/tasks.py
+34 -36
file changed
plugins/builder/runroot.py
+4 -2
file changed
tests/test_builder/test_build_notification.py
+4 -1
file changed
tests/test_builder/test_choose_taskarch.py
+4 -2
file changed
tests/test_builder/test_taskparams.py
+30
file added
tests/test_cli/data/image-build-config.conf
+4 -1
file changed
tests/test_cli/test_activate_session.py
+8 -4
file changed
tests/test_cli/test_add_group.py
+5 -1
file changed
tests/test_cli/test_add_group_pkg.py
+5 -1
file changed
tests/test_cli/test_add_group_req.py
+8 -2
file changed
tests/test_cli/test_add_host.py
+8 -2
file changed
tests/test_cli/test_add_host_to_channel.py
+4 -1
file changed
tests/test_cli/test_add_notification.py
+16 -4
file changed
tests/test_cli/test_add_pkg.py
+5 -1
file changed
tests/test_cli/test_add_tag.py
+5 -1
file changed
tests/test_cli/test_add_user.py
+5 -1
file changed
tests/test_cli/test_add_volume.py
+9 -3
file changed
tests/test_cli/test_assign_task.py
+5 -1
file changed
tests/test_cli/test_block_group_pkg.py
+5 -1
file changed
tests/test_cli/test_block_group_req.py
+8 -2
file changed
tests/test_cli/test_block_pkg.py
+28 -7
file changed
tests/test_cli/test_build.py
+12 -6
file changed
tests/test_cli/test_call.py
+24 -6
file changed
tests/test_cli/test_chain_build.py
+4 -1
file changed
tests/test_cli/test_disable_host.py
+5 -1
file changed
tests/test_cli/test_disable_user.py
+6 -2
file changed
tests/test_cli/test_dist_repo.py
+9 -2
file changed
tests/test_cli/test_download_file.py
+5 -1
file changed
tests/test_cli/test_download_logs.py
+32 -8
file changed
tests/test_cli/test_download_task.py
+9 -2
file changed
tests/test_cli/test_edit_host.py
+4 -1
file changed
tests/test_cli/test_edit_notification.py
+12 -4
file changed
tests/test_cli/test_edit_tag.py
+4 -1
file changed
tests/test_cli/test_enable_host.py
+5 -1
file changed
tests/test_cli/test_enable_user.py
+4 -1
file changed
tests/test_cli/test_grant_cg_access.py
+4 -1
file changed
tests/test_cli/test_grant_permission.py
+5 -2
file changed
tests/test_cli/test_hello.py
+34 -80
file changed
tests/test_cli/test_image_build.py
+9 -5
file changed
tests/test_cli/test_image_build_indirection.py
+31 -23
file changed
tests/test_cli/test_import.py
+26 -26
file changed
tests/test_cli/test_import_cg.py
+18 -6
file changed
tests/test_cli/test_import_comps.py
+8 -5
file changed
tests/test_cli/test_import_sig.py
+4 -1
file changed
tests/test_cli/test_list_api.py
+4 -1
file changed
tests/test_cli/test_list_channels.py
+4 -1
file changed
tests/test_cli/test_list_commands.py
+4 -1
file changed
tests/test_cli/test_list_groups.py
+8 -5
file changed
tests/test_cli/test_list_notifications.py
+5 -1
file changed
tests/test_cli/test_list_permissions.py
+4 -1
file changed
tests/test_cli/test_list_tasks.py
+5 -1
file changed
tests/test_cli/test_list_volumes.py
+4 -1
file changed
tests/test_cli/test_load_plugins.py
+40 -10
file changed
tests/test_cli/test_maven_build.py
+4 -1
file changed
tests/test_cli/test_maven_chain.py
+4 -1
file changed
tests/test_cli/test_mock_config.py
+5 -1
file changed
tests/test_cli/test_move_build.py
+5 -2
file changed
tests/test_cli/test_regen_repo.py
+8 -2
file changed
tests/test_cli/test_remove_channel.py
+8 -2
file changed
tests/test_cli/test_remove_host_from_channel.py
+5 -1
file changed
tests/test_cli/test_remove_notification.py
+9 -2
file changed
tests/test_cli/test_remove_pkg.py
+9 -2
file changed
tests/test_cli/test_rename_channel.py
+5 -2
file changed
tests/test_cli/test_restart_host.py
+4 -1
file changed
tests/test_cli/test_resubmit.py
+4 -1
file changed
tests/test_cli/test_revoke_cg_access.py
+4 -1
file changed
tests/test_cli/test_revoke_permission.py
+4 -2
file changed
tests/test_cli/test_running_in_bg.py
+4 -1
file changed
tests/test_cli/test_search.py
+5 -1
file changed
tests/test_cli/test_set_build_volume.py
+4 -1
file changed
tests/test_cli/test_set_pkg_arches.py
+4 -1
file changed
tests/test_cli/test_set_pkg_owner.py
+4 -1
file changed
tests/test_cli/test_set_task_priority.py
+5 -1
file changed
tests/test_cli/test_tag_build.py
+12 -9
file changed
tests/test_cli/test_taskinfo.py
+5 -1
file changed
tests/test_cli/test_unblock_group_pkg.py
+5 -1
file changed
tests/test_cli/test_unblock_group_req.py
+5 -1
file changed
tests/test_cli/test_unblock_pkg.py
+5 -1
file changed
tests/test_cli/test_unique_path.py
+5 -1
file changed
tests/test_cli/test_upload_progress_callback.py
+5 -2
file changed
tests/test_cli/test_wait_repo.py
+4 -1
file changed
tests/test_cli/test_watch_tasks.py
+4 -1
file changed
tests/test_cli/test_wrapper_rpm.py
+6 -3
file changed
tests/test_cli/test_write_signed_rpm.py
+17 -9
file changed
tests/test_cli/utils.py
+7 -2
file changed
tests/test_docs_version.py
+4 -1
file changed
tests/test_hub/test_add_btype.py
+4 -1
file changed
tests/test_hub/test_add_external_rpm.py
+4 -1
file changed
tests/test_hub/test_add_host.py
+4 -1
file changed
tests/test_hub/test_add_host_to_channel.py
+4 -2
file changed
tests/test_hub/test_apply_query_opts.py
+4 -1
file changed
tests/test_hub/test_cg_importer.py
+4 -2
file changed
tests/test_hub/test_check_volume_policy.py
+7 -5
file changed
tests/test_hub/test_complete_image_build.py
+7 -5
file changed
tests/test_hub/test_complete_maven_build.py
+4 -2
file changed
tests/test_hub/test_create_tag.py
+4 -1
file changed
tests/test_hub/test_delete_build.py
+4 -2
file changed
tests/test_hub/test_delete_tag.py
+4 -2
file changed
tests/test_hub/test_dist_repo.py
+4 -1
file changed
tests/test_hub/test_edit_host.py
+4 -2
file changed
tests/test_hub/test_edit_tag.py
+4 -2
file changed
tests/test_hub/test_getRPMDeps.py
+4 -2
file changed
tests/test_hub/test_get_active_repos.py
+4 -1
file changed
tests/test_hub/test_get_archive_file.py
+4 -2
file changed
tests/test_hub/test_get_build_logs.py
+4 -1
file changed
tests/test_hub/test_get_build_type.py
+4 -1
file changed
tests/test_hub/test_get_host.py
+4 -2
file changed
tests/test_hub/test_get_next_release.py
+17 -11
file changed
tests/test_hub/test_get_upload_path.py
+4 -2
file changed
tests/test_hub/test_get_user_perms.py
+5 -1
file changed
tests/test_hub/test_get_verify_class.py
+4 -2
file changed
tests/test_hub/test_group_operations.py
+4 -1
file changed
tests/test_hub/test_import_build.py
+4 -2
file changed
tests/test_hub/test_import_image_internal.py
+4 -1
file changed
tests/test_hub/test_insert_processor.py
+4 -2
file changed
tests/test_hub/test_list_archive_files.py
+4 -1
file changed
tests/test_hub/test_list_btypes.py
+4 -1
file changed
tests/test_hub/test_list_channels.py
+4 -1
file changed
tests/test_hub/test_list_hosts.py
+4 -1
file changed
tests/test_hub/test_list_task_output.py
+4 -1
file changed
tests/test_hub/test_listing.py
+4 -1
file changed
tests/test_hub/test_models/test_host.py
+4 -1
file changed
tests/test_hub/test_new_typed_build.py
+4 -1
file changed
tests/test_hub/test_notifications.py
+4 -1
file changed
tests/test_hub/test_policy_tests.py
+4 -1
file changed
tests/test_hub/test_query_processor.py
+4 -1
file changed
tests/test_hub/test_remove_host_from_channel.py
+4 -1
file changed
tests/test_hub/test_rpmdiff.py
+4 -1
file changed
tests/test_hub/test_set_host_enabled.py
+4 -1
file changed
tests/test_hub/test_tag_operations.py
+4 -1
file changed
tests/test_hub/test_task_wait_results.py
+4 -1
file changed
tests/test_hub/test_update_processor.py
+4 -1
file changed
tests/test_hub/test_user_groups.py
+9 -7
file changed
tests/test_hub/test_write_maven_repo_metadata.py
+4 -1
file changed
tests/test_hub/utils.py
+4 -1
file changed
tests/test_kojira/test_repo_manager.py
+5 -1
file changed
tests/test_lib/test_argspec.py
+4 -1
file changed
tests/test_lib/test_client_session.py
+4 -1
file changed
tests/test_lib/test_encode_datetime.py
+6 -2
file changed
tests/test_lib/test_fixEncoding.py
+5 -1
file changed
tests/test_lib/test_format_time.py
+4 -1
file changed
tests/test_lib/test_gen_mock_config.py
+4 -1
file changed
tests/test_lib/test_grab_session_options.py
+5 -3
file changed
tests/test_lib/test_gssapi.py
+4 -1
file changed
tests/test_lib/test_parsers.py
+4 -1
file changed
tests/test_lib/test_plugin.py
+5 -2
file changed
tests/test_lib/test_profiles.py
+76 -73
file changed
tests/test_lib/test_utils.py
+4 -1
file changed
tests/test_lib/test_xmlrpcplus.py
+4 -1
file changed
tests/test_lib_py2only/test_auth.py
+5 -3
file changed
tests/test_lib_py2only/test_krbv.py
+4 -1
file changed
tests/test_lib_py2only/test_policy.py
+4 -1
file changed
tests/test_lib_py2only/test_restart_tasks.py
+8 -4
file changed
tests/test_lib_py2only/test_tasks.py
+7 -3
file changed
tests/test_plugins/test_protonmsg.py
+28 -17
file changed
tests/test_plugins/test_runroot_builder.py
+4 -1
file changed
tests/test_plugins/test_runroot_cli.py
+4 -1
file changed
tests/test_plugins/test_runroot_hub.py
+4 -1
file changed
tests/test_plugins/test_save_failed_tree_builder.py
+4 -1
file changed
tests/test_plugins/test_save_failed_tree_cli.py
+5 -5
file changed
tests/test_scm.py
+5 -1
file changed
tests/test_www/test_taskinfo.py