This is an automated email from the ASF dual-hosted git repository. altay 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 ed83bef Futurize testing subpackage new 22407e3 This closes #5352 ed83bef is described below commit ed83bef86e4a9e751c48a101fbd6f16af5112b90 Author: Matthias Feys <matth...@ml6.eu> AuthorDate: Mon May 14 13:21:35 2018 +0200 Futurize testing subpackage --- sdks/python/apache_beam/testing/__init__.py | 1 + .../apache_beam/testing/pipeline_verifiers.py | 2 + .../apache_beam/testing/pipeline_verifiers_test.py | 3 ++ sdks/python/apache_beam/testing/test_pipeline.py | 2 + .../apache_beam/testing/test_pipeline_test.py | 2 + sdks/python/apache_beam/testing/test_stream.py | 51 ++++++++++++++++------ .../python/apache_beam/testing/test_stream_test.py | 2 + sdks/python/apache_beam/testing/test_utils.py | 3 ++ sdks/python/apache_beam/testing/test_utils_test.py | 4 +- sdks/python/apache_beam/testing/util.py | 4 ++ sdks/python/apache_beam/testing/util_test.py | 2 + sdks/python/tox.ini | 1 + 12 files changed, 63 insertions(+), 14 deletions(-) diff --git a/sdks/python/apache_beam/testing/__init__.py b/sdks/python/apache_beam/testing/__init__.py index cce3aca..f4f43cb 100644 --- a/sdks/python/apache_beam/testing/__init__.py +++ b/sdks/python/apache_beam/testing/__init__.py @@ -14,3 +14,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # +from __future__ import absolute_import diff --git a/sdks/python/apache_beam/testing/pipeline_verifiers.py b/sdks/python/apache_beam/testing/pipeline_verifiers.py index c421e25..1178672 100644 --- a/sdks/python/apache_beam/testing/pipeline_verifiers.py +++ b/sdks/python/apache_beam/testing/pipeline_verifiers.py @@ -22,6 +22,8 @@ of test pipeline job. Customized verifier should extend `hamcrest.core.base_matcher.BaseMatcher` and override _matches. """ +from __future__ import absolute_import + import logging import time diff --git a/sdks/python/apache_beam/testing/pipeline_verifiers_test.py b/sdks/python/apache_beam/testing/pipeline_verifiers_test.py index bc8789f..dd7cf6d 100644 --- a/sdks/python/apache_beam/testing/pipeline_verifiers_test.py +++ b/sdks/python/apache_beam/testing/pipeline_verifiers_test.py @@ -17,9 +17,12 @@ """Unit tests for the test pipeline verifiers""" +from __future__ import absolute_import + import logging import tempfile import unittest +from builtins import range from hamcrest import assert_that as hc_assert_that from mock import Mock diff --git a/sdks/python/apache_beam/testing/test_pipeline.py b/sdks/python/apache_beam/testing/test_pipeline.py index 0525945..4e4c928 100644 --- a/sdks/python/apache_beam/testing/test_pipeline.py +++ b/sdks/python/apache_beam/testing/test_pipeline.py @@ -17,6 +17,8 @@ """Test Pipeline, a wrapper of Pipeline for test purpose""" +from __future__ import absolute_import + import argparse import shlex diff --git a/sdks/python/apache_beam/testing/test_pipeline_test.py b/sdks/python/apache_beam/testing/test_pipeline_test.py index c642c65..62cee10 100644 --- a/sdks/python/apache_beam/testing/test_pipeline_test.py +++ b/sdks/python/apache_beam/testing/test_pipeline_test.py @@ -17,6 +17,8 @@ """Unit test for the TestPipeline class""" +from __future__ import absolute_import + import logging import unittest diff --git a/sdks/python/apache_beam/testing/test_stream.py b/sdks/python/apache_beam/testing/test_stream.py index 8a63e7b..caa74ec 100644 --- a/sdks/python/apache_beam/testing/test_stream.py +++ b/sdks/python/apache_beam/testing/test_stream.py @@ -19,9 +19,14 @@ For internal use only; no backwards-compatibility guarantees. """ +from __future__ import absolute_import from abc import ABCMeta from abc import abstractmethod +from builtins import object +from functools import total_ordering + +from future.utils import with_metaclass from apache_beam import coders from apache_beam import core @@ -41,18 +46,20 @@ __all__ = [ ] -class Event(object): +@total_ordering +class Event(with_metaclass(ABCMeta, object)): """Test stream event to be emitted during execution of a TestStream.""" - __metaclass__ = ABCMeta + @abstractmethod + def __eq__(self, other): + raise NotImplementedError - def __cmp__(self, other): - if type(self) is not type(other): - return cmp(type(self), type(other)) - return self._typed_cmp(other) + @abstractmethod + def __hash__(self): + raise NotImplementedError @abstractmethod - def _typed_cmp(self, other): + def __lt__(self, other): raise NotImplementedError @@ -62,8 +69,14 @@ class ElementEvent(Event): def __init__(self, timestamped_values): self.timestamped_values = timestamped_values - def _typed_cmp(self, other): - return cmp(self.timestamped_values, other.timestamped_values) + def __eq__(self, other): + return self.timestamped_values == other.timestamped_values + + def __hash__(self): + return hash(self.timestamped_values) + + def __lt__(self, other): + return self.timestamped_values < other.timestamped_values class WatermarkEvent(Event): @@ -72,8 +85,14 @@ class WatermarkEvent(Event): def __init__(self, new_watermark): self.new_watermark = timestamp.Timestamp.of(new_watermark) - def _typed_cmp(self, other): - return cmp(self.new_watermark, other.new_watermark) + def __eq__(self, other): + return self.new_watermark == other.new_watermark + + def __hash__(self): + return hash(self.new_watermark) + + def __lt__(self, other): + return self.new_watermark < other.new_watermark class ProcessingTimeEvent(Event): @@ -82,8 +101,14 @@ class ProcessingTimeEvent(Event): def __init__(self, advance_by): self.advance_by = timestamp.Duration.of(advance_by) - def _typed_cmp(self, other): - return cmp(self.advance_by, other.advance_by) + def __eq__(self, other): + return self.advance_by == other.advance_by + + def __hash__(self): + return hash(self.advance_by) + + def __lt__(self, other): + return self.advance_by < other.advance_by class TestStream(PTransform): diff --git a/sdks/python/apache_beam/testing/test_stream_test.py b/sdks/python/apache_beam/testing/test_stream_test.py index a907c18..3297f63 100644 --- a/sdks/python/apache_beam/testing/test_stream_test.py +++ b/sdks/python/apache_beam/testing/test_stream_test.py @@ -17,6 +17,8 @@ """Unit tests for the test_stream module.""" +from __future__ import absolute_import + import unittest import apache_beam as beam diff --git a/sdks/python/apache_beam/testing/test_utils.py b/sdks/python/apache_beam/testing/test_utils.py index af90cf8..6ca75e6 100644 --- a/sdks/python/apache_beam/testing/test_utils.py +++ b/sdks/python/apache_beam/testing/test_utils.py @@ -20,6 +20,8 @@ For internal use only; no backwards-compatibility guarantees. """ +from __future__ import absolute_import + import hashlib import imp import logging @@ -27,6 +29,7 @@ import os import shutil import tempfile import time +from builtins import object from mock import Mock from mock import patch diff --git a/sdks/python/apache_beam/testing/test_utils_test.py b/sdks/python/apache_beam/testing/test_utils_test.py index ba0b940..56df9fe 100644 --- a/sdks/python/apache_beam/testing/test_utils_test.py +++ b/sdks/python/apache_beam/testing/test_utils_test.py @@ -17,6 +17,8 @@ """Unittest for testing utilities,""" +from __future__ import absolute_import + import logging import os import tempfile @@ -52,7 +54,7 @@ class TestUtilsTest(unittest.TestCase): utils.delete_files([path]) self.assertTrue( error.exception.args[0].startswith('Delete operation failed')) - self.assertEqual(error.exception.exception_details.keys(), [path]) + self.assertEqual(list(error.exception.exception_details.keys()), [path]) def test_delete_files_fails_with_invalid_arg(self): with self.assertRaises(RuntimeError): diff --git a/sdks/python/apache_beam/testing/util.py b/sdks/python/apache_beam/testing/util.py index c518ed4..23d58cb 100644 --- a/sdks/python/apache_beam/testing/util.py +++ b/sdks/python/apache_beam/testing/util.py @@ -22,6 +22,7 @@ from __future__ import absolute_import import collections import glob import tempfile +from builtins import object from apache_beam import pvalue from apache_beam.transforms import window @@ -69,6 +70,9 @@ def contains_in_any_order(iterable): def __eq__(self, other): return self._counter == collections.Counter(other) + def __hash__(self): + return hash(self._counter) + def __repr__(self): return "InAnyOrder(%s)" % self._counter diff --git a/sdks/python/apache_beam/testing/util_test.py b/sdks/python/apache_beam/testing/util_test.py index 8e362ac..f46063e 100644 --- a/sdks/python/apache_beam/testing/util_test.py +++ b/sdks/python/apache_beam/testing/util_test.py @@ -17,6 +17,8 @@ """Unit tests for testing utilities.""" +from __future__ import absolute_import + import unittest from apache_beam import Create diff --git a/sdks/python/tox.ini b/sdks/python/tox.ini index 8958997..0c238ee 100644 --- a/sdks/python/tox.ini +++ b/sdks/python/tox.ini @@ -110,6 +110,7 @@ modules = apache_beam/pipeline_test apache_beam/pvalue apache_beam/pvalue_test + apache_beam/testing commands = python --version pip --version -- To stop receiving notification emails like this one, please contact al...@apache.org.