Fix bug/typo leading to incorrect --ties prompt behaviour in Python
This commit is contained in:
parent
77c5cfca75
commit
6612c35d4a
@ -51,7 +51,7 @@ class TiesPrompt:
|
|||||||
|
|
||||||
print()
|
print()
|
||||||
|
|
||||||
return l[i - 1]
|
return l[choice - 1]
|
||||||
else: # pragma: no cover
|
else: # pragma: no cover
|
||||||
if self.buffer is not None:
|
if self.buffer is not None:
|
||||||
try:
|
try:
|
||||||
|
@ -22,13 +22,16 @@ from pyRCV2.ties import TiesBackwards, TiesForwards, TiesPrompt, TiesRandom
|
|||||||
import tests.util
|
import tests.util
|
||||||
|
|
||||||
def test_prompt_py(monkeypatch):
|
def test_prompt_py(monkeypatch):
|
||||||
monkeypatch.setattr('builtins.input', lambda _: '2')
|
|
||||||
l = [
|
l = [
|
||||||
(Candidate('A'), CountCard()),
|
(Candidate('A'), CountCard()),
|
||||||
(Candidate('B'), CountCard()),
|
(Candidate('B'), CountCard()),
|
||||||
(Candidate('C'), CountCard()),
|
(Candidate('C'), CountCard()),
|
||||||
]
|
]
|
||||||
t = TiesPrompt()
|
t = TiesPrompt()
|
||||||
|
monkeypatch.setattr('builtins.input', lambda _: '1')
|
||||||
|
assert t.choose_lowest(l) == l[0]
|
||||||
|
assert t.choose_highest(l) == l[0]
|
||||||
|
monkeypatch.setattr('builtins.input', lambda _: '2')
|
||||||
assert t.choose_lowest(l) == l[1]
|
assert t.choose_lowest(l) == l[1]
|
||||||
assert t.choose_highest(l) == l[1]
|
assert t.choose_highest(l) == l[1]
|
||||||
|
|
||||||
@ -39,6 +42,10 @@ def test_prompt_js():
|
|||||||
ctx.eval('let raised = false; try { tie.choose_lowest(l); } catch (ex) { if (py.isinstance(ex, py.pyRCV2.ties.RequireInput)) { raised = true; } }')
|
ctx.eval('let raised = false; try { tie.choose_lowest(l); } catch (ex) { if (py.isinstance(ex, py.pyRCV2.ties.RequireInput)) { raised = true; } }')
|
||||||
assert ctx.eval('raised') == True
|
assert ctx.eval('raised') == True
|
||||||
|
|
||||||
|
ctx.eval('tie.buffer = "1";')
|
||||||
|
assert ctx.eval('tie.choose_lowest(l) === l[0]')
|
||||||
|
ctx.eval('tie.buffer = "1";')
|
||||||
|
assert ctx.eval('tie.choose_highest(l) === l[0]')
|
||||||
ctx.eval('tie.buffer = "2";')
|
ctx.eval('tie.buffer = "2";')
|
||||||
assert ctx.eval('tie.choose_lowest(l) === l[1]')
|
assert ctx.eval('tie.choose_lowest(l) === l[1]')
|
||||||
ctx.eval('tie.buffer = "2";')
|
ctx.eval('tie.buffer = "2";')
|
||||||
|
Reference in New Issue
Block a user