What was Wrong
While writing unittests I went off-track. Thankfully, mithro guided me at correct time. Two major wrong things I was doing were:
- For testing purposes, to each and every function in my code I was adding input validation statements, so that I did not get any TypeError or ValueError while running it. Instead of doing this, I should have made exception handlers. So my last few commits were not useful at all and I had to remove them.
- I was using setters and getters in my code. I had added them to give extra abstraction to the user. However, I learnt that in python these are seldom used. So, I had to remove these lines from the code.
Commits:
A rather long list of commits:
- exceptions for run, terminate and kill: af1bd7c8645b82fd2a725655fd6905709d6d8d45
- exceptions for run, terminate and kill: 51dada1c0b16e8e3fd90eb7a967fb583b87d76f8
- Exception handling for Server.run and py.tests: 8807d07c2d98d5d39b8a0c22eabfc77b619369e1
- exception handling for server process creation: 832e0cb1948c601faa20292b6883a4d4d12bb1dc
- added exception for subprocess: 8ef1346d40822b47e3cba16fd42848843a265783
- gst-option added and updated connection.py: 9f8434cb9f06a25d6f9e3fec22a04289d2ba458e
- Removed wrong unittests: 269d307d5edd1b6d621457038b9148152bf14e12
- Made helpers.py and testsource.py pythonic: 18608b8702826279711ed9d749f435b4340607ee
- Made server.py pythonic: abecf31fb2d429a84288026008e44feae3e8640c
- Made connection.py pythonic and removed dbus.py: 2c7c7c03b527885c6bc0043dd73a0aeb7d29444d
- Made connection.py pythonic and removed dbus.py: 82cd61beadbd499f9424409c218bcae5b4840217
- fixed typo: e11aaea2b080d63f55a95b682593d4e6c50c1606
- Fixed problems: 48e1742478627741b7c6def34ab2c2f972609b82
Exception Handling
From above experience I learnt that I had to put exception handlers in my code. I had very little knowledge of exception handlers and absolutely no experience.
Some good links that I found were very useful in the field of exception handling and testing:
- http://pythontesting.net/framework/pytest/pytest-introduction : This page nicely explains how to use py.test.
- http://www.itmaybeahack.com/book/python-2.6/html/p02/p02c07_exceptions.html: A very long and very good page which explains exception handling to its core.
- http://stackoverflow.com/questions/6180185/custom-python-exceptions-with-error-codes-and-error-messages: Nicely explains how to create custom exception classes
- http://blog.ianbicking.org/2007/09/12/re-raising-exceptions/: Nicely explains how to raise and re-raise exceptions in python
After spending lots of time on reading exception handling in python, I made a few changes to the code, where I defined some custom Exceptions like PathError: Raised when a wrong path is specified to the run the gst-switch-srv process. Another one is ServerProcessError: Raised when something wrong happens with the process running like a OSError indicating some internal fault.
Things to do..
Add exception handling for all modules and write py.test testing modules for testing them
Comments Section
Feel free to comment on the post but keep it clean and on topic.
blog comments powered by Disqus