From 072b38e492aedd5f86241f9bb8f3bf3b573739ac Mon Sep 17 00:00:00 2001 From: Chenxiong Qi Date: Feb 03 2018 11:18:09 +0000 Subject: Fix Python 3 incompatible code in tests Signed-off-by: Chenxiong Qi --- diff --git a/test/test_cli.py b/test/test_cli.py index c3e0a73..c84b57f 100644 --- a/test/test_cli.py +++ b/test/test_cli.py @@ -75,7 +75,7 @@ class TestUpdate(CliTestCase): def create_bodhi_update(self, cli): mocked_open = mock_open(read_data=self.fake_clog) - with patch('__builtin__.open', mocked_open): + with patch('six.moves.builtins.open', mocked_open): with patch('os.unlink') as unlink: cli.update() diff --git a/test/test_commands.py b/test/test_commands.py index d3bb8c4..acbf5e4 100644 --- a/test/test_commands.py +++ b/test/test_commands.py @@ -15,6 +15,7 @@ from pyrpkg.errors import rpkgError from fedpkg import _get_bodhi_version from utils import CommandTestCase from mock import call, patch, Mock, PropertyMock, mock_open +from six.moves import builtins class TestDetermineRuntimeEnv(CommandTestCase): @@ -120,7 +121,7 @@ class TestLoadUser(CommandTestCase): def test_load_from_fedora_upn(self, exists, expanduser): exists.return_value = True expanduser.return_value = '/home/user/.fedora.upn' - with patch('__builtin__.open', mock_open(read_data='user')) as m: + with patch.object(builtins, 'open', mock_open(read_data='user')) as m: self.cmd.load_user() m.assert_has_calls([ call(expanduser.return_value, 'r') diff --git a/test/test_retire.py b/test/test_retire.py index 6edfec7..26a5ebd 100644 --- a/test/test_retire.py +++ b/test/test_retire.py @@ -4,10 +4,10 @@ import os import shutil import unittest import mock -import ConfigParser import tempfile import subprocess +from six.moves import configparser from fedpkg.cli import fedpkgClient @@ -47,12 +47,13 @@ class RetireTestCase(unittest.TestCase): def _get_latest_commit(self): proc = subprocess.Popen(['git', 'log', '-n', '1', '--pretty=%s'], - cwd=self.tmpdir, stdout=subprocess.PIPE) + cwd=self.tmpdir, stdout=subprocess.PIPE, + universal_newlines=True) out, err = proc.communicate() return out.strip() def _fake_client(self, args): - config = ConfigParser.SafeConfigParser() + config = configparser.SafeConfigParser() config.read(TEST_CONFIG) with mock.patch('sys.argv', new=args): client = fedpkgClient(config)