pabloem commented on a change in pull request #12107:
URL: https://github.com/apache/beam/pull/12107#discussion_r448112826



##########
File path: sdks/python/apache_beam/runners/interactive/utils.py
##########
@@ -204,3 +205,23 @@ def run_within_progress_indicator(*args, **kwargs):
       return func(*args, **kwargs)
 
   return run_within_progress_indicator
+
+
+def as_json(func):
+  # type: (Callable[..., Any]) -> Callable[..., Any]

Review comment:
       The callable returns string, right?
   ```suggestion
     # type: (Callable[..., Any]) -> Callable[..., str]
   ```

##########
File path: sdks/python/apache_beam/runners/interactive/utils_test.py
##########
@@ -195,5 +195,25 @@ def progress_indicated_dummy():
     mocked_javascript.assert_called_once()
 
 
+@unittest.skipIf(
+    not ie.current_env().is_interactive_ready,
+    '[interactive] dependency is not installed.')
+@unittest.skipIf(
+    sys.version_info < (3, 6), 'The tests require at least Python 3.6 to 
work.')
+class MessagingUtilTest(unittest.TestCase):
+  def setUp(self):
+    ie.new_env()
+
+  def test_as_json_decorator(self):
+    @utils.as_json
+    def dummy():
+      return {'a': [1, 2, 3], 'b': 4, 'c': '5', 'd': {'e': 'f'}}
+
+    # As of Python 3.6, for the CPython implementation of Python,
+    # dictionaries remember the order of items inserted.
+    self.assertEqual(
+        dummy(), '{"a": [1, 2, 3], "b": 4, "c": "5", "d": {"e": "f"}}')

Review comment:
       nit: you could do something like `json.loads(dummy(), SAMPLE_DATA)` 
instead of depending on the ordering.
   ```suggestion
           json.loads(dummy()), {"a": [1, 2, 3], "b": 4, "c": "5", "d": {"e": 
"f"}})
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to