-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_pshell.py
executable file
·112 lines (94 loc) · 3.4 KB
/
test_pshell.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env python3
import os
import sys
import unittest
import subprocess
from subprocess import Popen, PIPE, STDOUT
#------------------------------------------------------------
class pshell_standard(unittest.TestCase):
def setUp(self):
global config, python, script, verbosity
self.config = config
self.python = python
self.script = script
self.verbosity = verbosity
# ---
def test_exit_codes(self):
p = Popen([self.python, self.script, "-v", self.verbosity, "help"], stdout=PIPE, stderr=STDOUT)
data = p.communicate()
code = p.returncode
self.assertEqual(code, 0)
p = Popen([self.python, self.script, "-v", self.verbosity, "bad_command_or_error_of_some_kind"], stdout=PIPE, stderr=STDOUT)
data = p.communicate()
code = p.returncode
self.assertNotEqual(code, 0)
# ---
def test_default_portal_config(self):
flag=False
p = Popen([self.python, self.script, "-v", self.verbosity, "remote"], stdout=PIPE, stderr=STDOUT)
for line in p.stdout:
text = line.decode()
if "portal" in text:
flag=True
self.assertTrue(flag)
# ---
def test_default_public_config(self):
flag=False
p = Popen([self.python, self.script, "-v", self.verbosity, "remote"], stdout=PIPE, stderr=STDOUT)
for line in p.stdout:
text = line.decode()
if "public" in text:
flag=True
self.assertTrue(flag)
# ---
def test_default_private_config(self):
flag=False
p = Popen([self.python, self.script, "-v", self.verbosity, "remote"], stdout=PIPE, stderr=STDOUT)
for line in p.stdout:
text = line.decode()
if "private" in text:
flag=True
self.assertTrue(flag)
# ---
def test_lpwd(self):
flag=False
pwd = os.getcwd()
p = Popen([self.python, self.script, "-v", self.verbosity, "lpwd"], stdout=PIPE, stderr=STDOUT)
for line in p.stdout:
if pwd in line.decode():
flag=True
# ---
def test_lcd(self):
flag=False
p = Popen([self.python, self.script, "-v", self.verbosity, "lcd ."], stdout=PIPE, stderr=STDOUT)
for line in p.stdout:
if 'Local' in line.decode():
flag = True
self.assertTrue(flag)
# ---
def test_lls(self):
flag = False
p = Popen([self.python, self.script, "-v", self.verbosity, "lls"], stdout=PIPE, stderr=STDOUT)
for line in p.stdout:
if "test_pshell.py" in line.decode():
flag = True
self.assertTrue(flag)
#------------------------------------------------------------
if __name__ == '__main__':
global python, config, script, verbosity
print("\n----------------------------------------------------------------------")
print("Running tests for: pshell")
print("----------------------------------------------------------------------\n")
python = "python3"
config = "test"
script = "pshell.py"
verbosity = "0"
# class suite to test
test_class_list = [pshell_standard]
# build suite
suite_list = []
for test_class in test_class_list:
suite_list.append(unittest.TestLoader().loadTestsFromTestCase(test_class))
suite = unittest.TestSuite(suite_list)
# run suite
unittest.TextTestRunner(verbosity=2).run(suite)