[ https://issues.apache.org/jira/browse/BEAM-9186?focusedWorklogId=377008&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-377008 ]
ASF GitHub Bot logged work on BEAM-9186: ---------------------------------------- Author: ASF GitHub Bot Created on: 24/Jan/20 19:36 Start Date: 24/Jan/20 19:36 Worklog Time Spent: 10m Work Description: aaltay commented on pull request #10637: [BEAM-9186] Allow injection of custom equality function. URL: https://github.com/apache/beam/pull/10637#discussion_r370807791 ########## File path: sdks/python/apache_beam/testing/util.py ########## @@ -154,41 +154,48 @@ def equal_to_per_window(expected_window_to_elements): # Note that equal_to checks if expected and actual are permutations of each # other. However, only permutations of the top level are checked. Therefore # [1,2] and [2,1] are considered equal and [[1,2]] and [[2,1]] are not. -def equal_to(expected): +def equal_to(expected, equals_fn=None): - def _equal(actual): + def _equal(actual, equals_fn=equals_fn): expected_list = list(expected) # Try to compare actual and expected by sorting. This fails with a # TypeError in Python 3 if different types are present in the same # collection. It can also raise false negatives for types that don't have # a deterministic sort order, like pyarrow Tables as of 0.14.1 - try: - sorted_expected = sorted(expected) - sorted_actual = sorted(actual) - if sorted_expected != sorted_actual: - raise BeamAssertException( - 'Failed assert: %r == %r' % (sorted_expected, sorted_actual)) + if not equals_fn: + try: + sorted_expected = sorted(expected) + sorted_actual = sorted(actual) + if sorted_expected == sorted_actual: + return + except (BeamAssertException, TypeError): Review comment: We can remove `BeamAssertException` from here. The remaining code in the block would not raise that exception. ---------------------------------------------------------------- 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 Issue Time Tracking ------------------- Worklog Id: (was: 377008) Remaining Estimate: 0h Time Spent: 10m > Allow passing a comparison function for assert_that(..., equal_to()) tests > -------------------------------------------------------------------------- > > Key: BEAM-9186 > URL: https://issues.apache.org/jira/browse/BEAM-9186 > Project: Beam > Issue Type: New Feature > Components: testing > Reporter: Jeffrey > Priority: Minor > Time Spent: 10m > Remaining Estimate: 0h > > Currently testing beam pipelines that produce objects that cannot be sorted > or compared is currently problematical, and developers are introducing > Map(str) and similar transforms in tests to transform PCollections into a > testable form. Adding by injection a comparison function will allow the > creation of more comprehensible tests. -- This message was sent by Atlassian Jira (v8.3.4#803005)