-
Notifications
You must be signed in to change notification settings - Fork 13
/
test_pyspin.py
59 lines (44 loc) · 1.42 KB
/
test_pyspin.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import time
from pyspin import spin
def test_spinner():
spinner = spin.Spinner(spin.Spin9)
assert spinner.length == 4
assert spinner.frames == spin.Spin9
assert spinner.current() == u'←'
assert spinner.next() == u'←'
assert spinner.next() == u'↑'
assert spinner.next() == u'→'
assert spinner.next() == u'↓'
assert spinner.next() == u'←'
assert spinner.next() == u'↑'
spinner.reset()
assert spinner.position == 0
def test_make_spin():
@spin.make_spin(spin.Default, 'Downloading...')
def fake_download():
time.sleep(2)
fake_download()
def test_make_spin_with_args():
@spin.make_spin(spin.Default, 'Downloading...')
def fake_download(url, retry_times=3):
print("Downloading {0}, will retry {1} times".format(url, retry_times))
time.sleep(2)
fake_download("https://www.example.com/text.txt", retry_times=5)
def test_stop_on_exception():
@spin.make_spin(spin.Default, 'Downloading...')
def fake_download():
1 / 0
try:
fake_download()
except ZeroDivisionError:
print("We catched the exception! Yeah!")
def test_several_calls():
@spin.make_spin(spin.Default, 'Downloading...')
def fake_download():
time.sleep(2)
print("Begin the first download.")
fake_download()
print("Begin the second download.")
fake_download()