TINKERPOP-1784 Refactored the assertion logic for ordered/unordered
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/692f50de Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/692f50de Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/692f50de Branch: refs/heads/TINKERPOP-1784 Commit: 692f50de7e6860dc7c2c11cbcb5010a72317eadf Parents: 70e6b5e Author: Stephen Mallette <sp...@genoprime.com> Authored: Thu Sep 28 15:17:14 2017 -0400 Committer: Stephen Mallette <sp...@genoprime.com> Committed: Thu Nov 2 13:37:22 2017 -0400 ---------------------------------------------------------------------- .../src/main/jython/radish/feature_steps.py | 41 ++++++++++---------- 1 file changed, 20 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/692f50de/gremlin-python/src/main/jython/radish/feature_steps.py ---------------------------------------------------------------------- diff --git a/gremlin-python/src/main/jython/radish/feature_steps.py b/gremlin-python/src/main/jython/radish/feature_steps.py index 7a4a30a..2db5922 100644 --- a/gremlin-python/src/main/jython/radish/feature_steps.py +++ b/gremlin-python/src/main/jython/radish/feature_steps.py @@ -68,9 +68,9 @@ def assert_result(step, characterized_as): if characterized_as == "empty": assert_that(len(step.context.result), equal_to(0)) elif characterized_as == "ordered": - __ordered_assertion(step) + __table_assertion(step.table, step.context.result, step.context, True) elif characterized_as == "unordered": - __unordered_assertion(step) + __table_assertion(step.table, step.context.result, step.context, False) else: raise ValueError("unknown data characterization of " + characterized_as) @@ -100,32 +100,31 @@ def __convert(val, ctx): else: return val +# +# def __ordered_assertion(data, result, ctx): +# # results from traversal should have the same number of entries as the feature data table +# assert_that(len(result), equal_to(len(data))) +# +# # assert the results in order they are expected in the data from the features file +# for ix, line in enumerate(data): +# assert_that(result[ix], equal_to(__convert(line[0], ctx))) +# -def __ordered_assertion(step): - data = step.table +def __table_assertion(data, result, ctx, ordered): # results from traversal should have the same number of entries as the feature data table - assert_that(len(step.context.result), equal_to(len(data))) + assert_that(len(result), equal_to(len(data))) - # assert the results by type where the first column will hold the type and the second column - # the data to assert. the contents of the second column will be dependent on the type specified - # in the first column - for ix, line in enumerate(data): - assert_that(step.context.result[ix], equal_to(__convert(line[0], step.context))) - -def __unordered_assertion(step): - data = step.table - - # results from traversal should have the same number of entries as the feature data table - assert_that(len(step.context.result), equal_to(len(data))) - - results_to_test = list(step.context.result) + results_to_test = list(result) # finds a match in the results for each line of data to assert and then removes that item # from the list - in the end there should be no items left over and each will have been asserted - for line in data: - val = __convert(line[0], step.context) - assert_that(val, is_in(results_to_test)) + for ix, line in enumerate(data): + val = __convert(line[0], ctx) + if ordered: + assert_that(results_to_test[ix], equal_to(val)) + else: + assert_that(val, is_in(results_to_test)) results_to_test.remove(val) assert_that(len(results_to_test), is_(0))