mirror of
https://github.com/public-apis/public-apis.git
synced 2025-05-21 21:16:20 +02:00
Create basic test to find_link_in_text function
This commit is contained in:
parent
80ba7262fa
commit
bf4dfcd39d
1 changed files with 40 additions and 1 deletions
|
@ -2,6 +2,45 @@
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
from validate.links import find_links_in_text
|
||||||
|
|
||||||
|
|
||||||
class TestValidateLinks(unittest.TestCase):
|
class TestValidateLinks(unittest.TestCase):
|
||||||
...
|
|
||||||
|
def setUp(self):
|
||||||
|
self.text = """
|
||||||
|
# this is valid
|
||||||
|
|
||||||
|
http://example.com?param1=1¶m2=2#anchor
|
||||||
|
https://www.example.com?param1=1¶m2=2#anchor
|
||||||
|
https://www.example.com.br
|
||||||
|
https://www.example.com.gov.br
|
||||||
|
[Example](https://www.example.com?param1=1¶m2=2#anchor)
|
||||||
|
lorem ipsum https://www.example.com?param1=1¶m2=2#anchor
|
||||||
|
https://www.example.com?param1=1¶m2=2#anchor lorem ipsum
|
||||||
|
|
||||||
|
# this not is valid
|
||||||
|
|
||||||
|
example.com
|
||||||
|
https:example.com
|
||||||
|
https:/example.com
|
||||||
|
https//example.com
|
||||||
|
https//.com
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def test_find_link_in_text(self):
|
||||||
|
links = find_links_in_text(self.text)
|
||||||
|
|
||||||
|
self.assertIsInstance(links, list)
|
||||||
|
self.assertEqual(len(links), 7)
|
||||||
|
|
||||||
|
for link in links:
|
||||||
|
with self.subTest():
|
||||||
|
self.assertIsInstance(link, str)
|
||||||
|
|
||||||
|
def test_find_link_in_text_with_invalid_argument(self):
|
||||||
|
with self.assertRaises(TypeError):
|
||||||
|
find_links_in_text()
|
||||||
|
find_links_in_text(1)
|
||||||
|
find_links_in_text(True)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue