Discussion:
PyLucene package test error
Shawn Gao
2017-01-06 11:02:11 UTC
Permalink
Hello, PyLucene User and Developers

Problems occurred during `make test` in pylucene-6.2.0 from PyLucen
Homepage <http://lucene.apache.org/pylucene> when testing
'test_PythonException.py'. And I think there might be something wrong with
the test python code.

The test python code I run and the Error Log are posted at the end of
this email.

The test script raised a python-exception(TestException). But it return
a JavaError first, which failed the test.

If I change assertRaises(TestException) to
assertRaises(lucene.JavaError) here, it passed the test.

Should I make this change to pass the test. Or am I missing something?


Thanks for your advice!



Here comes the python script:

import sys, lucene, unittest
from PyLuceneTestCase import PyLuceneTestCase

from org.apache.lucene.analysis.standard import StandardAnalyzer
from org.apache.pylucene.queryparser.classic import PythonQueryParser


class PythonExceptionTestCase(PyLuceneTestCase):
def testThroughLayerException(self):
class TestException(Exception):
pass

class TestQueryParser(PythonQueryParser):
def getFieldQuery_quoted(_self, field, queryText, quoted):
raise TestException("TestException")

qp = TestQueryParser('all', StandardAnalyzer())

with self.assertRaises(TestException):
qp.parse("foo bar")

if __name__ == "__main__":
lucene.initVM(vmargs=['-Djava.awt.headless=true'])
if '-loop' in sys.argv:
print "in if"
sys.argv.remove('-loop')
while True:
try:
unittest.main()
except:
pass
else:
print "in else"
unittest.main()


Here's the Error StackTrace:


***@shawn-Precision-T1700:~/workspace/pylucene-6.2.0/test$ python
./test_PythonException.py
in else
E
======================================================================
ERROR: testThroughLayerException (__main__.PythonExceptionTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "./test_PythonException.py", line 34, in testThroughLayerException
qp.parse("foo bar")
JavaError: <super: <class 'JavaError'>, <JavaError object>>
Java stacktrace:
java.lang.RuntimeException: TestException
at org.apache.pylucene.queryparser.classic.PythonQueryParser.getFieldQuery_quoted(Native
Method)
at org.apache.pylucene.queryparser.classic.PythonQueryParser.getFieldQuery(Unknown
Source)
at org.apache.lucene.queryparser.classic.QueryParser.MultiTerm(
QueryParser.java:585)
at org.apache.lucene.queryparser.classic.QueryParser.Query(
QueryParser.java:198)
at org.apache.lucene.queryparser.classic.QueryParser.
TopLevelQuery(QueryParser.java:187)
at org.apache.lucene.queryparser.classic.QueryParserBase.parse(
QueryParserBase.java:111)
Shawn Gao
2017-01-06 10:51:19 UTC
Permalink
Hello, PyLucene User and Developers

Problems occurred during `make test` in pylucene-6.2.0 from PyLucen
Homepage <http://lucene.apache.org/pylucene> when testing
'test_PythonException.py'. And I think there might be something wrong with
the test python code.

The test python code I run and the Error Log are posted at the end of
this email.

The test script raised a python-exception(TestException). But it return
a JavaError first, which failed the test.

If I change assertRaises(TestException) to
assertRaises(lucene.JavaError) here, it passed the test.

Should I make this change to pass the test. Or am I missing something?


Thanks for your advice!



Here comes the python script:

import sys, lucene, unittest
from PyLuceneTestCase import PyLuceneTestCase

from org.apache.lucene.analysis.standard import StandardAnalyzer
from org.apache.pylucene.queryparser.classic import PythonQueryParser


class PythonExceptionTestCase(PyLuceneTestCase):
def testThroughLayerException(self):
class TestException(Exception):
pass

class TestQueryParser(PythonQueryParser):
def getFieldQuery_quoted(_self, field, queryText, quoted):
raise TestException("TestException")

qp = TestQueryParser('all', StandardAnalyzer())

with self.assertRaises(TestException):
qp.parse("foo bar")

if __name__ == "__main__":
lucene.initVM(vmargs=['-Djava.awt.headless=true'])
if '-loop' in sys.argv:
print "in if"
sys.argv.remove('-loop')
while True:
try:
unittest.main()
except:
pass
else:
print "in else"
unittest.main()


Here's the Error StackTrace:


***@shawn-Precision-T1700:~/workspace/pylucene-6.2.0/test$ python
./test_PythonException.py
in else
E
======================================================================
ERROR: testThroughLayerException (__main__.PythonExceptionTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "./test_PythonException.py", line 34, in testThroughLayerException
qp.parse("foo bar")
JavaError: <super: <class 'JavaError'>, <JavaError object>>
Java stacktrace:
java.lang.RuntimeException: TestException
at
org.apache.pylucene.queryparser.classic.PythonQueryParser.getFieldQuery_quoted(Native
Method)
at
org.apache.pylucene.queryparser.classic.PythonQueryParser.getFieldQuery(Unknown
Source)
at
org.apache.lucene.queryparser.classic.QueryParser.MultiTerm(QueryParser.java:585)
at
org.apache.lucene.queryparser.classic.QueryParser.Query(QueryParser.java:198)
at
org.apache.lucene.queryparser.classic.QueryParser.TopLevelQuery(QueryParser.java:187)
at
org.apache.lucene.queryparser.classic.QueryParserBase.parse(QueryParserBase.java:111)
Andi Vajda
2017-01-06 15:20:58 UTC
Permalink
Post by Shawn Gao
Hello, PyLucene User and Developers
Problems occurred during `make test` in pylucene-6.2.0 from PyLucen
Homepage <http://lucene.apache.org/pylucene> when testing
'test_PythonException.py'. And I think there might be something wrong with
the test python code.
This error was just covered on another thread a few days ago: you either didn't build jcc in shared mode or didn't use --shared then on the jcc invocation lcommand line in PyLucene's Makefile when building it. The bug is that this test should be disabled when jcc is not in shared mode since this exception support depends on it.

Andi..
Post by Shawn Gao
The test python code I run and the Error Log are posted at the end of
this email.
The test script raised a python-exception(TestException). But it return
a JavaError first, which failed the test.
If I change assertRaises(TestException) to
assertRaises(lucene.JavaError) here, it passed the test.
Should I make this change to pass the test. Or am I missing something?
Thanks for your advice!
import sys, lucene, unittest
from PyLuceneTestCase import PyLuceneTestCase
from org.apache.lucene.analysis.standard import StandardAnalyzer
from org.apache.pylucene.queryparser.classic import PythonQueryParser
pass
raise TestException("TestException")
qp = TestQueryParser('all', StandardAnalyzer())
qp.parse("foo bar")
lucene.initVM(vmargs=['-Djava.awt.headless=true'])
print "in if"
sys.argv.remove('-loop')
unittest.main()
pass
print "in else"
unittest.main()
./test_PythonException.py
in else
E
======================================================================
ERROR: testThroughLayerException (__main__.PythonExceptionTestCase)
----------------------------------------------------------------------
File "./test_PythonException.py", line 34, in testThroughLayerException
qp.parse("foo bar")
JavaError: <super: <class 'JavaError'>, <JavaError object>>
java.lang.RuntimeException: TestException
at org.apache.pylucene.queryparser.classic.PythonQueryParser.getFieldQuery_quoted(Native
Method)
at org.apache.pylucene.queryparser.classic.PythonQueryParser.getFieldQuery(Unknown
Source)
at org.apache.lucene.queryparser.classic.QueryParser.MultiTerm(
QueryParser.java:585)
at org.apache.lucene.queryparser.classic.QueryParser.Query(
QueryParser.java:198)
at org.apache.lucene.queryparser.classic.QueryParser.
TopLevelQuery(QueryParser.java:187)
at org.apache.lucene.queryparser.classic.QueryParserBase.parse(
QueryParserBase.java:111)
Shawn Gao
2017-01-09 12:00:52 UTC
Permalink
Thank you Andi !

I change the build configuration for jcc and PyLucen to shared mode, and
try to build again. It worked!

Thanks again for the detailed explanation!
Post by Andi Vajda
Post by Shawn Gao
Hello, PyLucene User and Developers
Problems occurred during `make test` in pylucene-6.2.0 from PyLucen
Homepage <http://lucene.apache.org/pylucene> when testing
'test_PythonException.py'. And I think there might be something wrong
with
Post by Shawn Gao
the test python code.
This error was just covered on another thread a few days ago: you either
didn't build jcc in shared mode or didn't use --shared then on the jcc
invocation lcommand line in PyLucene's Makefile when building it. The bug
is that this test should be disabled when jcc is not in shared mode since
this exception support depends on it.
Andi..
Post by Shawn Gao
The test python code I run and the Error Log are posted at the end of
this email.
The test script raised a python-exception(TestException). But it
return
Post by Shawn Gao
a JavaError first, which failed the test.
If I change assertRaises(TestException) to
assertRaises(lucene.JavaError) here, it passed the test.
Should I make this change to pass the test. Or am I missing something?
Thanks for your advice!
import sys, lucene, unittest
from PyLuceneTestCase import PyLuceneTestCase
from org.apache.lucene.analysis.standard import StandardAnalyzer
from org.apache.pylucene.queryparser.classic import PythonQueryParser
pass
raise TestException("TestException")
qp = TestQueryParser('all', StandardAnalyzer())
qp.parse("foo bar")
lucene.initVM(vmargs=['-Djava.awt.headless=true'])
print "in if"
sys.argv.remove('-loop')
unittest.main()
pass
print "in else"
unittest.main()
./test_PythonException.py
in else
E
======================================================================
ERROR: testThroughLayerException (__main__.PythonExceptionTestCase)
----------------------------------------------------------------------
File "./test_PythonException.py", line 34, in testThroughLayerException
qp.parse("foo bar")
JavaError: <super: <class 'JavaError'>, <JavaError object>>
java.lang.RuntimeException: TestException
at org.apache.pylucene.queryparser.classic.PythonQueryParser.
getFieldQuery_quoted(Native
Post by Shawn Gao
Method)
at org.apache.pylucene.queryparser.classic.PythonQueryParser.
getFieldQuery(Unknown
Post by Shawn Gao
Source)
at org.apache.lucene.queryparser.classic.QueryParser.MultiTerm(
QueryParser.java:585)
at org.apache.lucene.queryparser.classic.QueryParser.Query(
QueryParser.java:198)
at org.apache.lucene.queryparser.classic.QueryParser.
TopLevelQuery(QueryParser.java:187)
at org.apache.lucene.queryparser.classic.QueryParserBase.parse(
QueryParserBase.java:111)
Loading...