def test_run_build_success_py3(self): mock_res = Mock() with patch('%s.os.getcwd' % pbm) as mock_getcwd, \ patch('%s.os.chdir' % pbm) as mock_chdir, \ patch('%s.subprocess' % pbm, autospec=True) as mock_subprocess,\ patch('%s.locale' % pbm, autospec=True) as mock_locale: mock_getcwd.return_value = '/my/pwd' mock_locale.getdefaultlocale.return_value = ['foo', 'bar'] mock_locale.return_value = ['foo', 'bar'] mock_subprocess.check_output.return_value = mock_res res = self.cls.run_build('/repo/path') assert mock_getcwd.mock_calls == [call()] assert mock_chdir.mock_calls == [ call('/repo/path'), call('/my/pwd') ] assert mock_subprocess.mock_calls == [ call.check_output( ['./.rebuildbot.sh'], stderr=mock_subprocess.STDOUT ), call.check_output().decode('bar') ] assert res == mock_res.decode.return_value assert mock_res.mock_calls == [ call.decode('bar') ]
def test_run_build_exception_py3(self): ex = Exception('foo') def se_exc(foo, stderr=None): raise ex with patch('%s.os.getcwd' % pbm) as mock_getcwd, \ patch('%s.os.chdir' % pbm) as mock_chdir, \ patch('%s.subprocess' % pbm, autospec=True) as mock_subprocess,\ patch('%s.locale' % pbm) as mock_locale: mock_getcwd.return_value = '/my/pwd' mock_locale.getdefaultlocale.return_value = ['foo', 'bar'] mock_subprocess.check_output.side_effect = se_exc with pytest.raises(Exception) as excinfo: self.cls.run_build('/repo/path') assert mock_getcwd.mock_calls == [call()] assert mock_chdir.mock_calls == [ call('/repo/path'), call('/my/pwd') ] assert mock_subprocess.mock_calls == [ call.check_output( ['./.rebuildbot.sh'], stderr=mock_subprocess.STDOUT ) ] assert excinfo.value == ex
def test_passing_content_to_publish_should_call_pelican(): draftin_a_flask.subprocess = MagicMock() expected = [call.check_output([draftin_a_flask.PELICAN, draftin_a_flask.CONTENT, '-o', draftin_a_flask.OUTPUT, '-s', draftin_a_flask.PELICANCONF]), ] draftin_a_flask.publish('a name', 'This is some content') assert draftin_a_flask.subprocess.mock_calls == expected
def test_run_build_success_py27(self): with patch('%s.os.getcwd' % pbm) as mock_getcwd, \ patch('%s.os.chdir' % pbm) as mock_chdir, \ patch('%s.subprocess' % pbm, autospec=True) as mock_subprocess: mock_getcwd.return_value = '/my/pwd' res = self.cls.run_build('/repo/path') assert mock_getcwd.mock_calls == [call()] assert mock_chdir.mock_calls == [ call('/repo/path'), call('/my/pwd') ] assert mock_subprocess.mock_calls == [ call.check_output( ['./.rebuildbot.sh'], stderr=mock_subprocess.STDOUT ) ] assert res == mock_subprocess.check_output.return_value