def test_incdec_port(self): """Test incdec_number with port.""" base_url = QUrl('http://localhost:8000') new_url = urlutils.incdec_number( base_url, 'increment', segments={'port'}) assert new_url == QUrl('http://localhost:8001') new_url = urlutils.incdec_number( base_url, 'decrement', segments={'port'}) assert new_url == QUrl('http://localhost:7999')
def test_incdec_leading_zeroes(self, number, expected, incdec): """Test incdec_number with leading zeroes.""" url = 'http://example.com/{}' base_url = QUrl(url.format(number)) expected_url = QUrl(url.format(expected)) new_url = urlutils.incdec_number(base_url, incdec, segments={'path'}) assert new_url == expected_url
def test_incdec_number_count(self, incdec, value, url, count): """Test incdec_number with valid URLs and a count.""" base_value = value.format(20) if incdec == 'increment': expected_value = value.format(20 + count) else: if count > 20: return expected_value = value.format(20 - count) base_url = QUrl(url.format(base_value)) expected_url = QUrl(url.format(expected_value)) new_url = urlutils.incdec_number( base_url, incdec, count, segments={'host', 'path', 'query', 'anchor'}) assert new_url == expected_url
def incdec(url, count, inc_or_dec): """Helper method for :navigate when `where' is increment/decrement. Args: url: The current url. count: How much to increment or decrement by. inc_or_dec: Either 'increment' or 'decrement'. tab: Whether to open the link in a new tab. background: Open the link in a new background tab. window: Open the link in a new window. """ segments = set(config.val.url.incdec_segments) try: new_url = urlutils.incdec_number(url, inc_or_dec, count, segments=segments) except urlutils.IncDecError as error: raise Error(error.msg) return new_url
def test_incdec_number(self, incdec, value, url): """Test incdec_number with valid URLs.""" if (value == '{}foo' and url == 'http://example.com/path with {} spaces'): pytest.xfail("https://github.com/glimpsebrowser/glimpsebrowser/issues/4917") # The integer used should not affect test output, as long as it's # bigger than 1 # 20 was chosen by dice roll, guaranteed to be random base_value = value.format(20) if incdec == 'increment': expected_value = value.format(21) else: expected_value = value.format(19) base_url = QUrl(url.format(base_value)) expected_url = QUrl(url.format(expected_value)) new_url = urlutils.incdec_number( base_url, incdec, segments={'host', 'path', 'query', 'anchor'}) assert new_url == expected_url
def test_wrong_segment(self): """Test if incdec_number rejects a wrong segment.""" with pytest.raises(urlutils.IncDecError): urlutils.incdec_number(QUrl('http://example.com'), 'increment', segments={'foobar'})
def test_wrong_mode(self): """Test if incdec_number rejects a wrong parameter for incdec.""" valid_url = QUrl("http://example.com/0") with pytest.raises(ValueError): urlutils.incdec_number(valid_url, "foobar")
def test_invalid_url(self): """Test if incdec_number rejects an invalid URL.""" with pytest.raises(urlutils.InvalidUrlError): urlutils.incdec_number(QUrl(""), "increment")
def test_number_below_0(self, url, count): """Test incdec_number with a number <0 after decrementing.""" with pytest.raises(urlutils.IncDecError): urlutils.incdec_number(QUrl(url), 'decrement', count=count)
def test_no_number(self, url): """Test incdec_number with URLs that don't contain a number.""" with pytest.raises(urlutils.IncDecError): urlutils.incdec_number(QUrl(url), "increment")
def test_incdec_segment_ignored(self, url, segments, expected): new_url = urlutils.incdec_number(QUrl(url), 'increment', segments=segments) assert new_url == QUrl(expected)
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'})