forked from Blazemeter/taurus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_utils.py
53 lines (39 loc) · 1.66 KB
/
test_utils.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
""" unit test """
import sys
import logging
from psutil import Popen
from bzt.utils import log_std_streams, get_uniq_name, JavaVM, ToolError, is_windows
from tests import BZTestCase
class TestJavaVM(BZTestCase):
def test_missed_tool(self):
self.obj = JavaVM(logging.getLogger(''), tool_path='java-not-found')
self.assertEqual(False, self.obj.check_if_installed())
self.assertRaises(ToolError, self.obj.install)
class TestLogStreams(BZTestCase):
def test_streams(self):
self.sniff_log(logging.getLogger(''))
print('test1')
with log_std_streams(logger=self.captured_logger, stdout_level=logging.DEBUG):
print('test2')
with log_std_streams(stdout_level=logging.DEBUG):
print('test3')
with log_std_streams(stdout_level=logging.DEBUG):
sys.stdout.write('test3')
with log_std_streams(logger=self.captured_logger, stdout_level=logging.DEBUG):
process = Popen(['echo', '"test5"'])
process.wait()
missed_file = get_uniq_name('.', 'test6', '')
with log_std_streams(logger=self.captured_logger, stderr_level=logging.WARNING):
if is_windows():
cmd = 'dir'
else:
cmd = 'ls'
process = Popen([cmd, missed_file])
process.wait()
debug_buf = self.log_recorder.debug_buff.getvalue()
warn_buf = self.log_recorder.warn_buff.getvalue()
self.assertNotIn('test1', debug_buf)
self.assertIn('test2', debug_buf)
self.assertNotIn('test3', debug_buf)
self.assertIn('test5', debug_buf)
self.assertTrue(len(warn_buf) > 0)