IMHO this is more readable:
self.assertEqual(retval, 0)
src/journald/test/TestIterators.py
(Diff revision 1)
|
|
|
64 |
iter_id = "LMI_JournalMessageLog_CMPI_Iter_9878972#0x7f8504021380#s=a13c10bf472048e69dceeee118cd7f84;i=3;b=5b96431d996a416ebf11dbb6543a5084;m=221f7b;t=4dcc1b6e70a7a;x=b1b572ade816b92e" |
Wow, I wonder whether this id is unique enough... :-D
IPv6 address sucks!
src/journald/test/TestIterators.py
(Diff revision 1)
|
|
|
65 |
try: |
|
|
66 |
self.wbemconnection.InvokeMethod(MethodName="CancelIteration", ObjectName=inst.path, IterationIdentifier=iter_id) |
|
|
67 |
raise AssertionError("Should not be reached") |
|
|
68 |
except pywbem.CIMError as e: |
|
|
69 |
self.assertTrue(e.args[0] == pywbem.CIM_ERR_INVALID_PARAMETER) |
unittest has means even for exception handling:
with self.assertRaises(pywbem.CIMError) as cm:
func(*args, **kwds)
self.assertEqual(pywbem.CIM_ERR_INVALID_PARAMETER, cm.exception.args[0])
And since this is a common use case in your test, you may save a lot by defining this method:
def assertRaisesCIM(self, cim_err_code, func, *args, **kwds):
"""
This test passes if given function called with supplied arguements
raises pywbem.CIMError with given cim error code.
"""
with self.assertRaises(pywbem.CIMError) as cm:
func(*args, **kwds)
self.assertEqual(cim_err_code, cm.exception.args[0])
resulting in:
self.assertRaisesCIM(pywbem.CIM_ERR_INVALID_PARAMETER,
self.wbemconnection.InvokeMethod,
MethodName="CancelIteration",
ObjectName=inst.path,
IterationIdentifier=rfirst['IterationIdentifier'])
I know it's a bit more code, but makes it usable elsewhere:
url = os.environ.get('LMI_CIMOM_URL', 'localhost')
username = os.environ.get('LMI_CIMOM_USERNAME', "pegasus")
password = os.environ.get('LMI_CIMOM_PASSWORD', "heslo")
c = connect(url, username, password)
- Michal Minar
On September 10th, 2013, 2:32 p.m. UTC, Tomáš Bžatek wrote:
Review request for OpenLMI Developers.
By Tomáš Bžatek.
Updated Sept. 10, 2013, 2:32 p.m.
Repository:
openlmi-providers
Description
journald: Add iterator tests
Tests basic iterator operations, assumes accessible journal and several (> 10)
records available.
Also comes with a simple example script for downloading complete journal.
--
This is the largest chunk of Python code I've ever written! \o/
|
Diffs
- src/journald/test/TestIterators.py (PRE-CREATION)
- src/journald/test/list-journal (PRE-CREATION)
View Diff
|