@@ -40,7 +40,7 @@ class TestWolframAlphaNoAPIEngine(SearxTestCase):
43−
43+ # test failed query
44 response = mock.Mock(text=html)
44 response = mock.Mock(text=html)
45 self.assertEqual(wolframalpha_noapi.response(response), [])
45 self.assertEqual(wolframalpha_noapi.response(response), [])
@@ -51,113 +51,30 @@ class TestWolframAlphaNoAPIEngine(SearxTestCase):
52 <script type="text/javascript">
52 <script type="text/javascript">
54− document.domain = "wolframalpha.com";
55− context = parent ? parent : document;
58− if (typeof(context.$) == "undefined") {
54+ if (typeof context.jsonArray.popups.pod_0100 == "undefined" ) {
59− context = window;
55+ context.jsonArray.popups.pod_0100 = [];
64− catch(e){ context = window;}
68− if (typeof context.jsonArray.popups.pod_0100 == "undefined" ) {
69− context.jsonArray.popups.pod_0100 = [];
72− context.jsonArray.popups.pod_0100.push( {"stringified": "sqrt(-1)","mInput": "","mOutput": "", "popLinks": {} });
57+ context.jsonArray.popups.pod_0100.push( {"stringified": "sqrt(-1)","mInput": "","mOutput": ""});
74− } catch(e) { }
58+ } catch(e) { }
78− $("#results #pod_0100:not(iframe #pod_0100)")
79− .add("#showsteps #pod_0100:not(iframe #pod_0100)")
80− .add(".results-pod #pod_0100:not(iframe #pod_0100)")
81− .data("tempFileID", 'MSP44501e0dda34g97a0c8900003i71207d6491ab22')
82− .data("podIdentifier", '\x22Input\x22')
83− .data("podShortIdentifier", '\x22Input\x22')
84− .data("buttonStates", '\x22\x22')
85− .data("scanner", '\x22\x22');
86− $("#results #pod_0100-popup:not(iframe #pod_0100-popup)")
87− .add("#showsteps #pod_0100-popup:not(iframe #pod_0100-popup)")
88− .add(".results-pod #pod_0100-popup:not(iframe #pod_0100-popup)")
89− .data("tempFileID", 'MSP44501e0dda34g97a0c8900003i71207d6491ab22')
90− .data("podIdentifier", '\x22Input\x22')
91− .data("podShortIdentifier", '\x22Input\x22')
92− .data("buttonStates", '\x22\x22')
93− .data("scanner", '\x22\x22');
95− $("#results #subpod_0100_1")
96− .add("#showsteps #subpod_0100_1:not(iframe #subpod_0100_1)")
97− .add(".results-pod #subpod_0100_1")
98− .data("tempFileID", "MSP44511e0dda34g97a0c89000059490h319161eea3")
99− .data("cellDataTempFile", "MSP44521e0dda34g97a0c89000011378c50d38ede6h")
100− .data("tempFileServer", "")
101− .data("dataSources", "")
102− .data("sources", "")
103− .data("sharetype", "1")
104− .data("shareable", "false");
112− if (typeof context.jsonArray.popups.pod_0200 == "undefined" ) {
113− context.jsonArray.popups.pod_0200 = [];
116− context.jsonArray.popups.pod_0200.push( {"stringified": "i","mInput": "","mOutput": "", "popLinks": {} });
122− $("#results #pod_0200:not(iframe #pod_0200)")
60+ try {
123− .add("#showsteps #pod_0200:not(iframe #pod_0200)")
61+ if (typeof context.jsonArray.popups.pod_0200 == "undefined" ) {
124− .add(".results-pod #pod_0200:not(iframe #pod_0200)")
62+ context.jsonArray.popups.pod_0200 = [];
125− .data("tempFileID", 'MSP44541e0dda34g97a0c8900004f449i50fa482fd8')
63+ }
126− .data("podIdentifier", '\x22Result\x22')
64+ context.jsonArray.popups.pod_0200.push( {"stringified": "i","mInput": "","mOutput": ""});
127− .data("podShortIdentifier", '\x22Result\x22')
128− .data("buttonStates", '\x22Result\x22\x20\x2D\x3E\x20\x7BAll,\x20None,\x20None,\x20None,\x20None\x7D')
129− .data("scanner", '\x22\x22');
130− $("#results #pod_0200-popup:not(iframe #pod_0200-popup)")
131− .add("#showsteps #pod_0200-popup:not(iframe #pod_0200-popup)")
132− .add(".results-pod #pod_0200-popup:not(iframe #pod_0200-popup)")
133− .data("tempFileID", 'MSP44541e0dda34g97a0c8900004f449i50fa482fd8')
134− .data("podIdentifier", '\x22Result\x22')
135− .data("podShortIdentifier", '\x22Result\x22')
136− .data("buttonStates", '\x22Result\x22\x20\x2D\x3E\x20\x7BAll,\x20None,\x20None\x7D')
137− .data("scanner", '\x22\x22');
139− $("#results #subpod_0200_1")
140− .add("#showsteps #subpod_0200_1:not(iframe #subpod_0200_1)")
141− .add(".results-pod #subpod_0200_1")
142− .data("tempFileID", "MSP44551e0dda34g97a0c8900003gdgd37faa7272e0")
143− .data("cellDataTempFile", "MSP44561e0dda34g97a0c89000018ea1iae00104g13")
144− .data("tempFileServer", "")
145− .data("dataSources", "")
146− .data("sources", "")
147− .data("sharetype", "1")
148− .data("shareable", "false");
149− } catch(e){}
65+ } catch(e) { }
150 </script>
66 </script>
154 response = mock.Mock(text=html)
71 response = mock.Mock(text=html)
155 results = wolframalpha_noapi.response(response)
72 results = wolframalpha_noapi.response(response)
156 self.assertEqual(type(results), list)
73 self.assertEqual(type(results), list)
157 self.assertEqual(len(results), 2)
74 self.assertEqual(len(results), 2)
158− self.assertIn("i", results[0]['answer'])
75+ self.assertEquals('i', results[0]['answer'])
159− self.assertIn("sqrt(-1) - Wolfram|Alpha", results[1]['title'])
76+ self.assertIn('sqrt(-1) - Wolfram|Alpha', results[1]['title'])
160− self.assertIn("http://www.wolframalpha.com/input/?i=+sqrt%28-1%29", results[1]['url'])
77+ self.assertEquals('http://www.wolframalpha.com/input/?i=+sqrt%28-1%29', results[1]['url'])
162 html = """
79 html = """
163 <!DOCTYPE html>
80 <!DOCTYPE html>
@@ -165,91 +82,78 @@ class TestWolframAlphaNoAPIEngine(SearxTestCase):
165 <meta charset="utf-8" />
82 <meta charset="utf-8" />
167 <script type="text/javascript">
84 <script type="text/javascript">
170− document.domain = "wolframalpha.com";
171− context = parent ? parent : document;
174− if (typeof(context.$) == "undefined") {
86+ if (typeof context.jsonArray.popups.pod_0100 == "undefined" ) {
175− context = window;
87+ context.jsonArray.popups.pod_0100 = [];
180− catch(e){ context = window;}
184− if (typeof context.jsonArray.popups.pod_0100 == "undefined" ) {
185− context.jsonArray.popups.pod_0100 = [];
188− context.jsonArray.popups.pod_0100.push( {"stringified": "integral 1\/x dx = log(x)+constant"});
89+ context.jsonArray.popups.pod_0100.push( {"stringified": "integral 1\/x dx = log(x)+constant"});
190− } catch(e) { }
90+ } catch(e) { }
194− $("#results #pod_0100:not(iframe #pod_0100)")
94+ """
195− .add("#showsteps #pod_0100:not(iframe #pod_0100)")
95+ # test integral
196− .add(".results-pod #pod_0100:not(iframe #pod_0100)")
96+ response = mock.Mock(text=html)
197− .data("tempFileID", 'MSP2051if2202e8bg0757100000d119b05egf583d3')
97+ results = wolframalpha_noapi.response(response)
198− .data("podIdentifier", '\x22IndefiniteIntegral\x22')
98+ self.assertEqual(type(results), list)
199− .data("podShortIdentifier", '\x22IndefiniteIntegral\x22')
99+ self.assertEqual(len(results), 2)
200− .data("buttonStates", '\x22Indefinite\x20integral\x22\x20\x2D\x3E\x20\x7B\x7D')
100+ self.assertIn('log(x)+c', results[0]['answer'])
201− .data("scanner", '\x22\x22');
101+ self.assertIn('integral 1/x - Wolfram|Alpha', results[1]['title'])
202− $("#results #pod_0100-popup:not(iframe #pod_0100-popup)")
102+ self.assertEquals('http://www.wolframalpha.com/input/?i=+integral+1%2Fx', results[1]['url'])
203− .add("#showsteps #pod_0100-popup:not(iframe #pod_0100-popup)")
204− .add(".results-pod #pod_0100-popup:not(iframe #pod_0100-popup)")
205− .data("tempFileID", 'MSP2051if2202e8bg0757100000d119b05egf583d3')
206− .data("podIdentifier", '\x22IndefiniteIntegral\x22')
207− .data("podShortIdentifier", '\x22IndefiniteIntegral\x22')
208− .data("buttonStates", '\x22Indefinite\x20integral\x22\x20\x2D\x3E\x20\x7B\x7D')
209− .data("scanner", '\x22\x22');
211− $("#results #subpod_0100_1")
212− .add("#showsteps #subpod_0100_1:not(iframe #subpod_0100_1)")
213− .add(".results-pod #subpod_0100_1")
214− .data("tempFileID", "MSP2071if2202e8bg0757100004dg60f2a4ca8cf73")
215− .data("cellDataTempFile", "MSP2081if2202e8bg0757100001h18329f72fe90fg")
216− .data("tempFileServer", "")
217− .data("dataSources", "")
218− .data("sources", "")
219− .data("sharetype", "1")
220− .data("shareable", "false");
224− //false
104+ html = """
106+ <title> ∫1/x x - Wolfram|Alpha</title>
107+ <meta charset="utf-8" />
109+ <script type="text/javascript">
111+ if (typeof context.jsonArray.popups.pod_0100 == "undefined" ) {
112+ context.jsonArray.popups.pod_0100 = [];
114+ context.jsonArray.popups.pod_0100.push( {"stringified": "integral 1\/x dx = log(x)+constant"});
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'])
227− $("#results #pod_0200:not(iframe #pod_0200)")
129+ html = """
228− .add("#showsteps #pod_0200:not(iframe #pod_0200)")
130+ <!DOCTYPE html>
229− .add(".results-pod #pod_0200:not(iframe #pod_0200)")
131+ <title> 1 euro to yen - Wolfram|Alpha</title>
230− .data("tempFileID", '')
132+ <meta charset="utf-8" />
231− .data("podIdentifier", '\x22Plot\x22')
133+ <body>
232− .data("podShortIdentifier", '')
134+ <script type="text/javascript">
233− .data("buttonStates", '')
135+ try {
234− .data("scanner", '\x22\x22');
136+ if (typeof context.jsonArray.popups.pod_0100 == "undefined" ) {
235− $("#results #pod_0200-popup:not(iframe #pod_0200-popup)")
137+ context.jsonArray.popups.pod_0100 = [];
236− .add("#showsteps #pod_0200-popup:not(iframe #pod_0200-popup)")
138+ }
237− .add(".results-pod #pod_0200-popup:not(iframe #pod_0200-popup)")
139+ context.jsonArray.popups.pod_0100.push( {"stringified": "convert euro1 (euro) to Japanese yen"});
238− .data("tempFileID", '')
140+ } catch(e) { }
239− .data("podIdentifier", '\x22Plot\x22')
240− .data("podShortIdentifier", '')
241− .data("buttonStates", '')
242− .data("scanner", '\x22\x22');
143+ if (typeof context.jsonArray.popups.pod_0200 == "undefined" ) {
144+ context.jsonArray.popups.pod_0200 = [];
146+ context.jsonArray.popups.pod_0200.push( {"stringified": "¥130.5 (Japanese yen)"});
244− } catch(e){}
147+ } catch(e) { }
245 </script>
148 </script>
152+ # test output in htmlentity
249 response = mock.Mock(text=html)
153 response = mock.Mock(text=html)
250 results = wolframalpha_noapi.response(response)
154 results = wolframalpha_noapi.response(response)
251 self.assertEqual(type(results), list)
155 self.assertEqual(type(results), list)
252 self.assertEqual(len(results), 2)
156 self.assertEqual(len(results), 2)
253− self.assertIn("log(x)+c", results[0]['answer'])
157+ self.assertIn("¥".decode('utf-8'), results[0]['answer'])
254− self.assertIn("integral 1/x - Wolfram|Alpha", results[1]['title'])
158+ self.assertIn('1 euro to yen - Wolfram|Alpha', results[1]['title'])
255− self.assertIn("http://www.wolframalpha.com/input/?i=+integral+1%2Fx", results[1]['url'])
159+ self.assertEquals('http://www.wolframalpha.com/input/?i=+1+euro+to+yen', results[1]['url'])