Skip to content

Commit 5a2f77e

Browse files
claudevdmClaude
authored andcommitted
Fix some tests that use update compat flag.
1 parent bae3e8b commit 5a2f77e

6 files changed

Lines changed: 41 additions & 7 deletions

File tree

sdks/python/apache_beam/internal/pickler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
try:
3434
from apache_beam.internal import dill_pickler
3535
except ImportError:
36-
dill_pickler = None
36+
dill_pickler = None # type: ignore[assignment]
3737

3838
USE_CLOUDPICKLE = 'cloudpickle'
3939
USE_DILL = 'dill'

sdks/python/apache_beam/io/gcp/bigquery_file_loads_test.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@
6363
except ImportError:
6464
raise unittest.SkipTest('GCP dependencies are not installed')
6565

66+
try:
67+
import dill
68+
except ImportError:
69+
dill = None
70+
6671
_LOGGER = logging.getLogger(__name__)
6772

6873
_DESTINATION_ELEMENT_PAIRS = [
@@ -406,6 +411,13 @@ def test_partition_files_dofn_size_split(self):
406411
label='CheckSinglePartition')
407412

408413

414+
def maybe_skip(compat_version):
415+
if compat_version and not dill:
416+
raise unittest.SkipTest(
417+
'Dill dependency not installed which is required for compat_version'
418+
' <= 2.67.0')
419+
420+
409421
class TestBigQueryFileLoads(_TestCaseWithTempDirCleanUp):
410422
def test_trigger_load_jobs_with_empty_files(self):
411423
destination = "project:dataset.table"
@@ -485,7 +497,9 @@ def test_records_traverse_transform_with_mocks(self):
485497
param(compat_version=None),
486498
param(compat_version="2.64.0"),
487499
])
500+
@pytest.mark.uses_dill
488501
def test_reshuffle_before_load(self, compat_version):
502+
maybe_skip(compat_version)
489503
destination = 'project1:dataset1.table1'
490504

491505
job_reference = bigquery_api.JobReference()
@@ -994,6 +1008,7 @@ def dynamic_destination_resolver(element, *side_inputs):
9941008
])
9951009
def test_triggering_frequency(
9961010
self, is_streaming, with_auto_sharding, compat_version):
1011+
maybe_skip(compat_version)
9971012
destination = 'project1:dataset1.table1'
9981013

9991014
job_reference = bigquery_api.JobReference()

sdks/python/apache_beam/pipeline_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,9 @@ def expand(self, pcoll):
177177
_ = pipeline | ParentTransform() | beam.Map(lambda x: x + 1)
178178

179179
@mock.patch('logging.info')
180+
@pytest.mark.uses_dill
180181
def test_runner_overrides_default_pickler(self, mock_info):
182+
pytest.importorskip("dill")
181183
with mock.patch.object(PipelineRunner,
182184
'default_pickle_library_override') as mock_fn:
183185
mock_fn.return_value = 'dill'

sdks/python/apache_beam/transforms/util_test.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@
8383
from apache_beam.utils.windowed_value import PaneInfoTiming
8484
from apache_beam.utils.windowed_value import WindowedValue
8585

86+
try:
87+
import dill
88+
except ImportError:
89+
dill = None
90+
8691
warnings.filterwarnings(
8792
'ignore', category=FutureWarning, module='apache_beam.transform.util_test')
8893

@@ -112,6 +117,13 @@ def is_deterministic(self):
112117
return True
113118

114119

120+
def maybe_skip(compat_version):
121+
if compat_version and not dill:
122+
raise unittest.SkipTest(
123+
'Dill dependency not installed which is required for compat_version'
124+
' <= 2.67.0')
125+
126+
115127
class CoGroupByKeyTest(unittest.TestCase):
116128
def test_co_group_by_key_on_tuple(self):
117129
with TestPipeline() as pipeline:
@@ -997,8 +1009,10 @@ def test_reshuffle_streaming_global_window_with_buckets(self):
9971009
param(compat_version=None),
9981010
param(compat_version="2.64.0"),
9991011
])
1012+
@pytest.mark.uses_dill
10001013
def test_reshuffle_custom_window_preserves_metadata(self, compat_version):
10011014
"""Tests that Reshuffle preserves pane info."""
1015+
maybe_skip(compat_version)
10021016
element_count = 12
10031017
timestamp_value = timestamp.Timestamp(0)
10041018
l = [
@@ -1098,10 +1112,11 @@ def test_reshuffle_custom_window_preserves_metadata(self, compat_version):
10981112
param(compat_version=None),
10991113
param(compat_version="2.64.0"),
11001114
])
1115+
@pytest.mark.uses_dill
11011116
def test_reshuffle_default_window_preserves_metadata(self, compat_version):
11021117
"""Tests that Reshuffle preserves timestamp, window, and pane info
11031118
metadata."""
1104-
1119+
maybe_skip(compat_version)
11051120
no_firing = PaneInfo(
11061121
is_first=True,
11071122
is_last=True,

sdks/python/apache_beam/typehints/schemas_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,8 @@ def test_named_fields_roundtrip(self, named_fields):
720720
@pytest.mark.uses_dill
721721
class PickleTest(unittest.TestCase):
722722
def setUp(self):
723-
if PickleTest.pickler == 'dill':
723+
# pylint: disable=access-member-before-definition
724+
if self.pickler == 'dill':
724725
self.pickler = pytest.importorskip("dill")
725726

726727
def test_generated_class_pickle_instance(self):

sdks/python/setup.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -407,10 +407,11 @@ def get_portability_package_data():
407407
extras_require={
408408
'dill': [
409409
# Dill doesn't have forwards-compatibility guarantees within minor
410-
# version. Pickles created with a new version of dill may not unpickle
411-
# using older version of dill. It is best to use the same version of
412-
# dill on client and server, therefore list of allowed versions is
413-
# very narrow. See: https://github.com/uqfoundation/dill/issues/341.
410+
# version. Pickles created with a new version of dill may not
411+
# unpickle using older version of dill. It is best to use the same
412+
# version of dill on client and server, therefore list of allowed
413+
# versions is very narrow.
414+
# See: https://github.com/uqfoundation/dill/issues/341.
414415
'dill>=0.3.1.1,<0.3.2',
415416
],
416417
'docs': [

0 commit comments

Comments
 (0)