[
https://issues.apache.org/jira/browse/BEAM-4004?focusedWorklogId=102294&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-102294
]
ASF GitHub Bot logged work on BEAM-4004:
----------------------------------------
Author: ASF GitHub Bot
Created on: 15/May/18 21:43
Start Date: 15/May/18 21:43
Worklog Time Spent: 10m
Work Description: Fematich closed pull request #5352: [BEAM-4004]
Futurize testing subpackage
URL: https://github.com/apache/beam/pull/5352
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/sdks/python/apache_beam/testing/__init__.py
b/sdks/python/apache_beam/testing/__init__.py
index cce3acad34a..f4f43cbb123 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 c421e259398..11786728a72 100644
--- a/sdks/python/apache_beam/testing/pipeline_verifiers.py
+++ b/sdks/python/apache_beam/testing/pipeline_verifiers.py
@@ -22,6 +22,8 @@
`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 bc8789f5b42..dd7cf6d8de2 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 0525945f15f..4e4c9282686 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 c642c65a7b7..62cee107fea 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 8a63e7bd056..caa74ec6c75 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 @@
]
-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 184a61e2a55..b43ce889350 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 af90cf80bfb..6ca75e65102 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 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 ba0b940136e..56df9fe091a 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 @@ def test_delete_files_fails_with_io_error(self):
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 5caa78ce919..a1b01020e62 100644
--- a/sdks/python/apache_beam/testing/util.py
+++ b/sdks/python/apache_beam/testing/util.py
@@ -22,6 +22,7 @@
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 __init__(self, 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 8e362ac6936..f46063e0871 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 caa899de2db..7e209295c6a 100644
--- a/sdks/python/tox.ini
+++ b/sdks/python/tox.ini
@@ -99,6 +99,7 @@ deps =
flake8==3.5.0
modules =
apache_beam/coders
+ apache_beam/testing
commands =
python --version
pip --version
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 102294)
Time Spent: 40m (was: 0.5h)
> Futurize and fix python 2 compatibility for testing subpackage
> --------------------------------------------------------------
>
> Key: BEAM-4004
> URL: https://issues.apache.org/jira/browse/BEAM-4004
> Project: Beam
> Issue Type: Sub-task
> Components: sdk-py-core
> Reporter: Robbe
> Assignee: Matthias Feys
> Priority: Major
> Time Spent: 40m
> Remaining Estimate: 0h
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)