jupyter-xeus / xeus-r

Jupyter kernel for the R programming language
Other
41 stars 5 forks source link

Use `publish_execution_result()` #33

Closed romainfrancois closed 9 months ago

romainfrancois commented 9 months ago

Our execute implementation is currently based on IRkernel's and therefore uses display for all results, and consequently does not use publish_execution_result()

The stock unit tests that we get from the 🍪 suggests that we do need to publish the results via publish_execution_result() rather than display.

24 is a first attempt to look at this, it may be a problem for:

romainfrancois commented 9 months ago

The trick that we inherit from IRkernel currently has to be compensated by a test trick .

def _execute_code(self, code, tests=True, silent=False, store_history=True):
        self.flush_channels()

        reply, output_msgs = self.execute_helper(code, silent=silent, store_history=store_history)

        self.assertEqual(reply['content']['status'], 'ok', '{0}: {0}'.format(reply['content'].get('ename'), reply['content'].get('evalue')))
        if tests:
            self.assertGreaterEqual(len(output_msgs), 1)
            # xeusr does the same as irkernel: only sends display_data, not execute_result
            self.assertEqual(output_msgs[0]['msg_type'], 'display_data')
        return reply, output_msgs

and redefine test_execute_result:

def test_execute_result(self):
        self.flush_channels()
        reply, output_msgs = self._execute_code(code="6*7")
        data = output_msgs[0]['content']['data']
        self.assertEqual(data['text/plain'], ['[1] 42'])