-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsearch_test.py
81 lines (59 loc) · 2.86 KB
/
search_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
import sys
import os
import unittest
import subprocess
sys.path.insert(0,r'./') #Add root directory here
class GoogleTest(unittest.TestCase):
def test_code_success(self):
process = subprocess.Popen(["python", "google", "--help"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True)
result, err = process.communicate()
if process.returncode != 0:
raise Exception("File handling failed %d %s %s" % (process.returncode, result, err))
with open('./test_example/python_help.txt', 'r') as f:
help_ref = f.read()
self.assertEqual(help_ref.lower(), str(result).lower())
def test_code_search_wiki(self):
process = subprocess.Popen(["python", "google", "Facebook"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True)
result, err = process.communicate()
if process.returncode != 0:
raise Exception("File handling failed %d %s %s" % (process.returncode, result, err))
with open('./test_example/Facebook_wiki.txt', 'r') as f:
facebook_wiki_ref = f.read()
self.assertIn(facebook_wiki_ref.lower(), str(result).lower())
def test_build_success(self):
# Change the current working directory
cwd = os.getcwd()
process = subprocess.Popen(["./google", "--help"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
cwd=os.path.join(cwd,'dist'), shell=True)
result, err = process.communicate()
if process.returncode != 0:
raise Exception("File handling failed %d %s %s" % (process.returncode, result, err))
with open('./test_example/help.txt', 'r') as f:
help_ref = f.read()
self.assertEqual(help_ref.lower(), str(result).lower())
def test_search_wiki(self):
# Change the current working directory
cwd = os.getcwd()
process = subprocess.Popen(["./google", "Facebook"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
cwd=os.path.join(cwd,'dist'), shell=True)
result, err = process.communicate()
if process.returncode != 0:
raise Exception("File handling failed %d %s %s" % (process.returncode, result, err))
with open('./test_example/Facebook_wiki.txt', 'r') as f:
facebook_wiki_ref = f.read()
self.assertIn(facebook_wiki_ref.lower(), str(result).lower())
print(err)
def main():
unittest.main()
if __name__ == "__main__":
main()