-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.py
94 lines (78 loc) · 2.49 KB
/
test.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import unittest
import sys
import os
import shutil
from StringIO import StringIO
sys.exit = lambda x: x
OUTPUT = StringIO()
sys.stdout = OUTPUT
class CommandTest(unittest.TestCase):
def setUp(self):
OUTPUT.truncate(0)
class InitCommandTest(CommandTest):
def setUp(self):
super(InitCommandTest, self).setUp()
self.arguments = {
'--handlers': None,
'--help': False,
'--version': False,
'<args>': [],
'<name>': 'example42',
'<port>': None,
'init': True,
'list': False,
'panel': False,
'watch': False
}
def test_init_with_name_empty_dir(self):
from easydojo.commands import DojoCommand
path = 'example42'
os.mkdir(path)
os.chdir(path)
cmd = DojoCommand.make(self.arguments)
cmd.run()
self.assertTrue(os.path.exists('.easydojo.yaml'))
self.assertTrue(os.path.exists('example42.py'))
self.assertTrue(os.path.exists('test_example42.py'))
self.assertIn("Initialize example42", OUTPUT.getvalue())
os.chdir('..')
shutil.rmtree(path)
def test_init_with_name_already_easydojo_dir(self):
from easydojo.commands import DojoCommand
path = 'example42'
os.mkdir(path)
os.chdir(path)
cmd = DojoCommand.make(self.arguments)
cmd.run()
self.assertIn("Initialize example42", OUTPUT.getvalue())
cmd.run()
self.assertIn("EasyDojo already exists", OUTPUT.getvalue())
os.chdir('..')
shutil.rmtree(path)
def test_init_with_name_not_empty_dir(self):
from easydojo.commands import DojoCommand
cmd = DojoCommand.make(self.arguments)
cmd.run()
self.assertIn("This dir isn't empty", OUTPUT.getvalue())
class ListCommandTest(CommandTest):
def setUp(self):
super(ListCommandTest, self).setUp()
self.arguments = {
'--handlers': None,
'--help': False,
'--version': False,
'<args>': [],
'<name>': None,
'<port>': None,
'init': False,
'list': True,
'panel': False,
'watch': False
}
def test_list(self):
from easydojo.commands import DojoCommand
cmd = DojoCommand.make(self.arguments)
cmd.run()
self.assertIn('List of all handlers:', OUTPUT.getvalue())
if __name__ == '__main__':
unittest.main()