コード例 #1
0
    def test_sends_correct_request_and_returns_when_resource_is_finished(self):
        self.conn.send_get_request.return_value = self.status_with(
            {'finished': True})
        a = Analysis('ID', self.conn)

        a.wait_until_finished()

        self.assert_get_request_was_sent_with('/ID/status')
コード例 #2
0
    def test_does_not_raise_exception_when_on_failure_is_none(self):
        self.conn.send_get_request.return_value = self.status_with({
            'finished': True,
            'failed': True,
            'error': 'error message'
        })
        a = Analysis('ID', self.conn)

        a.wait_until_finished(on_failure=None)
コード例 #3
0
    def test_does_not_raise_exception_when_on_failure_is_none(self):
        self.conn.send_get_request.return_value = self.status_with({
            'finished': True,
            'failed': True,
            'error': 'error message'
        })
        a = Analysis('ID', self.conn)

        a.wait_until_finished(on_failure=None)
コード例 #4
0
    def test_sends_correct_request_and_returns_when_resource_is_finished(self):
        self.conn.send_get_request.return_value = self.status_with({
            'finished': True
        })
        a = Analysis('ID', self.conn)

        a.wait_until_finished()

        self.assert_get_request_was_sent_with('/ID/status')
コード例 #5
0
    def test_raises_exception_by_default_when_resource_failed(self):
        self.conn.send_get_request.return_value = self.status_with({
            'finished': True,
            'failed': True,
            'error': 'error message'
        })
        a = Analysis('ID', self.conn)

        with self.assertRaises(AnalysisFailedError):
            a.wait_until_finished()
コード例 #6
0
    def test_raises_exception_by_default_when_resource_failed(self):
        self.conn.send_get_request.return_value = self.status_with({
            'finished': True,
            'failed': True,
            'error': 'error message'
        })
        a = Analysis('ID', self.conn)

        with self.assertRaises(AnalysisFailedError):
            a.wait_until_finished()
コード例 #7
0
    def test_calls_on_failure_when_it_is_callable(self):
        self.conn.send_get_request.return_value = self.status_with({
            'finished': True,
            'succeeded': False,
            'failed': True,
            'error': 'error message'
        })
        a = Analysis('ID', self.conn)
        on_failure = mock.Mock()

        a.wait_until_finished(on_failure=on_failure)

        on_failure.assert_called_once_with('error message')
コード例 #8
0
    def test_waits_until_analysis_finishes(self):
        self.conn.send_get_request.side_effect = [
            self.status_with({
                'finished': False,
                'succeeded': False
            }), self.status_with({
                'finished': True,
                'succeeded': True
            })
        ]
        a = Analysis('ID', self.conn)

        a.wait_until_finished()
コード例 #9
0
    def test_calls_on_failure_when_it_is_callable(self):
        self.conn.send_get_request.return_value = self.status_with({
            'finished': True,
            'succeeded': False,
            'failed': True,
            'error': 'error message'
        })
        a = Analysis('ID', self.conn)
        on_failure = mock.Mock()

        a.wait_until_finished(on_failure=on_failure)

        on_failure.assert_called_once_with('error message')
コード例 #10
0
    def test_waits_until_analysis_finishes(self):
        self.conn.send_get_request.side_effect = [
            self.status_with({
                'finished': False,
                'succeeded': False
            }), self.status_with({
                'finished': True,
                'succeeded': True
            })
        ]
        a = Analysis('ID', self.conn)

        a.wait_until_finished()
コード例 #11
0
    def test_repr_returns_correct_value(self):
        a = Analysis('ID', self.conn)

        self.assertEqual(
            repr(a),
            "<retdec.analysis.Analysis id='ID'>"
        )
コード例 #12
0
    def test_get_output_obtains_file_contents(self):
        a = Analysis('ID', self.conn)

        self.assert_obtains_file_contents(
            a.get_output,
            '/ID/output',
            is_text_file=True
        )
コード例 #13
0
ファイル: fileinfo.py プロジェクト: fangbei/retdec-python
    def start_analysis(self, **kwargs):
        """Starts an analysis with the given parameters.

        :param input_file: File to be analyzed (**required**).
        :type input_file: str or file-like object
        :param verbose: Should the analysis produce a detailed output?
                        ``False`` by default.
        :type verbose: bool

        :returns: Started analysis (:class:`~retdec.analysis.Analysis`).
        """
        conn = self._create_new_api_connection('/fileinfo/analyses')
        id = self._start_analysis(conn, **kwargs)
        return Analysis(id, conn)