-
Notifications
You must be signed in to change notification settings - Fork 114
/
test_download.py
65 lines (53 loc) · 1.83 KB
/
test_download.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import arxiv
import os
import shutil
import tempfile
import unittest
# Returns the object id.
def custom_slugify(obj):
return obj.get('pdf_url').split('/')[-1]
class TestDownload(unittest.TestCase):
@classmethod
def setUpClass(self):
self.paper_query = arxiv.query(id_list=["1605.08386"])[0]
self.paper_dict = {
"pdf_url": "http://arxiv.org/pdf/1605.08386v1",
"title": "The Paper Title"}
@classmethod
def setUp(self):
self.temp_dir = tempfile.mkdtemp()
@classmethod
def tearDown(self):
shutil.rmtree(self.temp_dir)
def test_download_with_custom_slugify_from_query(self):
arxiv.download(self.paper_query, slugify=custom_slugify, dirpath=self.temp_dir)
self.assertTrue(
os.path.exists(
os.path.join(self.temp_dir, '1605.08386v1.pdf')
)
)
def test_download_with_custom_slugify_from_dict(self):
arxiv.download(self.paper_dict, slugify=custom_slugify, dirpath=self.temp_dir)
self.assertTrue(
os.path.exists(
os.path.join(self.temp_dir, '1605.08386v1.pdf')
)
)
def test_download_from_dict(self):
arxiv.download(self.paper_dict, dirpath=self.temp_dir)
self.assertTrue(
os.path.exists(
os.path.join(
self.temp_dir,
'1605.08386v1.The_Paper_Title.pdf')
)
)
def test_download_from_query(self):
arxiv.download(self.paper_query, dirpath=self.temp_dir)
self.assertTrue(
os.path.exists(
os.path.join(
self.temp_dir,
'1605.08386v1.Heat_bath_random_walks_with_Markov_bases.pdf')
)
)