Skip to content

Commit

Permalink
Merge pull request #87 from xenserver-next/fix-yesno-input-for-py2-xs8
Browse files Browse the repository at this point in the history
Fix yes/no input for Python2/XS8: revert to raw_input() on Python2
  • Loading branch information
bernhardkaindl authored Feb 23, 2024
2 parents 6b9aac1 + d0e569d commit 9ba210f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
9 changes: 7 additions & 2 deletions tests/unit/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,15 @@ def patch_bugtool(bugtool, mocker, dom0_template, report_name, tmp_path):
bugtool.DB_CONF = xensource_db_conf

# To cover the the code resulting from inputting "n", we need to mock input:
def input(prompt):
def return_no_for_proc_files(prompt):
"""Mock the input() function to return "n" when prompted for /proc files"""

return "n" if "/proc" in prompt else "y"

bugtool.input = input
if sys.version_info.major == 2: # pragma: no cover
bugtool.raw_input = return_no_for_proc_files
else:
bugtool.input = return_no_for_proc_files

entries = [
"xenserver-config",
Expand Down
5 changes: 4 additions & 1 deletion xen-bugtool
Original file line number Diff line number Diff line change
Expand Up @@ -2173,7 +2173,10 @@ def capability(document, key):


def yes(prompt):
yn = input(prompt)
if sys.version_info.major == 2: # pragma: no cover
yn = raw_input(prompt) # pyright: ignore[reportUndefinedVariable]
else:
yn = input(prompt)

return len(yn) == 0 or yn.lower()[0] == 'y'

Expand Down

0 comments on commit 9ba210f

Please sign in to comment.