Repository navigation
Expand file tree
/
Copy pathutils_test.py
More file actions
67 lines (49 loc) · 1.94 KB
/
Copy pathutils_test.py
File metadata and controls
67 lines (49 loc) · 1.94 KB
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
66
67
import unittest
from stream_framework.utils import chunks, warn_on_duplicate, make_list_unique,\
warn_on_error
from stream_framework.exceptions import DuplicateActivityException
import mock
class ChunksTest(unittest.TestCase):
def test_chunks(self):
chunked = chunks(list(range(6)), 2)
chunked = list(chunked)
self.assertEqual(chunked, [(0, 1), (2, 3), (4, 5)])
def test_one_chunk(self):
chunked = chunks(list(range(2)), 5)
chunked = list(chunked)
self.assertEqual(chunked, [(0, 1)])
def safe_function():
return 10
def evil_duplicate():
raise DuplicateActivityException('test')
def evil_value():
raise ValueError('test')
class WarnTest(unittest.TestCase):
def test_warn(self):
# this should raise an error
self.assertRaises(ValueError, evil_value)
with mock.patch('stream_framework.utils.logger.warn') as warn:
# this shouldnt raise an error
wrapped = warn_on_error(evil_value, (ValueError,))
wrapped()
# but stick something in the log
assert warn.called
def test_warn_on_duplicate(self):
# this should raise an error
self.assertRaises(DuplicateActivityException, evil_duplicate)
# this shouldnt raise an error
with mock.patch('stream_framework.utils.logger.warn') as warn:
wrapped = warn_on_duplicate(evil_duplicate)
wrapped()
# but stick something in the log
assert warn.called
class UniqueListTest(unittest.TestCase):
def test_make_list_unique(self):
with_doubles = list(range(10)) + list(range(5, 15))
result = make_list_unique(with_doubles)
assert result == list(range(15))
def test_make_list_unique_marker(self):
with_doubles = list(range(10)) + list(range(5, 15))
marker = lambda x: x / 5
result = make_list_unique(with_doubles, marker)
assert result == [0, 5, 10]