@pytest.mark.parametrize('url, valid, has_err_string', [('http://www.example.com/', True, False), ('', False, False), ('://', False, True)])
def test_raise_cmdexc_if_invalid(url, valid, has_err_string):
 qurl = QUrl(url)
 assert (qurl.isValid() == valid)
 if valid:
  urlutils.raise_cmdexc_if_invalid(qurl)
 else:
  assert (bool(qurl.errorString()) == has_err_string)
  with pytest.raises(cmdexc.CommandError) as excinfo:
   urlutils.raise_cmdexc_if_invalid(qurl)
  if has_err_string:
   expected_text = ('Invalid URL - ' + qurl.errorString())
  else:
   expected_text = 'Invalid URL'
  assert (str(excinfo.value) == expected_text)

@ pytest . mark . parametrize ( 'url, valid, has_err_string' , [ ( 'http://www.example.com/' , True , False ) , ( '' , False , False ) , ( '://' , False , True ) ] ) def test_raise_cmdexc_if_invalid ( url , valid , has_err_string ) : qurl = QUrl ( url ) assert ( qurl . isValid ( ) == valid ) if valid : urlutils . raise_cmdexc_if_invalid ( qurl ) else : assert ( bool ( qurl . errorString ( ) ) == has_err_string ) with pytest . raises ( cmdexc . CommandError ) as excinfo : urlutils . raise_cmdexc_if_invalid ( qurl ) if has_err_string : expected_text = ( 'Invalid URL - ' + qurl . errorString ( ) ) else : expected_text = 'Invalid URL' assert ( str ( excinfo . value ) == expected_text )
test raise_cmdexc_if_invalid .