Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def reprompts_on_bad_input(self, mock_input):
assert confirm("O rly?") is True
assert "I didn't understand you" in sys.stderr.getvalue()
def suffix_changes_when_assume_yes_False(self, mock_input):
confirm("Are you sure?", assume_yes=False)
assert mock_input.call_args[0][0] == "Are you sure? [y/N] "
def displays_question_with_yes_no_suffix(self, mock_input):
confirm("Are you sure?")
assert mock_input.call_args[0][0] == "Are you sure? [Y/n] "
def default_on_empty_response_is_True_by_default(self, mock_input):
assert confirm("Are you sure?") is True
def whitespace_is_trimmed(self, mock_input):
assert confirm("Are you sure?") is True
def default_on_empty_response_is_False_if_assume_yes_False(
self, mock_input
):
assert confirm("Are you sure?", assume_yes=False) is False
def returns_False_for_nolike_responses(self, mock_input):
for value in ("n", "N", "no", "NO", "nO", "No"):
mock_input.return_value = value
assert confirm("Meh") is False
def returns_True_for_yeslike_responses(self, mock_input):
for value in ("y", "Y", "yes", "YES", "yES", "Yes"):
mock_input.return_value = value
assert confirm("Meh") is True
def bucket_delete(c):
"""Deletes the S3 bucket used to host the site"""
if not confirm("Are you sure you want to delete the bucket %r?" % BUCKET_NAME):
print('Aborting at user request.')
exit(1)
conn = connect_s3(calling_format=BUCKET_CALLING_FORMAT)
conn.delete_bucket(BUCKET_NAME)
print('Bucket %r deleted.' % BUCKET_NAME)
def all_(c):
"""
Catchall version-bump/tag/changelog/PyPI upload task.
"""
# Print dry-run/status/actions-to-take data & grab programmatic result
# TODO: maybe expand the enum-based stuff to have values that split up
# textual description, command string, etc. See the TODO up by their
# definition too, re: just making them non-enum classes period.
# TODO: otherwise, we at least want derived eg changelog/version/etc paths
# transmitted from status() into here...
actions, state = status(c)
# TODO: unless nothing-to-do in which case just say that & exit 0
if not confirm("Take the above actions?"):
sys.exit("Aborting.")
# TODO: factor out what it means to edit a file:
# - $EDITOR or explicit expansion of it in case no shell involved
# - pty=True and hide=False, because otherwise things can be bad
# - what else?
# Changelog! (pty for non shite editing, eg vim sure won't like non-pty)
if actions.changelog is Changelog.NEEDS_RELEASE:
# TODO: identify top of list and inject a ready-made line? Requires vim
# assumption...GREAT opportunity for class/method based tasks!
cmd = "$EDITOR {0.packaging.changelog_file}".format(c)
c.run(cmd, pty=True, hide=False)
# TODO: add a step for checking reqs.txt / setup.py vs virtualenv contents
# Version file!
if actions.version == VersionFile.NEEDS_BUMP: