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