|
@@ -1,6 +1,5 @@
|
1
|
1
|
# -*- coding: utf-8 -*-
|
2
|
2
|
from collections import defaultdict
|
3
|
|
-import mock
|
4
|
3
|
from searx.engines import wolframalpha_noapi
|
5
|
4
|
from searx.testing import SearxTestCase
|
6
|
5
|
|
|
@@ -21,173 +20,4 @@ class TestWolframAlphaNoAPIEngine(SearxTestCase):
|
21
|
20
|
self.assertRaises(AttributeError, wolframalpha_noapi.response, [])
|
22
|
21
|
self.assertRaises(AttributeError, wolframalpha_noapi.response, '')
|
23
|
22
|
self.assertRaises(AttributeError, wolframalpha_noapi.response, '[]')
|
24
|
|
-
|
25
|
|
- html = """
|
26
|
|
- <!DOCTYPE html>
|
27
|
|
- <title> Parangaricutirimícuaro - Wolfram|Alpha</title>
|
28
|
|
- <meta charset="utf-8" />
|
29
|
|
- <body>
|
30
|
|
- <div id="closest">
|
31
|
|
- <p class="pfail">Wolfram|Alpha doesn't know how to interpret your input.</p>
|
32
|
|
- <div id="dtips">
|
33
|
|
- <div class="tip">
|
34
|
|
- <span class="tip-title">Tip: </span>
|
35
|
|
- Check your spelling, and use English
|
36
|
|
- <span class="tip-extra"></span>
|
37
|
|
- </div>
|
38
|
|
- </div>
|
39
|
|
- </div>
|
40
|
|
- </body>
|
41
|
|
- </html>
|
42
|
|
- """
|
43
|
|
- # test failed query
|
44
|
|
- response = mock.Mock(text=html)
|
45
|
|
- self.assertEqual(wolframalpha_noapi.response(response), [])
|
46
|
|
-
|
47
|
|
- html = """
|
48
|
|
- <!DOCTYPE html>
|
49
|
|
- <title> sqrt(-1) - Wolfram|Alpha</title>
|
50
|
|
- <meta charset="utf-8" />
|
51
|
|
- <body>
|
52
|
|
- <script type="text/javascript">
|
53
|
|
- try {
|
54
|
|
- if (typeof context.jsonArray.popups.pod_0100 == "undefined" ) {
|
55
|
|
- context.jsonArray.popups.pod_0100 = [];
|
56
|
|
- }
|
57
|
|
- context.jsonArray.popups.pod_0100.push( {"stringified": "sqrt(-1)","mInput": "","mOutput": ""});
|
58
|
|
- } catch(e) { }
|
59
|
|
-
|
60
|
|
- try {
|
61
|
|
- if (typeof context.jsonArray.popups.pod_0200 == "undefined" ) {
|
62
|
|
- context.jsonArray.popups.pod_0200 = [];
|
63
|
|
- }
|
64
|
|
- context.jsonArray.popups.pod_0200.push( {"stringified": "i","mInput": "","mOutput": ""});
|
65
|
|
- } catch(e) { }
|
66
|
|
- </script>
|
67
|
|
- </body>
|
68
|
|
- </html>
|
69
|
|
- """
|
70
|
|
- # test plaintext
|
71
|
|
- response = mock.Mock(text=html)
|
72
|
|
- results = wolframalpha_noapi.response(response)
|
73
|
|
- self.assertEqual(type(results), list)
|
74
|
|
- self.assertEqual(len(results), 2)
|
75
|
|
- self.assertEquals('i', results[0]['answer'])
|
76
|
|
- self.assertIn('sqrt(-1) - Wolfram|Alpha', results[1]['title'])
|
77
|
|
- self.assertEquals('http://www.wolframalpha.com/input/?i=+sqrt%28-1%29', results[1]['url'])
|
78
|
|
-
|
79
|
|
- html = """
|
80
|
|
- <!DOCTYPE html>
|
81
|
|
- <title> integral 1/x - Wolfram|Alpha</title>
|
82
|
|
- <meta charset="utf-8" />
|
83
|
|
- <body>
|
84
|
|
- <script type="text/javascript">
|
85
|
|
- try {
|
86
|
|
- if (typeof context.jsonArray.popups.pod_0100 == "undefined" ) {
|
87
|
|
- context.jsonArray.popups.pod_0100 = [];
|
88
|
|
- }
|
89
|
|
- context.jsonArray.popups.pod_0100.push( {"stringified": "integral 1\/x dx = log(x)+constant"});
|
90
|
|
- } catch(e) { }
|
91
|
|
- </script>
|
92
|
|
- </body>
|
93
|
|
- </html>
|
94
|
|
- """
|
95
|
|
- # test integral
|
96
|
|
- response = mock.Mock(text=html)
|
97
|
|
- results = wolframalpha_noapi.response(response)
|
98
|
|
- self.assertEqual(type(results), list)
|
99
|
|
- self.assertEqual(len(results), 2)
|
100
|
|
- self.assertIn('log(x)+c', results[0]['answer'])
|
101
|
|
- self.assertIn('integral 1/x - Wolfram|Alpha', results[1]['title'])
|
102
|
|
- self.assertEquals('http://www.wolframalpha.com/input/?i=+integral+1%2Fx', results[1]['url'])
|
103
|
|
-
|
104
|
|
- html = """
|
105
|
|
- <!DOCTYPE html>
|
106
|
|
- <title> ∫1/x x - Wolfram|Alpha</title>
|
107
|
|
- <meta charset="utf-8" />
|
108
|
|
- <body>
|
109
|
|
- <script type="text/javascript">
|
110
|
|
- try {
|
111
|
|
- if (typeof context.jsonArray.popups.pod_0100 == "undefined" ) {
|
112
|
|
- context.jsonArray.popups.pod_0100 = [];
|
113
|
|
- }
|
114
|
|
- context.jsonArray.popups.pod_0100.push( {"stringified": "integral 1\/x dx = log(x)+constant"});
|
115
|
|
- } catch(e) { }
|
116
|
|
- </script>
|
117
|
|
- </body>
|
118
|
|
- </html>
|
119
|
|
- """
|
120
|
|
- # test input in mathematical notation
|
121
|
|
- response = mock.Mock(text=html)
|
122
|
|
- results = wolframalpha_noapi.response(response)
|
123
|
|
- self.assertEqual(type(results), list)
|
124
|
|
- self.assertEqual(len(results), 2)
|
125
|
|
- self.assertIn('log(x)+c', results[0]['answer'])
|
126
|
|
- self.assertIn('∫1/x x - Wolfram|Alpha'.decode('utf-8'), results[1]['title'])
|
127
|
|
- self.assertEquals('http://www.wolframalpha.com/input/?i=+%E2%88%AB1%2Fx+%EF%9D%8Cx', results[1]['url'])
|
128
|
|
-
|
129
|
|
- html = """
|
130
|
|
- <!DOCTYPE html>
|
131
|
|
- <title> 1 euro to yen - Wolfram|Alpha</title>
|
132
|
|
- <meta charset="utf-8" />
|
133
|
|
- <body>
|
134
|
|
- <script type="text/javascript">
|
135
|
|
- try {
|
136
|
|
- if (typeof context.jsonArray.popups.pod_0100 == "undefined" ) {
|
137
|
|
- context.jsonArray.popups.pod_0100 = [];
|
138
|
|
- }
|
139
|
|
- context.jsonArray.popups.pod_0100.push( {"stringified": "convert euro1 (euro) to Japanese yen"});
|
140
|
|
- } catch(e) { }
|
141
|
|
-
|
142
|
|
- try {
|
143
|
|
- if (typeof context.jsonArray.popups.pod_0200 == "undefined" ) {
|
144
|
|
- context.jsonArray.popups.pod_0200 = [];
|
145
|
|
- }
|
146
|
|
- context.jsonArray.popups.pod_0200.push( {"stringified": "¥130.5 (Japanese yen)"});
|
147
|
|
- } catch(e) { }
|
148
|
|
- </script>
|
149
|
|
- </body>
|
150
|
|
- </html>
|
151
|
|
- """
|
152
|
|
- # test output with htmlentity
|
153
|
|
- response = mock.Mock(text=html)
|
154
|
|
- results = wolframalpha_noapi.response(response)
|
155
|
|
- self.assertEqual(type(results), list)
|
156
|
|
- self.assertEqual(len(results), 2)
|
157
|
|
- self.assertIn('¥'.decode('utf-8'), results[0]['answer'])
|
158
|
|
- self.assertIn('1 euro to yen - Wolfram|Alpha', results[1]['title'])
|
159
|
|
- self.assertEquals('http://www.wolframalpha.com/input/?i=+1+euro+to+yen', results[1]['url'])
|
160
|
|
-
|
161
|
|
- html = """
|
162
|
|
- <!DOCTYPE html>
|
163
|
|
- <title> distance from nairobi to kyoto in inches - Wolfram|Alpha</title>
|
164
|
|
- <meta charset="utf-8" />
|
165
|
|
- <body>
|
166
|
|
- <script type="text/javascript">
|
167
|
|
- try {
|
168
|
|
- if (typeof context.jsonArray.popups.pod_0100 == "undefined" ) {
|
169
|
|
- context.jsonArray.popups.pod_0100 = [];
|
170
|
|
- }
|
171
|
|
-[...].pod_0100.push( {"stringified": "convert distance | from | Nairobi, Kenya\nto | Kyoto, Japan to inches"});
|
172
|
|
- } catch(e) { }
|
173
|
|
-
|
174
|
|
- try {
|
175
|
|
- if (typeof context.jsonArray.popups.pod_0200 == "undefined" ) {
|
176
|
|
- context.jsonArray.popups.pod_0200 = [];
|
177
|
|
- }
|
178
|
|
-pod_0200.push({"stringified": "4.295×10^8 inches","mOutput": "Quantity[4.295×10^8,&quot;Inches&quot;]"});
|
179
|
|
-
|
180
|
|
- } catch(e) { }
|
181
|
|
- </script>
|
182
|
|
- </body>
|
183
|
|
- </html>
|
184
|
|
- """
|
185
|
|
- # test output with utf-8 character
|
186
|
|
- response = mock.Mock(text=html)
|
187
|
|
- results = wolframalpha_noapi.response(response)
|
188
|
|
- self.assertEqual(type(results), list)
|
189
|
|
- self.assertEqual(len(results), 2)
|
190
|
|
- self.assertIn('4.295×10^8 inches'.decode('utf-8'), results[0]['answer'])
|
191
|
|
- self.assertIn('distance from nairobi to kyoto in inches - Wolfram|Alpha', results[1]['title'])
|
192
|
|
- self.assertEquals('http://www.wolframalpha.com/input/?i=+distance+from+nairobi+to+kyoto+in+inches',
|
193
|
|
- results[1]['url'])
|
|
23
|
+ # TODO
|