-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathtest_cli.py
More file actions
55 lines (43 loc) · 1.34 KB
/
test_cli.py
File metadata and controls
55 lines (43 loc) · 1.34 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import logging
import sys
import unittest
from haystack import cli
from test.haystack import SrcTests
from contextlib import contextmanager
try:
from StringIO import StringIO
except:
from io import StringIO
@contextmanager
def captured_output():
new_out, new_err = StringIO(), StringIO()
old_out, old_err = sys.stdout, sys.stderr
try:
sys.stdout, sys.stderr = new_out, new_err
yield sys.stdout, sys.stderr
finally:
sys.stdout, sys.stderr = old_out, old_err
class TestCLI(SrcTests):
@unittest.skip('argparse kills the run')
def test_cli_usage(self):
# check the helper desc
# use buffered mode
args = ['haystack-search', '--help']
sys.argv = args
with captured_output() as (out, err):
cli.search()
# This can go inside or outside the `with` block
output = out.getvalue().strip()
self.assertIn(output, 'dir://')
self.assertIn(output, 'dmp://')
self.assertIn(output, 'volatility://')
self.assertIn(output, 'rekall://')
self.assertIn(output, 'live://')
# self.assertIn('0x000d0000', ret)
return
if __name__ == '__main__':
logging.basicConfig(level=logging.INFO)
# logging.basicConfig(level=logging.INFO)
unittest.main(verbosity=2)