Skip to content

Commit

Permalink
fix test for TaggedValue
Browse files Browse the repository at this point in the history
  • Loading branch information
Cube707 committed Jan 8, 2024
1 parent 11d575f commit 0a2330c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
10 changes: 5 additions & 5 deletions src/inquirer/questions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@
class TaggedValue:
def __init__(self, choice):
self.label = choice[0]
self.value = choice[1]
self.tag = choice[1]
self._hash = hash(choice)

def __str__(self):
return self.label

def __repr__(self):
return self.value
return repr(self.tag)

def __eq__(self, other):
if isinstance(other, TaggedValue):
return self.value == other.value
return other.tag == self.tag
if isinstance(other, tuple):
return self.label, self.value == other
return self.value == other
return other == (self.label, self.tag)
return other == self.tag

def __ne__(self, other):
return not self.__eq__(other)
Expand Down
21 changes: 14 additions & 7 deletions tests/unit/test_question.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,17 @@ def test_default_value_validation(self):


def test_tagged_value():
tv = questions.TaggedValue("label", "value")

assert tv.__str__() == "label"
assert tv.__repr__() == "value"
assert tv.__eq__(tv) is True
assert tv.__eq__("") is False
assert tv.__ne__(tv) is False
LABEL = "label"
TAG = "l"
tp = (LABEL, TAG)
tv = questions.TaggedValue(tp)

assert (str(tv) == LABEL) is True
assert (repr(tv) == TAG) is True
assert (hash(tv) == hash(tp)) is True

assert (tv == tv) is True
assert (tv != tv) is False
assert (tv == tp) is True
assert (tv == TAG) is True
assert (tv == "") is False

0 comments on commit 0a2330c

Please sign in to comment.