Skip to content

Commit

Permalink
Merge pull request #7 from JFoederer/List-operator-improvements
Browse files Browse the repository at this point in the history
List operator improvements
  • Loading branch information
JFoederer authored Jan 8, 2024
2 parents f802aab + cacc65b commit 2edc20f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
34 changes: 34 additions & 0 deletions atest/robotNL tests/Check that/Operators/List-like_operators.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
*** Settings ***
Resource base.resource

*** Test Cases ***
Basic element checks
@{empty_list}= Create List
Check That ${empty_list} Is Empty
@{animals}= Create List Bird Wolf Fish
Check That @{animals} Contains Wolf
Run Keyword And Expect Error CheckFailed* Check That @{animals} Contains WOLF
Check That @{animals} Contains Item WOLF
Check That @{animals} Does not contain Platypus
Check That @{animals} Does Not Contain Item Platypus
Run Keyword And Expect Error CheckFailed* Check That @{animals} Does Not Contain Item WOLF

Contains exactly the items from
@{animals}= Create List Bird Wolf Fish
Check that ${animals} Contains Exactly The Items From Bird Wolf Fish
Check that ${animals} Contains Exactly The Items From Wolf Fish Bird
Check that ${animals} Contains Exactly The Items From ${animals}
Check that ${animals} Contains Exactly The Items From @{animals}
Check that @{animals} Contains Exactly The Items From @{animals}
Check that @{animals} Contains Exactly The Items From ${animals}
@{short_list}= Create List Single element
Check that ${short_list} Contains Exactly The Items From Single element
@{empty_list}= Create List
Check That ${empty_list} Contains Exactly The Items From ${empty_list}
Check that Item1 Item2 Contains Exactly The Items From Item2 Item1
Run Keyword And Expect Error CheckFailed* Check that ${animals} Contains Exactly The Items From Bird Wolf
Run Keyword And Expect Error CheckFailed* Check that ${animals} Contains Exactly The Items From Bird Wolf Fish Extra
Run Keyword And Expect Error CheckFailed* Check that ${animals} Contains Exactly The Items From ${short_list}
Run Keyword And Expect Error CheckFailed* Check that ${short_list} Contains Exactly The Items From @{animals}
Run Keyword And Expect Error CheckFailed* Check that ${empty_list} Contains Exactly The Items From Extra
Run Keyword And Expect Error CheckFailed* Check that Item1 Item2 Contains Exactly The Items From ${empty_list}
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "robotframework-nl"
version = "2.2.0"
version = "2.2.1"
description = "robotnl is a proving ground to boost Robot framework closer to Natural Language."
readme = "README.md"
authors = [{ name = "Johan Foederer", email = "[email protected]" }]
Expand Down
15 changes: 9 additions & 6 deletions robotnl/CheckOperator.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ def contains_item(self, sequence, part):
Iterates over the sequence to apply automatic Robot type conversion where applicable.
"""
for item in sequence:
BuiltIn().log("Processing '%s' from list" % item)
if self.is_equal_to(part, item):
BuiltIn().log(f"Processing '{item}' from list")
if self.equals(part, item):
BuiltIn().log("Matched")
return True
BuiltIn().log("No match")
Expand All @@ -140,19 +140,22 @@ def contains_exactly_the_items_from(self, sequence, sequence_right):
Checks whether the sequence on the right side contains all items of the left side and vice versa.
Iterates over sequence on the left and matches each element with a single element on the right.
"""
if isinstance(sequence_right, str):
sequence_right = [sequence_right]
sequence_right = [*sequence_right]
for item in sequence:
item_found_in_parts = False
BuiltIn().log("Processing '%s' from list" % item)
BuiltIn().log(f"Processing '{item}' from left side list")
for i in range(len(sequence_right)):
if self.equals(sequence_right[i],item):
if self.equals(item, sequence_right[i]):
sequence_right.pop(i)
item_found_in_parts = True
break
if not item_found_in_parts:
BuiltIn().log("Item '%s' from left side is not found in the list on the right side" % item)
BuiltIn().log(f"Item '{item}' from left side is not found in the list on the right side")
return False
if len(sequence_right) > 0:
BuiltIn().log("Not all items from right side list are present: %s" % sequence_right)
BuiltIn().log(f"Not all items from right side list are present: {sequence_right}")
return False

return True
Expand Down
2 changes: 1 addition & 1 deletion robotnl/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = '2.2.0'
VERSION = '2.2.1'

0 comments on commit 2edc20f

Please sign in to comment.