Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_empty_userpass(tmpdir):
"""Suppress prompts if empty username and password are provided in .pypirc."""
pypirc = os.path.join(str(tmpdir), ".pypirc")
with open(pypirc, "w") as fp:
fp.write(
textwrap.dedent(
"""
[pypi]
username=
password=
"""
)
)
config = utils.get_config(pypirc)
pypi = config["pypi"]
assert pypi["username"] == pypi["password"] == ""
def test_get_config_override_pypi_url(tmpdir):
pypirc = os.path.join(str(tmpdir), ".pypirc")
with open(pypirc, "w") as fp:
fp.write(
textwrap.dedent(
"""
[pypi]
repository = http://pypiproxy
"""
)
)
assert utils.get_config(pypirc)["pypi"]["repository"] == "http://pypiproxy"
def test_get_config_missing(tmpdir):
pypirc = os.path.join(str(tmpdir), ".pypirc")
assert utils.get_config(pypirc) == {
"pypi": {
"repository": utils.DEFAULT_REPOSITORY,
"username": None,
"password": None,
},
"testpypi": {
"repository": utils.TEST_REPOSITORY,
"username": None,
"password": None,
},
def test_get_config_deprecated_pypirc():
tests_dir = os.path.dirname(os.path.abspath(__file__))
deprecated_pypirc_path = os.path.join(tests_dir, "fixtures", "deprecated-pypirc")
assert utils.get_config(deprecated_pypirc_path) == {
"pypi": {
"repository": utils.DEFAULT_REPOSITORY,
"username": "testusername",
"password": "testpassword",
},
"testpypi": {
"repository": utils.TEST_REPOSITORY,
"username": "testusername",
"password": "testpassword",
},
def _pypirc_section_for_repo(repo):
from twine import utils
config = utils.get_config()
for section in config:
if config[section].get("repository") == repo:
return section
return None
def check_pypirc():
try:
config = get_config()
except Error as e:
raise ScriptError('Failed to parse .pypirc file: {}'.format(e))
if config is None:
raise ScriptError('Failed to parse .pypirc file')
if 'pypi' not in config:
raise ScriptError('Missing [pypi] section in .pypirc file')
if not (config['pypi'].get('username') and config['pypi'].get('password')):
raise ScriptError('Missing login/password pair for pypi repo')