@pytest.mark.parametrize('url, valid, has_err_string', [('http://www.example.com/', True, False), ('', False, False), ('://', False, True)])
def test_invalid_url_error(message_mock, caplog, url, valid, has_err_string):
 qurl = QUrl(url)
 assert (qurl.isValid() == valid)
 if valid:
  with pytest.raises(ValueError):
   urlutils.invalid_url_error(qurl, '')
  assert (not message_mock.messages)
 else:
  assert (bool(qurl.errorString()) == has_err_string)
  with caplog.at_level(logging.ERROR):
   urlutils.invalid_url_error(qurl, 'frozzle')
  msg = message_mock.getmsg(usertypes.MessageLevel.error)
  if has_err_string:
   expected_text = ('Trying to frozzle with invalid URL - ' + qurl.errorString())
  else:
   expected_text = 'Trying to frozzle with invalid URL'
  assert (msg.text == expected_text)

@ pytest . mark . parametrize ( 'url, valid, has_err_string' , [ ( 'http://www.example.com/' , True , False ) , ( '' , False , False ) , ( '://' , False , True ) ] ) def test_invalid_url_error ( message_mock , caplog , url , valid , has_err_string ) : qurl = QUrl ( url ) assert ( qurl . isValid ( ) == valid ) if valid : with pytest . raises ( ValueError ) : urlutils . invalid_url_error ( qurl , '' ) assert ( not message_mock . messages ) else : assert ( bool ( qurl . errorString ( ) ) == has_err_string ) with caplog . at_level ( logging . ERROR ) : urlutils . invalid_url_error ( qurl , 'frozzle' ) msg = message_mock . getmsg ( usertypes . MessageLevel . error ) if has_err_string : expected_text = ( 'Trying to frozzle with invalid URL - ' + qurl . errorString ( ) ) else : expected_text = 'Trying to frozzle with invalid URL' assert ( msg . text == expected_text )
test invalid_url_error() .