From c61abac1377e4381fbfbfc4acdec1f9916f719c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Tue, 23 Feb 2016 15:26:28 +0100 Subject: [PATCH] [tests] Use temporary files for buildinstall MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of mocking open just write to the temporary file and then check its content. Signed-off-by: Lubomír Sedlář --- tests/test_buildinstall.py | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/tests/test_buildinstall.py b/tests/test_buildinstall.py index 756971f1..c3b52686 100755 --- a/tests/test_buildinstall.py +++ b/tests/test_buildinstall.py @@ -379,10 +379,8 @@ class BuildinstallThreadTestCase(PungiTestCase): @mock.patch('pungi.phases.buildinstall.KojiWrapper') @mock.patch('pungi.phases.buildinstall.get_buildroot_rpms') - @mock.patch('pungi.phases.buildinstall.open') @mock.patch('pungi.phases.buildinstall.run') - def test_buildinstall_thread_with_lorax_in_runroot(self, run, mock_open, - get_buildroot_rpms, KojiWrapperMock): + def test_buildinstall_thread_with_lorax_in_runroot(self, run, get_buildroot_rpms, KojiWrapperMock): compose = BuildInstallCompose(self.topdir, { 'buildinstall_method': 'lorax', 'runroot': True, @@ -414,16 +412,14 @@ class BuildinstallThreadTestCase(PungiTestCase): use_shell=True, task_id=True, packages=['strace', 'lorax'], mounts=[self.topdir])]) run_runroot_cmd(get_runroot_cmd.return_value, log_file='/log/buildinstall-Server.x86_64.log') - self.assertItemsEqual( - mock_open.return_value.write.mock_calls, - [mock.call('bash\nzsh')]) + with open(self.topdir + '/logs/x86_64/buildinstall-Server-RPMs.x86_64.log') as f: + rpms = f.read().strip().split('\n') + self.assertItemsEqual(rpms, ['bash', 'zsh']) @mock.patch('pungi.phases.buildinstall.KojiWrapper') @mock.patch('pungi.phases.buildinstall.get_buildroot_rpms') - @mock.patch('pungi.phases.buildinstall.open') @mock.patch('pungi.phases.buildinstall.run') - def test_buildinstall_thread_with_buildinstall_in_runroot(self, run, mock_open, - get_buildroot_rpms, KojiWrapperMock): + def test_buildinstall_thread_with_buildinstall_in_runroot(self, run, get_buildroot_rpms, KojiWrapperMock): compose = BuildInstallCompose(self.topdir, { 'buildinstall_method': 'buildinstall', 'runroot': True, @@ -456,16 +452,14 @@ class BuildinstallThreadTestCase(PungiTestCase): packages=['strace', 'anaconda'], mounts=[self.topdir])]) run_runroot_cmd(get_runroot_cmd.return_value, log_file=self.topdir + '/logs/buildinstall.x86_64.log') - self.assertItemsEqual( - mock_open.return_value.write.mock_calls, - [mock.call('bash\nzsh')]) + with open(self.topdir + '/logs/x86_64/buildinstall-RPMs.x86_64.log') as f: + rpms = f.read().strip().split('\n') + self.assertItemsEqual(rpms, ['bash', 'zsh']) @mock.patch('pungi.phases.buildinstall.KojiWrapper') @mock.patch('pungi.phases.buildinstall.get_buildroot_rpms') - @mock.patch('pungi.phases.buildinstall.open') @mock.patch('pungi.phases.buildinstall.run') - def test_buildinstall_fail_exit_code(self, run, mock_open, - get_buildroot_rpms, KojiWrapperMock): + def test_buildinstall_fail_exit_code(self, run, get_buildroot_rpms, KojiWrapperMock): compose = BuildInstallCompose(self.topdir, { 'buildinstall_method': 'buildinstall', 'runroot': True, @@ -500,10 +494,8 @@ class BuildinstallThreadTestCase(PungiTestCase): @mock.patch('pungi.phases.buildinstall.KojiWrapper') @mock.patch('pungi.phases.buildinstall.get_buildroot_rpms') - @mock.patch('pungi.phases.buildinstall.open') @mock.patch('pungi.phases.buildinstall.run') - def test_lorax_fail_exit_code(self, run, mock_open, - get_buildroot_rpms, KojiWrapperMock): + def test_lorax_fail_exit_code(self, run, get_buildroot_rpms, KojiWrapperMock): compose = BuildInstallCompose(self.topdir, { 'buildinstall_method': 'lorax', 'runroot': True,