aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGertjan van den Burg <gertjanvandenburg@gmail.com>2020-12-28 15:22:49 +0000
committerGertjan van den Burg <gertjanvandenburg@gmail.com>2020-12-28 15:22:49 +0000
commitab0611a9d597bf0e3c78bb3d01e857f4727bb2d3 (patch)
treeec804b5bf5f15308c5a85928e4ce009bd9c8eb06 /tests
parentUpdate badge in readme (diff)
parentBump version and update changelog and readme (diff)
downloadpaper2remarkable-ab0611a9d597bf0e3c78bb3d01e857f4727bb2d3.tar.gz
paper2remarkable-ab0611a9d597bf0e3c78bb3d01e857f4727bb2d3.zip
Merge branch 'master' into feature/gh_actions
Diffstat (limited to 'tests')
-rw-r--r--tests/test_html.py51
-rw-r--r--tests/test_providers.py22
2 files changed, 73 insertions, 0 deletions
diff --git a/tests/test_html.py b/tests/test_html.py
new file mode 100644
index 0000000..41f6b83
--- /dev/null
+++ b/tests/test_html.py
@@ -0,0 +1,51 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""Additional tests for the HTML provider
+
+This file is part of paper2remarkable.
+
+"""
+
+import os
+import pdfplumber
+import unittest
+
+from paper2remarkable.providers.html import HTML
+from paper2remarkable.providers.html import make_readable
+from paper2remarkable.utils import get_page_with_retry
+
+
+class TestHTML(unittest.TestCase):
+ def test_experimental_fix_lazy_loading(self):
+ url = "https://www.seriouseats.com/2015/01/tea-for-everyone.html"
+ prov = HTML(upload=False, experimental=True)
+ page = get_page_with_retry(url, return_text=True)
+ title, article = make_readable(page)
+ html_article = prov.preprocess_html(url, title, article)
+ expected_image = "https://www.seriouseats.com/images/2015/01/20150118-tea-max-falkowitz-3.jpg"
+ self.assertIn(expected_image, html_article)
+
+ def test_custom_css(self):
+ test_css = """
+ @page { size: 702px 936px; margin: 1in; }
+ img { display: block; margin: 0 auto; text-align: center; max-width: 70%; max-height: 300px; }
+ h1,h2,h3 { font-family: 'Montserrat'; }
+ p, li { font-size: 12pt; line-height: 2; font-family: 'Montserrat'; text-align: left; }
+ """
+
+ test_font_urls = [
+ "https://fonts.googleapis.com/css2?family=Montserrat&display=swap"
+ ]
+
+ url = "https://hbr.org/2019/11/getting-your-team-to-do-more-than-meet-deadlines"
+ prov = HTML(upload=False, css=test_css, font_urls=test_font_urls)
+ filename = prov.run(url)
+ with pdfplumber.open(filename) as pdf:
+ self.assertEqual(8, len(pdf.pages))
+
+ os.unlink(filename)
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/tests/test_providers.py b/tests/test_providers.py
index 9b2f24d..db616e9 100644
--- a/tests/test_providers.py
+++ b/tests/test_providers.py
@@ -28,6 +28,7 @@ from paper2remarkable.providers import (
PdfUrl,
PubMed,
SagePub,
+ ScienceDirect,
SemanticScholar,
Springer,
TandFOnline,
@@ -392,6 +393,27 @@ class TestProviders(unittest.TestCase):
filename = prov.run(url)
self.assertEqual(exp, os.path.basename(filename))
+ def test_sciencedirect_1(self):
+ prov = ScienceDirect(upload=False, verbose=VERBOSE)
+ url = "https://www.sciencedirect.com/science/article/pii/S0166354220302011"
+ exp = "Caly_et_al_-_The_FDA-approved_Drug_Ivermectin_Inhibits_the_Replication_of_SARS-CoV-2_in_Vitro_2020.pdf"
+ filename = prov.run(url)
+ self.assertEqual(exp, os.path.basename(filename))
+
+ def test_sciencedirect_2(self):
+ prov = ScienceDirect(upload=False, verbose=VERBOSE)
+ url = "https://www.sciencedirect.com/science/article/pii/S0047235220302543"
+ exp = "Bolger_Lytle_Bolger_-_What_Matters_in_Citizen_Satisfaction_With_Police_a_Meta-Analysis_2021.pdf"
+ filename = prov.run(url)
+ self.assertEqual(exp, os.path.basename(filename))
+
+ def test_sciencedirect_3(self):
+ prov = ScienceDirect(upload=False, verbose=VERBOSE)
+ url = r"https://pdf.sciencedirectassets.com/272398/1-s2.0-S0022039616X00095/1-s2.0-S0022039616001029/main.pdf?X-Amz-Security-Token=IQoJb3JpZ2luX2VjELf%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaCXV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ySXWoqIdO7b9Q%3D%3D&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20201117T155020Z&X-Amz-SignedHeaders=host&X-Amz-Expires=300&X-Amz-Credential=ASIAQ3PHCVTY7OS7PK7A%2F20201117%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Signature=03abad117208b684a1a4ca2ffdcbe5b9a40a19e6c841c609e299315a2f2234ce&hash=24f71da9f05f6835c9797841d1462d11eea85c49e9655dde043ed9f748edf17e&host=68042c943591013ac2b2430a89b270f6af2c76d8dfd086a07176afe7c76c2c61&pii=S0022039616001029&tid=spdf-6b78a4fa-826e-4267-8ce6-43c814fa51b2&sid=776192553463724f1a4b56613fcf5e514b72gxrqb&type=client"
+ exp = "Kristiansen_Wulff_-_Exponential_Estimates_of_Symplectic_Slow_Manifolds_2016.pdf"
+ filename = prov.run(url)
+ self.assertEqual(exp, os.path.basename(filename))
+
if __name__ == "__main__":
unittest.main()