From 0ceb00e4ad0a9c21df958466b95652dfecd6042b Mon Sep 17 00:00:00 2001 From: Hasan Ramezani Date: Sun, 22 Oct 2017 20:25:44 +0330 Subject: [PATCH] Improve test coverage of util.parse_address() (#1629) --- tests/test_util.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/tests/test_util.py b/tests/test_util.py index fbd0aa21..89169523 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -3,10 +3,25 @@ # This file is part of gunicorn released under the MIT license. # See the NOTICE for more information. +import pytest + from gunicorn import util -def test_parse_address(): - # 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' +@pytest.mark.parametrize('test_input, expected', [ + ('unix://var/run/test.sock', 'var/run/test.sock'), + ('unix:/var/run/test.sock', '/var/run/test.sock'), + ('', ('0.0.0.0', 8000)), + ('[::1]:8000', ('::1', 8000)), + ('localhost:8000', ('localhost', 8000)), + ('127.0.0.1:8000', ('127.0.0.1', 8000)), + ('localhost', ('localhost', 8000)) +]) +def test_parse_address(test_input, expected): + assert util.parse_address(test_input) == expected + + +def test_parse_address_invalid(): + with pytest.raises(RuntimeError) as err: + util.parse_address('127.0.0.1:test') + assert "'test' is not a valid port number." in str(err)