fixup! incdec_number: add support for port

This commit is contained in:
Daniel Hahler 2018-01-22 21:48:21 +01:00
parent 6a40cbf160
commit 9f14ae184f
2 changed files with 7 additions and 1 deletions

View File

@ -561,7 +561,7 @@ def incdec_number(url, incdec, count=1, segments=None):
# Order as they appear in a URL
segment_modifiers = [
('host', url.host, url.setHost),
('port', lambda: str(url.port()), lambda x: url.setPort(int(x))),
('port', lambda: str(url.port()) if url.port() > 0 else '', lambda x: url.setPort(int(x))),
('path', url.path, url.setPath),
('query', url.query, url.setQuery),
('anchor', url.fragment, url.setFragment),

View File

@ -633,6 +633,12 @@ class TestIncDecNumber:
base_url, 'decrement', segments={'port'})
assert new_url == QUrl('http://localhost:7999')
def test_incdec_port_default(self):
"""Test that a default port (with url.port() == -1) is not touched."""
base_url = QUrl('http://localhost')
with pytest.raises(urlutils.IncDecError):
urlutils.incdec_number(base_url, 'increment', segments={'port'})
@pytest.mark.parametrize('incdec', ['increment', 'decrement'])
@pytest.mark.parametrize('value', [
'{}foo', 'foo{}', 'foo{}bar', '42foo{}'