This is an automated email from the ASF dual-hosted git repository.

robertwb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git


The following commit(s) were added to refs/heads/master by this push:
     new 2959fcc  BEAM-7477 add is not empty helper test method (#8742)
2959fcc is described below

commit 2959fcc062cd38d5e490fa18bf5f424c04f655d4
Author: Rakesh Kumar <rakeshcu...@gmail.com>
AuthorDate: Mon Jun 3 03:42:28 2019 -0700

    BEAM-7477 add is not empty helper test method (#8742)
---
 sdks/python/apache_beam/testing/util.py      | 14 ++++++++++++++
 sdks/python/apache_beam/testing/util_test.py | 11 +++++++++++
 2 files changed, 25 insertions(+)

diff --git a/sdks/python/apache_beam/testing/util.py 
b/sdks/python/apache_beam/testing/util.py
index 7e68540..3099b0f 100644
--- a/sdks/python/apache_beam/testing/util.py
+++ b/sdks/python/apache_beam/testing/util.py
@@ -40,6 +40,7 @@ __all__ = [
     'assert_that',
     'equal_to',
     'is_empty',
+    'is_not_empty',
     # open_shards is internal and has no backwards compatibility guarantees.
     'open_shards',
     'TestWindowedValue',
@@ -150,6 +151,19 @@ def is_empty():
   return _empty
 
 
+def is_not_empty():
+  """
+  This is test method which makes sure that the pcol is not empty and it has
+  some data in it.
+  :return:
+  """
+  def _not_empty(actual):
+    actual = list(actual)
+    if not actual:
+      raise BeamAssertException('Failed assert: pcol is empty')
+  return _not_empty
+
+
 def assert_that(actual, matcher, label='assert_that',
                 reify_windows=False, use_global_window=True):
   """A PTransform that checks a PCollection has an expected value.
diff --git a/sdks/python/apache_beam/testing/util_test.py 
b/sdks/python/apache_beam/testing/util_test.py
index 83b68e8..1fd1da6 100644
--- a/sdks/python/apache_beam/testing/util_test.py
+++ b/sdks/python/apache_beam/testing/util_test.py
@@ -23,10 +23,12 @@ import unittest
 
 from apache_beam import Create
 from apache_beam.testing.test_pipeline import TestPipeline
+from apache_beam.testing.util import BeamAssertException
 from apache_beam.testing.util import TestWindowedValue
 from apache_beam.testing.util import assert_that
 from apache_beam.testing.util import equal_to
 from apache_beam.testing.util import is_empty
+from apache_beam.testing.util import is_not_empty
 from apache_beam.transforms.window import GlobalWindow
 from apache_beam.transforms.window import IntervalWindow
 from apache_beam.utils.timestamp import MIN_TIMESTAMP
@@ -99,6 +101,15 @@ class UtilTest(unittest.TestCase):
       with TestPipeline() as p:
         assert_that(p | Create([1, 2, 3]), is_empty())
 
+  def test_assert_that_passes_is_not_empty(self):
+    with TestPipeline() as p:
+      assert_that(p | Create([1, 2, 3]), is_not_empty())
+
+  def test_assert_that_fails_on_empty_expected(self):
+    with self.assertRaises(BeamAssertException):
+      with TestPipeline() as p:
+        assert_that(p | Create([]), is_not_empty())
+
 
 if __name__ == '__main__':
   unittest.main()

Reply via email to