-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated .gitignore, added mega.py, rm pdfs, cleanups
Signed-off-by: wiseaidev <business@wiseai.dev>
- Loading branch information
Showing
14 changed files
with
126 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
PDFS = { | ||
"email_test_single_page.pdf": "https://mega.nz/file/akRAXJhT#u5hWvL4JJmoz8JUQdJw4Nfnzw-WnXc2qwCAcVZwbLcM", | ||
"embedded_link_image.pdf": "https://mega.nz/file/nsBgDSxT#dZIjpEb437SLxH-26P9V8cSNwVc9kTpqLFCP9x6CEeg", | ||
"embedded_link_testcase.pdf": "https://mega.nz/file/C5gGTJJR#GUbraILCDX1j4QnVLEbtoKkzxBbJqN-AUBNWCXPFRS8", | ||
"i14doc1.pdf": "https://mega.nz/file/u1owmDZa#xqeMALTWhA5UVyT7PRbevRzXmPU8pgBbjN0vzt6aRgo", | ||
"i14doc2.pdf": "https://mega.nz/file/ehRwSBbC#BqaIZd4XKhdtmRguibffiTX8tA39m6cTSDx-OFFKQqs", | ||
"invalid.pdf": "https://mega.nz/file/Hs4VHAII#dd9F6Uonk6c4tVnSO6VyeqQEkXh65EhMq6sT8zlIowY", | ||
"valid.pdf": "https://mega.nz/file/Xp5RkbaI#3pRFF-kTQFh-ZwOs0O6JqqNdXhsjLuBNxZB2NDgl8Mc", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import pytest | ||
from mega import Mega | ||
import shutil | ||
import os | ||
from constants import PDFS | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def download_pdfs(): | ||
# setup | ||
os.mkdir("./tests/pdfs") | ||
# mega client | ||
mega = Mega() | ||
m = mega.login() | ||
for url in PDFS.values(): | ||
m.download_url(url, "./tests/pdfs") | ||
yield | ||
# teardown | ||
shutil.rmtree("./tests/pdfs") |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,9 @@ | ||
import os | ||
from linkrot import cli | ||
# import pytest | ||
|
||
curdir = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
|
||
def test_cli(): | ||
parser = cli.create_parser() | ||
parsed = parser.parse_args(['-j', 'pdfs/valid.pdf']) | ||
parsed = parser.parse_args(["-j", "./tests/pdfs/valid.pdf"]) | ||
assert parsed.json | ||
assert parsed.pdf == "pdfs/valid.pdf" | ||
assert parsed.pdf == "./tests/pdfs/valid.pdf" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,56 @@ | ||
|
||
import os | ||
import linkrot | ||
from linkrot.exceptions import FileNotFoundError, DownloadError, PDFInvalidError | ||
from linkrot import linkrot | ||
from fixtures import download_pdfs | ||
import pytest | ||
|
||
curdir = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
def test_all(): | ||
with pytest.raises(linkrot.exceptions.FileNotFoundError): | ||
linkrot.linkrot("asd") | ||
|
||
with pytest.raises(linkrot.exceptions.DownloadError): | ||
linkrot.linkrot("http://invalid.com/404.pdf") | ||
@pytest.mark.parametrize( | ||
"test_case, expected", | ||
[ | ||
("asd", FileNotFoundError), | ||
("http://invalid.com/404.pdf", DownloadError), | ||
("./tests/pdfs/invalid.pdf", PDFInvalidError), | ||
], | ||
) | ||
def test_linkrot_exceptions(download_pdfs, test_case, expected): | ||
with pytest.raises(expected): | ||
linkrot(test_case) | ||
|
||
with pytest.raises(linkrot.exceptions.PDFInvalidError): | ||
linkrot.linkrot(os.path.join(curdir, "pdfs/invalid.pdf")) | ||
|
||
pdf = linkrot.linkrot(os.path.join(curdir, "pdfs/valid.pdf")) | ||
def test_valid_pdf(): | ||
pdf = linkrot("./tests/pdfs/valid.pdf") | ||
urls = pdf.get_references(reftype="pdf") | ||
assert len(urls) == 18 | ||
# pdf.download_pdfs("/tmp/") | ||
|
||
|
||
def test_two_pdfs(): | ||
linkrot.linkrot(os.path.join(curdir, "pdfs/i14doc1.pdf")) | ||
pdf_2 = linkrot.linkrot(os.path.join(curdir, "pdfs/i14doc2.pdf")) | ||
linkrot("./tests/pdfs/i14doc1.pdf") | ||
pdf_2 = linkrot("./tests/pdfs/i14doc2.pdf") | ||
assert len(pdf_2.get_references()) == 2 | ||
|
||
|
||
def test_pdf_with_email_address(): | ||
pdf_with_email_addresses = linkrot.linkrot(os.path.join(curdir, "pdfs/email_test_single_page.pdf")) | ||
pdf_with_email_addresses = linkrot("./tests/pdfs/email_test_single_page.pdf") | ||
references = pdf_with_email_addresses.get_references() | ||
# there are only 2 email references in the pdf that should be excluded | ||
assert len(references) == 0 | ||
|
||
|
||
def test_pdf_with_embedded_links(): | ||
pdf_with_embedded_links = linkrot.linkrot(os.path.join(curdir, "pdfs/embedded_link_testcase.pdf")) | ||
pdf_with_embedded_links = linkrot("./tests/pdfs/embedded_link_testcase.pdf") | ||
references = pdf_with_embedded_links.get_references() | ||
|
||
assert len(references) == 7 | ||
|
||
|
||
def test_pdf_with_embedded_link_in_image(): | ||
pdf_with_embedded_link_in_image = linkrot.linkrot(os.path.join(curdir, "pdfs/embedded_link_image.pdf")) | ||
pdf_with_embedded_link_in_image = linkrot("./tests/pdfs/embedded_link_image.pdf") | ||
references = pdf_with_embedded_link_in_image.get_references() | ||
# assert that the reference was found | ||
assert len(references) == 1 | ||
# get the reference from the set | ||
image_ref = references.pop() | ||
|
||
EMBEDDED_LINK_IN_IMAGE = "/~https://github.com/marshalmiller/linkrot/blob/6e6fb45239f8d06e89671e2ec68a11629747355d/branding/Asset%207@4x.png" | ||
assert image_ref.ref == EMBEDDED_LINK_IN_IMAGE | ||
assert image_ref.ref == EMBEDDED_LINK_IN_IMAGE |