options: compare equality of Arguments objects

ac45740
This commit is contained in:
bastimeyer 2024-02-11 14:28:50 +01:00 committed by Sebastian Meyer
parent 0acbca3af1
commit eb901bbc9e
2 changed files with 19 additions and 0 deletions

View File

@ -279,6 +279,12 @@ class Arguments:
# iterate in reverse order due to add() being called by multiple pluginargument decorators in reverse order
return reversed(self.arguments.values())
def __hash__(self):
return hash(tuple(self.arguments.items()))
def __eq__(self, other):
return isinstance(other, self.__class__) and hash(self) == hash(other)
def add(self, argument: Argument) -> None:
self.arguments[argument.name] = argument

View File

@ -213,8 +213,11 @@ class TestArgument:
sensitive=False,
argument_name="custom-name",
)
a3 = Argument("foo")
assert a1 is not a2
assert a1 == a2
assert a1 != a3
assert a2 != a3
class TestArguments:
@ -246,6 +249,16 @@ class TestArguments:
args.add(test3)
assert list(iter(args)) == [test3, test1, test2]
def test_equality(self):
test1 = Arguments()
test1.add(Argument("testA"))
test1.add(Argument("testB"))
test2 = Arguments(Argument("testB"), Argument("testA"))
test3 = Arguments(Argument("testA"), Argument("testB"))
assert test1 == test2
assert test1 != test3
assert test2 != test3
def test_requires(self):
test1 = Argument("test1", requires="test2")
test2 = Argument("test2", requires="test3")