1
|
|
|
from __future__ import print_function, unicode_literals |
2
|
|
|
|
3
|
|
|
# Standard libary imports |
4
|
|
|
from os import path |
5
|
|
|
import unittest |
6
|
|
|
|
7
|
|
|
# Local imports |
8
|
|
|
from binstar_client.inspect_package import conda |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
def data_path(filename): |
12
|
|
|
return path.join(path.dirname(__file__), 'data', filename) |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
expected_package_data = { |
16
|
|
|
'license': None, |
17
|
|
|
'name': 'conda_gc_test', |
18
|
|
|
'summary': 'This is a simple meta-package', |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
expected_version_data = { |
22
|
|
|
'description': '', |
23
|
|
|
'home_page': None, |
24
|
|
|
'icon': None, # The icon if found on the conda folder is uplaoded here. |
25
|
|
|
'version': '1.2.1', |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
expected_file_data = { |
29
|
|
|
'attrs': { |
30
|
|
|
'arch': 'x86_64', |
31
|
|
|
'build': 'py27_3', |
32
|
|
|
'build_number': 3, |
33
|
|
|
'depends': ['foo ==3*', 'python ==2.7.8'], |
34
|
|
|
'license': None, |
35
|
|
|
'machine': 'x86_64', |
36
|
|
|
'operatingsystem': 'darwin', |
37
|
|
|
'platform': 'osx', |
38
|
|
|
'subdir': 'osx-64', |
39
|
|
|
'target-triplet': 'x86_64-any-darwin', |
40
|
|
|
'has_prefix': False, |
41
|
|
|
}, |
42
|
|
|
'basename': 'osx-64/conda_gc_test-1.2.1-py27_3.tar.bz2', |
43
|
|
|
'dependencies': { |
44
|
|
|
'depends': [{'name': 'foo', 'specs': [['==', '3']]}, |
45
|
|
|
{'name': 'python', 'specs': [['==', '2.7.8']]}], |
46
|
|
|
}, |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
# Test package application data |
50
|
|
|
# ----------------------------------------------------------------------------- |
51
|
|
|
with open(data_path('test-app-package-icon-0.1.0-b64.txt'), 'r') as f: |
52
|
|
|
ICON_B64_DATA = f.read().strip() # Removes a line return at the end |
53
|
|
|
|
54
|
|
|
app_expected_package_data = { |
55
|
|
|
'license': None, |
56
|
|
|
'name': u'test-app-package-icon', |
57
|
|
|
'summary': u'', |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
app_expected_version_data = { |
61
|
|
|
'description': '', |
62
|
|
|
'home_page': None, |
63
|
|
|
'icon': ICON_B64_DATA, |
64
|
|
|
'version': u'0.1', |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
class Test(unittest.TestCase): |
69
|
|
|
|
70
|
|
|
def test_conda(self): |
71
|
|
|
filename = data_path('conda_gc_test-1.2.1-py27_3.tar.bz2') |
72
|
|
|
with open(filename, 'rb') as fd: |
73
|
|
|
package_data, version_data, file_data = conda.inspect_conda_package(filename, fd) |
74
|
|
|
|
75
|
|
|
self.assertEqual(expected_package_data, package_data) |
76
|
|
|
self.assertEqual(expected_version_data, version_data) |
77
|
|
|
self.assertEqual(expected_file_data, file_data) |
78
|
|
|
|
79
|
|
|
def test_conda_app_image(self): |
80
|
|
|
filename = data_path('test-app-package-icon-0.1-0.tar.bz2') |
81
|
|
|
with open(filename, 'rb') as fd: |
82
|
|
|
package_data, version_data, file_data = conda.inspect_conda_package(filename, fd) |
83
|
|
|
|
84
|
|
|
self.assertEqual(app_expected_package_data, package_data) |
85
|
|
|
self.assertEqual(app_expected_version_data, version_data) |
86
|
|
|
|
87
|
|
|
|
88
|
|
|
if __name__ == "__main__": |
89
|
|
|
# import sys;sys.argv = ['', 'Test.testName'] |
90
|
|
|
unittest.main() |
91
|
|
|
|