| |
@@ -1,13 +1,19 @@
|
| |
import re
|
| |
import unittest
|
| |
- import mock
|
| |
import configparser
|
| |
- from os.path import realpath, dirname
|
| |
- from ..copr_rpmbuild.builders.mock import MockBuilder
|
| |
import subprocess
|
| |
import datetime
|
| |
+ from os.path import realpath, dirname
|
| |
+
|
| |
+ from copr_rpmbuild.builders.mock import MockBuilder
|
| |
|
| |
- from unittest.mock import MagicMock
|
| |
+ try:
|
| |
+ from unittest import mock
|
| |
+ builtins = 'builtins'
|
| |
+ except ImportError:
|
| |
+ # Python 2 version depends on mock
|
| |
+ import mock
|
| |
+ builtins = '__builtin__'
|
| |
|
| |
class TestMockBuilder(unittest.TestCase):
|
| |
def setUp(self):
|
| |
@@ -35,6 +41,8 @@
|
| |
"task_id": "10-fedora-24-x86_64",
|
| |
"timeout": 21600,
|
| |
"use_bootstrap_container": False,
|
| |
+ "with_opts": [],
|
| |
+ "without_opts": [],
|
| |
}
|
| |
self.sourcedir = "/path/to/sourcedir"
|
| |
self.resultdir = "/path/to/resultdir"
|
| |
@@ -71,12 +79,12 @@
|
| |
self.assertEqual(config_opts["use_bootstrap_container"], False)
|
| |
self.assertEqual(config_opts["yum.conf"], [])
|
| |
|
| |
- @mock.patch("rpmbuild.copr_rpmbuild.builders.mock.get_mock_uniqueext")
|
| |
- @mock.patch("rpmbuild.copr_rpmbuild.builders.mock.subprocess.Popen")
|
| |
+ @mock.patch("copr_rpmbuild.builders.mock.get_mock_uniqueext")
|
| |
+ @mock.patch("copr_rpmbuild.builders.mock.GentlyTimeoutedPopen")
|
| |
def test_produce_rpm(self, popen_mock, get_mock_uniqueext_mock):
|
| |
builder = MockBuilder(self.task, self.sourcedir, self.resultdir, self.config)
|
| |
get_mock_uniqueext_mock.return_value = '2'
|
| |
- process = MagicMock(returncode=0)
|
| |
+ process = mock.MagicMock(returncode=0)
|
| |
popen_mock.return_value = process
|
| |
builder.produce_rpm("/path/to/pkg.src.rpm", "/path/to/configs", "/path/to/results")
|
| |
assert_cmd = ['unbuffer', '/usr/bin/mock',
|
| |
@@ -85,9 +93,11 @@
|
| |
'--resultdir', '/path/to/results',
|
| |
'--uniqueext', '2',
|
| |
'-r', 'child']
|
| |
- popen_mock.assert_called_with(assert_cmd, stdin=subprocess.PIPE, preexec_fn=builder.preexec_fn_build_stream)
|
| |
+ popen_mock.assert_called_with(assert_cmd, stdin=subprocess.PIPE,
|
| |
+ preexec_fn=builder.preexec_fn_build_stream,
|
| |
+ timeout=21600)
|
| |
|
| |
- @mock.patch('builtins.open', new_callable=mock.mock_open())
|
| |
+ @mock.patch('{}.open'.format(builtins), new_callable=mock.mock_open())
|
| |
def test_touch_success_file(self, mock_open):
|
| |
builder = MockBuilder(self.task, self.sourcedir, self.resultdir, self.config)
|
| |
builder.touch_success_file()
|
| |
As suggested in https://lists.fedoraproject.org/archives/list/copr-devel@lists.fedorahosted.org/thread/LNQZYFZJAWWRYN2PH7BSD6LXX3XUMGPG/, we should get rid of python3-mock and use unittest native python3 module. Only for python2 (copr-cli, python-copr, copr-rpmbuild), we should employ python2-mock, which is supposed to backport functionality from python3's unittest.mock into python2. Basically, we should be doing something like:
in our tests that should be run under python2 as well as well as python3. This is what this PR does.
I also needed to fix copr-rpmbuild tests under EPEL7 so that I could verify this change work. I enabled running the tests during build in
%check
phase.