forked from kuhaku/atango
/
test_misc.py
45 lines (32 loc) · 1.09 KB
/
test_misc.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
44
45
# -*- coding: utf-8 -*-
import random
from nose.tools import assert_equals, assert_true, assert_false, assert_raises
from lib import misc
def test_command():
assert_true(misc.command('date')[0])
def test_choice():
got = misc.choice('aaaa')
assert_equals(got, 'a')
def test_nones():
got = misc.nones(2)
assert_equals(got, [None, None])
got = misc.nones(2, 2)
assert_equals(got, [[None, None], [None, None]])
assert_raises(ValueError, misc.nones, 1, 0.5)
assert_raises(ValueError, misc.nones, 0.5, 1)
assert_raises(ValueError, misc.nones, 0, 1)
assert_raises(ValueError, misc.nones, 1, 0)
def test_map_dict():
got = misc.map_dict(int, {1: '1', 2: '2'})
assert_equals(got, {1: 1, 2: 2})
def test_has_substr():
iterable = ('マミさん', 'チーズケーキ')
assert_true(misc.has_substr(iterable, 'マミ'))
assert_false(misc.has_substr(iterable, 'ほむ'))
def test_retry():
@misc.retry(1000, interval=0.001)
def testfunc():
if random.randint(0, 1):
raise Exception
return True
assert_true(testfunc())