Esempio n. 1
0
    def test_run_other_exception(self):
        ex_t, ex, tb = self.make_exc_info()

        def se_ex(foo):
            raise ex

        with patch('%s.clone_repo' % pb) as mock_clone, \
                patch('%s.run_build' % pb) as mock_run, \
                patch('%s.rmtree' % pbm) as mock_rmtree, \
                patch('%s.sys.exc_info' % pbm) as mock_excinfo, \
                patch('%s.get_time' % pb) as mock_time:
            mock_clone.return_value = ('/my/clone/path', 'repostr')
            mock_run.side_effect = se_ex
            mock_time.side_effect = [
                datetime(2015, 1, 1, 1, 0, 0),
                datetime(2015, 1, 1, 2, 0, 0),
            ]
            mock_excinfo.return_value = ex_t, ex, tb
            self.cls.run()
        assert mock_clone.mock_calls == [call()]
        assert mock_run.mock_calls == [call('/my/clone/path')]
        assert self.bi.mock_calls == [
            call.set_local_build(excinfo=ex, ex_type=ex_t, traceback=tb,
                                 start_dt=datetime(2015, 1, 1, 1, 0, 0),
                                 end_dt=datetime(2015, 1, 1, 2, 0, 0),
                                 repo_str='repostr')
        ]
        assert mock_rmtree.mock_calls == [call('/my/clone/path')]
Esempio n. 2
0
    def test_run_clone_exception(self):
        ex_t, ex, tb = self.make_exc_info()

        def clone_se():
            raise ex

        with patch('%s.clone_repo' % pb) as mock_clone, \
                patch('%s.run_build' % pb) as mock_run, \
                patch('%s.rmtree' % pbm) as mock_rmtree, \
                patch('%s.sys.exc_info' % pbm) as mock_excinfo, \
                patch('%s.get_time' % pb) as mock_time:
            mock_clone.side_effect = clone_se
            mock_run.return_value = 'my output'
            mock_time.side_effect = [
                datetime(2015, 1, 1, 1, 0, 0),
                datetime(2015, 1, 1, 2, 0, 0),
            ]
            mock_excinfo.return_value = ex_t, ex, tb
            self.cls.run()
        assert mock_clone.mock_calls == [call()]
        assert mock_run.mock_calls == []
        assert self.bi.mock_calls == [
            call.set_local_build(return_code=-1, excinfo=ex,
                                 ex_type=ex_t, traceback=tb)
        ]
        assert mock_rmtree.mock_calls == []
Esempio n. 3
0
 def test_run_ok(self):
     with patch('%s.clone_repo' % pb) as mock_clone, \
             patch('%s.run_build' % pb) as mock_run, \
             patch('%s.rmtree' % pbm) as mock_rmtree, \
             patch('%s.get_time' % pb) as mock_time:
         mock_clone.return_value = ('/my/clone/path', 'repostr')
         mock_run.return_value = 'my output'
         mock_time.side_effect = [
             datetime(2015, 1, 1, 1, 0, 0),
             datetime(2015, 1, 1, 2, 0, 0),
         ]
         self.cls.run()
     assert mock_clone.mock_calls == [call()]
     assert mock_run.mock_calls == [call('/my/clone/path')]
     assert self.bi.mock_calls == [
         call.set_local_build(return_code=0, output='my output',
                              start_dt=datetime(2015, 1, 1, 1, 0, 0),
                              end_dt=datetime(2015, 1, 1, 2, 0, 0),
                              repo_str='repostr')
     ]
     assert mock_rmtree.mock_calls == [call('/my/clone/path')]