mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-10-03 17:50:11 +02:00
FDroidException handle Exceptions that return things other than str
This is related to a4c4a16ed9
This commit is contained in:
parent
af0d8ab84c
commit
7d4e354f25
@ -17,7 +17,10 @@ class FDroidException(Exception):
|
||||
return ret
|
||||
|
||||
def __str__(self):
|
||||
ret = self.value
|
||||
if self.value is None:
|
||||
ret = __name__
|
||||
else:
|
||||
ret = str(self.value)
|
||||
if self.detail:
|
||||
ret += "\n==== detail begin ====\n%s\n==== detail end ====" % ''.join(self.detail).strip()
|
||||
return ret
|
||||
|
65
tests/exception.TestCase
Executable file
65
tests/exception.TestCase
Executable file
@ -0,0 +1,65 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# http://www.drdobbs.com/testing/unit-testing-with-python/240165163
|
||||
|
||||
import inspect
|
||||
import optparse
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
localmodule = os.path.realpath(
|
||||
os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..'))
|
||||
print('localmodule: ' + localmodule)
|
||||
if localmodule not in sys.path:
|
||||
sys.path.insert(0, localmodule)
|
||||
|
||||
import fdroidserver.common
|
||||
import fdroidserver.exception
|
||||
|
||||
|
||||
class ExceptionTest(unittest.TestCase):
|
||||
'''fdroidserver/exception.py'''
|
||||
|
||||
def test_FDroidException(self):
|
||||
try:
|
||||
raise fdroidserver.exception.FDroidException()
|
||||
except fdroidserver.exception.FDroidException as e:
|
||||
str(e)
|
||||
|
||||
try:
|
||||
raise fdroidserver.exception.FDroidException(9)
|
||||
except fdroidserver.exception.FDroidException as e:
|
||||
str(e)
|
||||
|
||||
try:
|
||||
raise fdroidserver.exception.FDroidException(-123.12234)
|
||||
except fdroidserver.exception.FDroidException as e:
|
||||
str(e)
|
||||
|
||||
try:
|
||||
raise fdroidserver.exception.FDroidException("this is a string")
|
||||
except fdroidserver.exception.FDroidException as e:
|
||||
str(e)
|
||||
|
||||
try:
|
||||
raise fdroidserver.exception.FDroidException(['one', 'two', 'three'])
|
||||
except fdroidserver.exception.FDroidException as e:
|
||||
str(e)
|
||||
|
||||
try:
|
||||
raise fdroidserver.exception.FDroidException(('one', 'two', 'three'))
|
||||
except fdroidserver.exception.FDroidException as e:
|
||||
str(e)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = optparse.OptionParser()
|
||||
parser.add_option("-v", "--verbose", action="store_true", default=False,
|
||||
help="Spew out even more information than normal")
|
||||
(fdroidserver.exception.options, args) = parser.parse_args(['--verbose'])
|
||||
fdroidserver.common.options = fdroidserver.exception.options
|
||||
|
||||
newSuite = unittest.TestSuite()
|
||||
newSuite.addTest(unittest.makeSuite(ExceptionTest))
|
||||
unittest.main()
|
Loading…
Reference in New Issue
Block a user