Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve parse_address utils tests #1629

Merged
merged 3 commits into from
Oct 22, 2017

Conversation

hramezani
Copy link
Contributor

No description provided.

from gunicorn import util


def test_parse_address():
def test_parse_address(capsys):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems unused. Is it needed?

Copy link
Collaborator

@tilgovi tilgovi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but if capsys isn't used we can remove it. Otherwise great!


with pytest.raises(RuntimeError) as err:
assert util.parse_address('127.0.0.1:test')
assert err.value.message == "'test' is not a valid port number."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will raise an AttributeError under Python 3. I'd use str(exc) instead.

# Test unix socket addresses (PR #1623)
assert util.parse_address('unix://var/run/test.sock') == 'var/run/test.sock'
assert util.parse_address('unix:/var/run/test.sock') == '/var/run/test.sock'

assert util.parse_address('') == ('0.0.0.0', 8000)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could turn this test to use pytest.mark.parametrize: https://docs.pytest.org/en/latest/parametrize.html#pytest-mark-parametrize

@hramezani hramezani force-pushed the improve_test_parse_address branch from 04404f3 to d2d0edb Compare October 21, 2017 17:02
@hramezani
Copy link
Contributor Author

@berkerpeksag, thanks. it is ok for use pytest.mark.parametrize , but how do I test RuntimeError with pytest.mark.parametrize?

@berkerpeksag
Copy link
Collaborator

but how do I test RuntimeError with pytest.mark.parametrize?

I'd move it to a separate test function (e.g. test_parse_address_erroror test_parse_address_invalid)

@hramezani hramezani force-pushed the improve_test_parse_address branch from d2d0edb to 56cc113 Compare October 22, 2017 07:59
@hramezani hramezani force-pushed the improve_test_parse_address branch from 56cc113 to 13df156 Compare October 22, 2017 08:08
Copy link
Collaborator

@berkerpeksag berkerpeksag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thank you! I just made some trivial style changes and will merge this once Travis is passed.

@berkerpeksag berkerpeksag merged commit 0ceb00e into benoitc:master Oct 22, 2017
mjjbell pushed a commit to mjjbell/gunicorn that referenced this pull request Mar 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants