forked from discoproject/disco
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_util.py
43 lines (37 loc) · 1.8 KB
/
test_util.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
import os
from datetime import datetime
from disco.test import TestCase
from disco.util import flatten, iterify, urlsplit
def function(x):
return x + 0
sequence = 0, [1, [2, 3], [[4, [5, [6]]]]]
class UtilTestCase(TestCase):
def test_flatten(self):
self.assertEquals(list(range(7)), list(flatten(sequence)))
def test_iterify(self):
self.assertEquals([5], list(iterify(5)))
self.assertEquals([5], list(iterify([5])))
def test_urlsplit(self):
port = self.settings['DISCO_PORT']
ddfs = self.settings['DDFS_DATA']
data = self.settings['DISCO_DATA']
self.assertEquals(urlsplit('http://host/path'),
('http', ('host', ''), 'path'))
self.assertEquals(urlsplit('http://host:port/path'),
('http', ('host', 'port'), 'path'))
self.assertEquals(urlsplit('disco://master/long/path'),
('http', ('master', '{0}'.format(port)), 'long/path'))
self.assertEquals(urlsplit('disco://localhost/ddfs/path',
localhost='localhost',
ddfs_data=ddfs),
('file', ('', ''), os.path.join(ddfs, 'path')))
self.assertEquals(urlsplit('disco://localhost/data/path',
localhost='localhost',
disco_data=data),
('file', ('', ''), os.path.join(data, 'path')))
self.assertEquals(urlsplit('tag://tag', ''),
('tag', ('', ''), 'tag'))
self.assertEquals(urlsplit('tag://host/tag', ''),
('tag', ('host', ''), 'tag'))
self.assertEquals(urlsplit('tag://host:port/tag', ''),
('tag', ('host', 'port'), 'tag'))