diff --git a/ActionTree/__init__.py b/ActionTree/__init__.py index 291e881..9a7b1f4 100644 --- a/ActionTree/__init__.py +++ b/ActionTree/__init__.py @@ -81,7 +81,7 @@ def __init__(self, label, dependencies=[], resources_required={}, accept_failed_ """ :param label: A string used to represent the action in :class:`GanttChart` and :class:`DependencyGraph`. Can be retrieved by :attr:`label`. - :type label: string or None + :type label: str or None :param list(Action) dependencies: see :meth:`~.Action.add_dependency` :param resources_required: @@ -249,13 +249,13 @@ def action_started(self, time, action): :param Action action: the action. """ - def action_printed(self, time, action, text): + def action_printed(self, time, action, data): """ Called when an action prints something. - :param datetime.datetime time: the time at which the action printed the text. + :param datetime.datetime time: the time at which the action printed the data. :param Action action: the action. - :param str text: the text printed. + :param str data: the data printed. """ def action_successful(self, time, action, return_value): @@ -346,15 +346,15 @@ def _set_start_time(self, start_time): def _set_success(self, success_time, return_value): self.__success_time = success_time self.__return_value = return_value - self._add_output("") + self._add_output(b"") def _set_failure(self, failure_time, exception): self.__failure_time = failure_time self.__exception = exception - self._add_output("") + self._add_output(b"") def _add_output(self, output): - self.__output = (self.__output or "") + output + self.__output = (self.__output or b"") + output @property def status(self): @@ -958,10 +958,8 @@ def _handle_successful_event(self, action, success_time, return_value): self._deallocate_resources(action) def _handle_printed_event(self, action, print_time, data): - text = data.decode("utf8") # @todo DO NOT decode. - # We have no way to know the encoding used. Give bytes back to client and let them decode. - self.report.get_action_status(action)._add_output(text) - self.hooks.action_printed(print_time, action, text) + self.report.get_action_status(action)._add_output(data) + self.hooks.action_printed(print_time, action, data) def _handle_failed_event(self, action, failure_time, exception): self.report.get_action_status(action)._set_failure(failure_time, exception) diff --git a/ActionTree/tests/capture_output.py b/ActionTree/tests/capture_output.py index f405ddf..ed9afeb 100644 --- a/ActionTree/tests/capture_output.py +++ b/ActionTree/tests/capture_output.py @@ -13,13 +13,13 @@ def test_successful_nothing(self): a = self._action("a") report = execute(a) - self.assertEqual(report.get_action_status(a).output, "") + self.assertEqual(report.get_action_status(a).output, b"") def test_failed_nothing(self): a = self._action("a", exception=Exception()) report = execute(a, do_raise=False) - self.assertEqual(report.get_action_status(a).output, "") + self.assertEqual(report.get_action_status(a).output, b"") def test_canceled_nothing(self): a = self._action("a") @@ -32,25 +32,25 @@ def test_print(self): a = self._action("a", print_on_stdout="printed on stdout") report = execute(a) - self.assertEqual(report.get_action_status(a).output, "printed on stdout\n") + self.assertEqual(report.get_action_status(a).output, b"printed on stdout\n") def test_print_stderr(self): a = self._action("a", print_on_stderr="printed on stderr") report = execute(a) - self.assertEqual(report.get_action_status(a).output, "printed on stderr\n") + self.assertEqual(report.get_action_status(a).output, b"printed on stderr\n") def test_echo(self): a = self._action("a", echo_on_stdout="echoed on stdout") report = execute(a) - self.assertEqual(report.get_action_status(a).output, "echoed on stdout\n") + self.assertEqual(report.get_action_status(a).output, b"echoed on stdout\n") def test_puts(self): a = self._action("a", puts_on_stdout=b"putsed on stdout") report = execute(a) - self.assertEqual(report.get_action_status(a).output, "putsed on stdout\n") + self.assertEqual(report.get_action_status(a).output, b"putsed on stdout\n") def test_many_print(self): MANY = 5 @@ -61,5 +61,5 @@ def test_many_print(self): a.add_dependency(y) report = execute(a) - self.assertEqual(report.get_action_status(x).output, "x\n" * MANY) - self.assertEqual(report.get_action_status(y).output, "y\n" * MANY) + self.assertEqual(report.get_action_status(x).output, b"x\n" * MANY) + self.assertEqual(report.get_action_status(y).output, b"y\n" * MANY) diff --git a/ActionTree/tests/hooks.py b/ActionTree/tests/hooks.py index b442952..df980bf 100644 --- a/ActionTree/tests/hooks.py +++ b/ActionTree/tests/hooks.py @@ -100,7 +100,7 @@ def test_successful_action_print(self): ("pending", "a"), ("ready", "a"), ("started", "a"), - ("printed", "a", "something\n"), + ("printed", "a", b"something\n"), ("successful", "a", None), ] ) @@ -115,7 +115,7 @@ def test_failed_action_print(self): ("pending", "a"), ("ready", "a"), ("started", "a"), - ("printed", "a", "something\n"), + ("printed", "a", b"something\n"), ("failed", "a", "foo"), ] ) @@ -131,9 +131,9 @@ def test_print_several_times(self): ("pending", "a"), ("ready", "a"), ("started", "a"), - ("printed", "a", "something 1\n"), - ("printed", "a", "something 2\n"), - ("printed", "a", "something 3\n"), + ("printed", "a", b"something 1\n"), + ("printed", "a", b"something 2\n"), + ("printed", "a", b"something 3\n"), ("successful", "a", None), ] ) diff --git a/docs/reference.html b/docs/reference.html index 4538b57..7b6c766 100644 --- a/docs/reference.html +++ b/docs/reference.html @@ -103,7 +103,7 @@

Reference Parameters: