blob: c948d6998c5746d1903c1039d9347183f25028fe (
plain)
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
|
import contextlib
import io
import tempfile
import unittest
from lesana import command
class Args:
def __init__(self, args):
self.args = args
def __getattribute__(self, k):
try:
return super().__getattribute__(k)
except AttributeError:
try:
return self.args[k]
except KeyError as e:
raise AttributeError(e)
class testCommands(unittest.TestCase):
def setUp(self):
self.collection_dir = tempfile.TemporaryDirectory()
def tearDown(self):
pass
def _edit_file(self, filepath):
return True
def _run_command(self, cmd, args):
stream = {
'stdout': io.StringIO(),
'stderr': io.StringIO(),
}
cmd.edit_file_in_external_editor = self._edit_file
cmd.args = Args(args)
with contextlib.redirect_stdout(stream['stdout']):
with contextlib.redirect_stderr(stream['stderr']):
cmd.main()
return stream
def test_init(self):
args = {
'collection': self.collection_dir.name,
'git': True,
}
streams = self._run_command(command.Init(), args)
self.assertEqual(streams['stdout'].getvalue(), '')
self.assertEqual(streams['stderr'].getvalue(), '')
if __name__ == '__main__':
unittest.main()
|