diff --git a/src/streamlink/options.py b/src/streamlink/options.py index d63ee7c1..26ed07d5 100644 --- a/src/streamlink/options.py +++ b/src/streamlink/options.py @@ -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 diff --git a/tests/test_options.py b/tests/test_options.py index 5b5f2d21..2f718048 100644 --- a/tests/test_options.py +++ b/tests/test_options.py @@ -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")