1
|
|
|
|
2
|
|
|
import unittest |
3
|
|
|
|
4
|
|
|
from collections import namedtuple |
5
|
|
|
|
6
|
|
|
from freezegun import freeze_time |
7
|
|
|
|
8
|
|
|
from binstar_client.inspect_package.ipynb import inspect_ipynb_package |
9
|
|
|
from binstar_client.utils.test.utils import data_dir |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class InspectIPYNBPackageTest(unittest.TestCase): |
13
|
|
|
def test_package_data(self): |
14
|
|
|
with open(data_dir('notebook.ipynb')) as fd: |
15
|
|
|
package_data, _, _ = inspect_ipynb_package('notebook.ipynb', fd) |
16
|
|
|
|
17
|
|
|
self.assertEqual({ |
18
|
|
|
'name': 'notebook', |
19
|
|
|
'description': 'ipynb description', |
20
|
|
|
'summary': 'ipynb summary', |
21
|
|
|
}, package_data) |
22
|
|
|
|
23
|
|
|
def test_package_data_no_metadata(self): |
24
|
|
|
with open(data_dir('notebook-no-metadata.ipynb')) as fd: |
25
|
|
|
package_data, _, _ = inspect_ipynb_package('notebook.ipynb', fd) |
26
|
|
|
|
27
|
|
|
self.assertEqual({ |
28
|
|
|
'name': 'notebook', |
29
|
|
|
'description': 'Jupyter Notebook', |
30
|
|
|
'summary': 'Jupyter Notebook', |
31
|
|
|
}, package_data) |
32
|
|
|
|
33
|
|
|
def test_package_data_normalized_name(self): |
34
|
|
|
with open(data_dir('notebook.ipynb')) as fd: |
35
|
|
|
package_data, _, _ = inspect_ipynb_package('test nótëbOOk.ipynb', fd) |
36
|
|
|
|
37
|
|
|
self.assertIn('name', package_data) |
38
|
|
|
self.assertEqual(package_data['name'], 'test-notebook') |
39
|
|
|
|
40
|
|
|
def test_package_thumbnail(self): |
41
|
|
|
parser_args = namedtuple('parser_args', ['thumbnail'])(data_dir('43c9b994a4d96f779dad87219d645c9f.png')) |
42
|
|
|
with open(data_dir('notebook.ipynb')) as fd: |
43
|
|
|
package_data, _, _ = inspect_ipynb_package('notebook.ipynb', fd, parser_args=parser_args) |
44
|
|
|
|
45
|
|
|
self.assertIn('thumbnail', package_data) |
46
|
|
|
|
47
|
|
|
def test_release_data(self): |
48
|
|
|
with freeze_time('2018-02-01 09:10:00', tz_offset=0): |
49
|
|
|
with open(data_dir('notebook.ipynb')) as fd: |
50
|
|
|
_, release_data, _ = inspect_ipynb_package('notebook.ipynb', fd) |
51
|
|
|
|
52
|
|
|
self.assertEqual({ |
53
|
|
|
'version': '2018.02.01.0910', |
54
|
|
|
'description': 'ipynb description', |
55
|
|
|
'summary': 'ipynb summary', |
56
|
|
|
}, release_data) |
57
|
|
|
|
58
|
|
|
def test_release_data_no_metadata(self): |
59
|
|
|
with freeze_time('2018-05-03 12:30:00', tz_offset=0): |
60
|
|
|
with open(data_dir('notebook-no-metadata.ipynb')) as fd: |
61
|
|
|
_, release_data, _ = inspect_ipynb_package('notebook-no-metadata.ipynb', fd) |
62
|
|
|
|
63
|
|
|
self.assertEqual({ |
64
|
|
|
'version': '2018.05.03.1230', |
65
|
|
|
'description': 'Jupyter Notebook', |
66
|
|
|
'summary': 'Jupyter Notebook', |
67
|
|
|
}, release_data) |
68
|
|
|
|
69
|
|
|
def test_file_data(self): |
70
|
|
|
with open(data_dir('notebook.ipynb')) as fd: |
71
|
|
|
_, _, file_data = inspect_ipynb_package('notebook.ipynb', fd) |
72
|
|
|
|
73
|
|
|
self.assertEqual({ |
74
|
|
|
'basename': 'notebook.ipynb', |
75
|
|
|
'attrs': {} |
76
|
|
|
}, file_data) |
77
|
|
|
|