| |
@@ -673,35 +673,35 @@
|
| |
|
| |
expected_cmd = ['rpmbuild'] + cli.cmd.rpmdefines + \
|
| |
['--nodeps', '-bs', os.path.join(cli.cmd.path, cli.cmd.spec)]
|
| |
- _run_command.assert_called_once_with(expected_cmd, shell=True)
|
| |
+ _run_command.assert_called_once_with(expected_cmd)
|
| |
|
| |
@patch('pyrpkg.Commands._run_command')
|
| |
def test_srpm_with_options(self, _run_command):
|
| |
cli_cmd = ['rpkg', '--path', self.cloned_repo_path, '--release', 'rhel-6', 'srpm',
|
| |
- '--define', '"macro1 meansthis"']
|
| |
+ '--define', 'macro1 meansthis']
|
| |
|
| |
with patch('sys.argv', new=cli_cmd):
|
| |
cli = self.new_cli()
|
| |
cli.srpm()
|
| |
|
| |
expected_cmd = ['rpmbuild'] + cli.cmd.rpmdefines + \
|
| |
- ['--define', '"macro1 meansthis"', '--nodeps', '-bs',
|
| |
+ ['--define', 'macro1 meansthis', '--nodeps', '-bs',
|
| |
os.path.join(cli.cmd.path, cli.cmd.spec)]
|
| |
- _run_command.assert_called_once_with(expected_cmd, shell=True)
|
| |
+ _run_command.assert_called_once_with(expected_cmd)
|
| |
|
| |
@patch('pyrpkg.Commands._run_command')
|
| |
def test_srpm_with_extra_args(self, _run_command):
|
| |
cli_cmd = ['rpkg', '--path', self.cloned_repo_path, '--release', 'rhel-6', 'srpm',
|
| |
- '--', '--define', '"name body"', '--undefine', 'python']
|
| |
+ '--', '--define', 'name body', '--undefine', 'python']
|
| |
|
| |
with patch('sys.argv', new=cli_cmd):
|
| |
cli = self.new_cli()
|
| |
cli.srpm()
|
| |
|
| |
expected_cmd = ['rpmbuild'] + cli.cmd.rpmdefines + \
|
| |
- ['--define', shlex.quote('"name body"'), '--undefine', 'python', '--nodeps', '-bs',
|
| |
+ ['--define', shlex.quote('name body'), '--undefine', 'python', '--nodeps', '-bs',
|
| |
os.path.join(cli.cmd.path, cli.cmd.spec)]
|
| |
- _run_command.assert_called_once_with(expected_cmd, shell=True)
|
| |
+ _run_command.assert_called_once_with(expected_cmd)
|
| |
|
| |
|
| |
class TestCompile(CliTestCase):
|
| |
@@ -719,7 +719,7 @@
|
| |
spec = os.path.join(cli.cmd.path, cli.cmd.spec)
|
| |
rpmbuild = ['rpmbuild'] + cli.cmd.rpmdefines + ['-bc', spec]
|
| |
|
| |
- _run_command.assert_called_once_with(rpmbuild, shell=True)
|
| |
+ _run_command.assert_called_once_with(rpmbuild)
|
| |
|
| |
@patch('pyrpkg.Commands._run_command')
|
| |
def test_compile_with_options(self, _run_command):
|
| |
@@ -735,11 +735,11 @@
|
| |
|
| |
spec = os.path.join(cli.cmd.path, cli.cmd.spec)
|
| |
rpmbuild = ['rpmbuild'] + cli.cmd.rpmdefines + \
|
| |
- ["--define '_builddir %s'" % builddir, '--target', 'i686',
|
| |
+ ['--define', '_builddir %s' % builddir, '--target', 'i686',
|
| |
'--define', 'macro1 meansthis', '--rmspec', '--short-circuit',
|
| |
'--nocheck', '--quiet', '-bc', spec]
|
| |
|
| |
- _run_command.assert_called_once_with(rpmbuild, shell=True)
|
| |
+ _run_command.assert_called_once_with(rpmbuild)
|
| |
|
| |
|
| |
class TestPrep(CliTestCase):
|
| |
@@ -756,7 +756,7 @@
|
| |
|
| |
spec = os.path.join(cli.cmd.path, cli.cmd.spec)
|
| |
rpmbuild = ['rpmbuild'] + cli.cmd.rpmdefines + ['--nodeps', '-bp', spec]
|
| |
- _run_command.assert_called_once_with(rpmbuild, shell=True)
|
| |
+ _run_command.assert_called_once_with(rpmbuild)
|
| |
|
| |
@patch('pyrpkg.Commands._run_command')
|
| |
def test_prep_with_options(self, _run_command):
|
| |
@@ -775,11 +775,11 @@
|
| |
|
| |
spec = os.path.join(cli.cmd.path, cli.cmd.spec)
|
| |
rpmbuild = ['rpmbuild'] + cli.cmd.rpmdefines + [
|
| |
- "--define '_builddir %s'" % builddir, '--target', 'i686', '-v',
|
| |
- '--quiet', "--define '_buildrootdir %s'" % buildrootdir,
|
| |
+ '--define', '_builddir %s' % builddir, '--target', 'i686', '-v',
|
| |
+ '--quiet', '--define', '_buildrootdir %s' % buildrootdir,
|
| |
'--nodeps', '-bp', spec
|
| |
]
|
| |
- _run_command.assert_called_once_with(rpmbuild, shell=True)
|
| |
+ _run_command.assert_called_once_with(rpmbuild)
|
| |
|
| |
@patch('pyrpkg.Commands._run_command')
|
| |
def test_prep_extra_args_with_space(self, _run_command):
|
| |
@@ -797,7 +797,7 @@
|
| |
shlex.quote(first_arg_with_space),
|
| |
shlex.quote(second_arg_with_space),
|
| |
'--nodeps', '-bp', spec]
|
| |
- _run_command.assert_called_once_with(rpmbuild, shell=True)
|
| |
+ _run_command.assert_called_once_with(rpmbuild)
|
| |
|
| |
|
| |
class TestInstall(CliTestCase):
|
| |
@@ -815,7 +815,7 @@
|
| |
spec = os.path.join(cli.cmd.path, cli.cmd.spec)
|
| |
rpmbuild = ['rpmbuild'] + cli.cmd.rpmdefines + ['-bi', spec]
|
| |
|
| |
- _run_command.assert_called_once_with(rpmbuild, shell=True)
|
| |
+ _run_command.assert_called_once_with(rpmbuild)
|
| |
|
| |
@patch('pyrpkg.Commands._run_command')
|
| |
def test_install_with_options(self, _run_command):
|
| |
@@ -834,37 +834,55 @@
|
| |
|
| |
spec = os.path.join(cli.cmd.path, cli.cmd.spec)
|
| |
rpmbuild = ['rpmbuild'] + cli.cmd.rpmdefines + [
|
| |
- "--define '_builddir %s'" % builddir, '--target', 'i686',
|
| |
+ '--define', '_builddir %s' % builddir, '--target', 'i686',
|
| |
'--nocheck', '--quiet',
|
| |
- "--define '_buildrootdir %s'" % buildrootdir,
|
| |
+ '--define', '_buildrootdir %s' % buildrootdir,
|
| |
'-bi', spec
|
| |
]
|
| |
|
| |
- _run_command.assert_called_once_with(rpmbuild, shell=True)
|
| |
+ _run_command.assert_called_once_with(rpmbuild)
|
| |
|
| |
|
| |
class TestLocal(CliTestCase):
|
| |
|
| |
create_repo_per_test = False
|
| |
|
| |
- @patch('pyrpkg.subprocess.check_call')
|
| |
- def test_local(self, check_call):
|
| |
+ @patch('subprocess.Popen')
|
| |
+ @patch('pyrpkg.Commands.rel')
|
| |
+ @patch('pyrpkg.Commands.ver')
|
| |
+ def test_local(self, ver, rel, popen):
|
| |
cli_cmd = ['rpkg', '--path', self.cloned_repo_path, '--release', 'rhel-6', 'local']
|
| |
|
| |
+ rel.__str__ = Mock()
|
| |
+ rel.__str__.return_value = '2.el6'
|
| |
+ ver.__str__ = Mock()
|
| |
+ ver.__str__.return_value = '1.2'
|
| |
+
|
| |
with patch('sys.argv', new=cli_cmd):
|
| |
cli = self.new_cli()
|
| |
cli.local()
|
| |
|
| |
spec = os.path.join(cli.cmd.path, cli.cmd.spec)
|
| |
rpmbuild = ['rpmbuild'] + cli.cmd.rpmdefines + ['-ba', spec]
|
| |
- tee = ['tee', '.build-%s-%s.log' % (cli.cmd.ver, cli.cmd.rel)]
|
| |
- cmd = '%s 2>&1 | %s; exit "${PIPESTATUS[0]} ${pipestatus[1]}"' % (
|
| |
- ' '.join(rpmbuild), ' '.join(tee)
|
| |
- )
|
| |
- check_call.assert_called_once_with(cmd, shell=True)
|
| |
+ tee = ('tee', '.build-%s-%s.log' % (cli.cmd.ver, cli.cmd.rel))
|
| |
+
|
| |
+ popen.assert_has_calls([
|
| |
+ # at the beginning of this list, there are other calls from load_nameverrel
|
| |
+ call(rpmbuild, stdout=-1, stderr=-2),
|
| |
+ # I can't match this call - stdin=Mock has it's dynamic id. Therefore any_oreder=True
|
| |
+ # call(tee, stdin=Mock(), stdout=-1), # check call [-3] separately
|
| |
+ call().stdout.close(),
|
| |
+ call().communicate(),
|
| |
+ ], any_order=True)
|
| |
|
| |
- @patch('pyrpkg.subprocess.check_call')
|
| |
- def test_local_with_options(self, check_call):
|
| |
+ tee_call_arg = popen.mock_calls[-3]
|
| |
+ if 'args' in dir(tee_call_arg): # doesn't work in <=py36
|
| |
+ self.assertEqual(tee, tee_call_arg.args[0])
|
| |
+
|
| |
+ @patch('subprocess.Popen')
|
| |
+ @patch('pyrpkg.Commands.rel')
|
| |
+ @patch('pyrpkg.Commands.ver')
|
| |
+ def test_local_with_options(self, ver, rel, popen):
|
| |
builddir = os.path.join(self.cloned_repo_path, 'this-builddir')
|
| |
buildrootdir = os.path.join(self.cloned_repo_path, 'this-buildrootdir')
|
| |
|
| |
@@ -874,6 +892,11 @@
|
| |
'--with', 'a', '--without', 'b', '--buildrootdir', buildrootdir,
|
| |
'--', '--clean']
|
| |
|
| |
+ rel.__str__ = Mock()
|
| |
+ rel.__str__.return_value = '2.el6'
|
| |
+ ver.__str__ = Mock()
|
| |
+ ver.__str__.return_value = '1.2'
|
| |
+
|
| |
with patch('sys.argv', new=cli_cmd):
|
| |
cli = self.new_cli()
|
| |
cli.local()
|
| |
@@ -881,18 +904,25 @@
|
| |
spec = os.path.join(cli.cmd.path, cli.cmd.spec)
|
| |
rpmbuild = ['rpmbuild'] + cli.cmd.rpmdefines + [
|
| |
'--with', 'a', '--without', 'b',
|
| |
- "--define '_builddir %s'" % builddir,
|
| |
+ '--define', '_builddir %s' % builddir,
|
| |
'--target', 'i686', '--clean', '--quiet',
|
| |
- "--define '_buildrootdir %s'" % buildrootdir,
|
| |
+ '--define', '_buildrootdir %s' % buildrootdir,
|
| |
'-ba', spec
|
| |
]
|
| |
- tee = ['tee', '.build-%s-%s.log' % (cli.cmd.ver, cli.cmd.rel)]
|
| |
+ tee = ('tee', '.build-%s-%s.log' % (cli.cmd.ver, cli.cmd.rel))
|
| |
|
| |
- cmd = '%s 2>&1 | %s; exit "${PIPESTATUS[0]} ${pipestatus[1]}"' % (
|
| |
- ' '.join(rpmbuild), ' '.join(tee)
|
| |
- )
|
| |
+ popen.assert_has_calls([
|
| |
+ # at the beginning of this list, there are other calls from load_nameverrel
|
| |
+ call(rpmbuild, stdout=-1, stderr=-2),
|
| |
+ # I can't match this call - stdin=Mock has it's dynamic id. Therefore any_oreder=True
|
| |
+ # call(tee, stdin=Mock(), stdout=-1), # check call [-3] separately
|
| |
+ call().stdout.close(),
|
| |
+ call().communicate(),
|
| |
+ ], any_order=True)
|
| |
|
| |
- check_call.assert_called_once_with(cmd, shell=True)
|
| |
+ tee_call_arg = popen.mock_calls[-3]
|
| |
+ if 'args' in dir(tee_call_arg): # doesn't work in <=py36
|
| |
+ self.assertEqual(tee, tee_call_arg.args[0])
|
| |
|
| |
|
| |
class TestVerifyFiles(CliTestCase):
|
| |
@@ -909,7 +939,7 @@
|
| |
|
| |
spec = os.path.join(cli.cmd.path, cli.cmd.spec)
|
| |
rpmbuild = ['rpmbuild'] + cli.cmd.rpmdefines + ['-bl', spec]
|
| |
- _run_command.assert_called_once_with(rpmbuild, shell=True)
|
| |
+ _run_command.assert_called_once_with(rpmbuild)
|
| |
|
| |
@patch('pyrpkg.Commands._run_command')
|
| |
def test_verify_files_with_options(self, _run_command):
|
| |
@@ -928,12 +958,12 @@
|
| |
|
| |
spec = os.path.join(cli.cmd.path, cli.cmd.spec)
|
| |
rpmbuild = ['rpmbuild'] + cli.cmd.rpmdefines + [
|
| |
- "--define '_builddir %s'" % builddir,
|
| |
+ '--define', '_builddir %s' % builddir,
|
| |
'--quiet',
|
| |
- "--define '_buildrootdir %s'" % buildrootdir,
|
| |
+ '--define', '_buildrootdir %s' % buildrootdir,
|
| |
'-bl', spec
|
| |
]
|
| |
- _run_command.assert_called_once_with(rpmbuild, shell=True)
|
| |
+ _run_command.assert_called_once_with(rpmbuild)
|
| |
|
| |
|
| |
class TestVerrel(CliTestCase):
|
| |
@@ -1162,7 +1192,7 @@
|
| |
|
| |
_run_command.assert_has_calls([
|
| |
call(['rpmlint', '--version'], return_stdout=True, return_text=True),
|
| |
- call(['rpmlint', os.path.join(cli.cmd.path, cli.cmd.spec)], shell=True),
|
| |
+ call(['rpmlint', os.path.join(cli.cmd.path, cli.cmd.spec)]),
|
| |
])
|
| |
|
| |
@patch('pyrpkg.Commands._run_command')
|
| |
@@ -1179,7 +1209,7 @@
|
| |
|
| |
_run_command.assert_has_calls([
|
| |
call(['rpmlint', '--version'], return_stdout=True, return_text=True),
|
| |
- call(['rpmlint', '-i', os.path.join(cli.cmd.path, cli.cmd.spec)], shell=True),
|
| |
+ call(['rpmlint', '-i', os.path.join(cli.cmd.path, cli.cmd.spec)]),
|
| |
])
|
| |
|
| |
@patch('pyrpkg.Commands._run_command')
|
| |
@@ -1196,7 +1226,7 @@
|
| |
|
| |
_run_command.assert_has_calls([
|
| |
call(['rpmlint', '--version'], return_stdout=True, return_text=True),
|
| |
- call(['rpmlint', '--info', os.path.join(cli.cmd.path, cli.cmd.spec)], shell=True),
|
| |
+ call(['rpmlint', '--info', os.path.join(cli.cmd.path, cli.cmd.spec)]),
|
| |
])
|
| |
|
| |
@patch('pyrpkg.Commands._run_command')
|
| |
@@ -1215,8 +1245,7 @@
|
| |
|
| |
_run_command.assert_has_calls([
|
| |
call(['rpmlint', '--version'], return_stdout=True, return_text=True),
|
| |
- call(['rpmlint', '-f', lint_config_path, os.path.join(cli.cmd.path, cli.cmd.spec)],
|
| |
- shell=True),
|
| |
+ call(['rpmlint', '-f', lint_config_path, os.path.join(cli.cmd.path, cli.cmd.spec)],),
|
| |
])
|
| |
|
| |
@patch('pyrpkg.Commands._run_command')
|
| |
@@ -1235,8 +1264,7 @@
|
| |
|
| |
_run_command.assert_has_calls([
|
| |
call(['rpmlint', '--version'], return_stdout=True, return_text=True),
|
| |
- call(['rpmlint', '-r', lint_config_path, os.path.join(cli.cmd.path, cli.cmd.spec)],
|
| |
- shell=True),
|
| |
+ call(['rpmlint', '-r', lint_config_path, os.path.join(cli.cmd.path, cli.cmd.spec)],),
|
| |
])
|
| |
|
| |
@patch('pyrpkg.Commands._run_command')
|
| |
@@ -1257,8 +1285,7 @@
|
| |
|
| |
_run_command.assert_has_calls([
|
| |
call(['rpmlint', '--version'], return_stdout=True, return_text=True),
|
| |
- call(['rpmlint', '-f', lint_config_path, os.path.join(cli.cmd.path, cli.cmd.spec)],
|
| |
- shell=True),
|
| |
+ call(['rpmlint', '-f', lint_config_path, os.path.join(cli.cmd.path, cli.cmd.spec)],),
|
| |
])
|
| |
|
| |
@patch('pyrpkg.Commands._run_command')
|
| |
@@ -1281,8 +1308,7 @@
|
| |
_run_command.assert_has_calls([
|
| |
call(['rpmlint', '--version'], return_stdout=True, return_text=True),
|
| |
call(['rpmlint', '-f', custom_lint_config_path,
|
| |
- os.path.join(cli.cmd.path, cli.cmd.spec)],
|
| |
- shell=True),
|
| |
+ os.path.join(cli.cmd.path, cli.cmd.spec)],),
|
| |
])
|
| |
|
| |
|
| |
@@ -3654,7 +3680,7 @@
|
| |
self.assert_option_srpm_use()
|
| |
|
| |
args, kwargs = _run_command.call_args
|
| |
- self.assertEqual({'shell': True}, kwargs)
|
| |
+ self.assertEqual({}, kwargs)
|
| |
rpmbuild_cmd, = args
|
| |
self.assertIn('-bs', rpmbuild_cmd)
|
| |
|
| |
JIRA: RHELCMP-9241
These changes will probably require similar steps for dependent tools like rhpkg and fedpkg.
Signed-off-by: Ondrej Nosek onosek@redhat.com