I just installed WordPress for Android in my HTC Sensation. This is a test post from my phone.
Posted from WordPress for Android
I just installed WordPress for Android in my HTC Sensation. This is a test post from my phone.
Posted from WordPress for Android
Coverage.py is a tool for measuring code coverage of Python programs. It monitors your program, noting which parts of the code have been executed, then analyzes the source to identify code that could have been executed but was not.
Coverage measurement is typically used to gauge the effectiveness of tests. It can show which parts of your code are being exercised by tests, and which are not.
Getting started:
1. Install coverage:
2. Use coverage to run your program and gather data:
$ coverage run my_program.py arg1 arg2
blah blah ..your program's output.. blah blah
3. Generate reports with coverage:
$coverage -rm
Name Stmts Miss Cover Missing
-------------------------------------------------------
my_program 20 4 80% 33-35, 39
my_other_module 56 6 89% 17-23
-------------------------------------------------------
TOTAL 76 10 87%
4. You can also use coverage to generate reports in other presentation oriented formats like HTML:
$coverage html
You can also use coverage.py with Django. You can run your Django tests along with coverage to check which codes in your app have been tested by your tests. With the coverage data, you can write new tests to test the codes which have not been tested so far by your tests. For example:
You can also write custom Test Runners using the coverage API to measure code coverage in a more controlled manner. You can find more detailed documentation about coverage here.
Here is a good tutorial to start Django development server with HTTPS using stunnel.
Lotte is the component of Transifex providing the web UI for the translators to translate online. Well, some time back, I made some changes in the Lotte code so that it has the auto-save feature on by default. It was running fine then and I was happy. Then I added the spellcheck feature in Lotte. Then the things started going not as expected.
Actually, the auto-save triggers when the contents of a text area has been edited and it loses focus. The first problem I faced is that the spellcheck button did not respond on the first click, but on the second. As expected, on the first click, auto-save was triggered. But this was not the case when I clicked the Undo button. First the auto-save and then the undo function would be executed. I was not able to come up with an answer to explain this. I was tinkering with the code and then accidentally I solved the problem. I just changed the order of the buttons. Initially I had – Spellcheck button , Save Button and Undo Button. Now, I have – Save button, Spellcheck button, Undo button. Weird! You can have a look at the change at https://bitbucket.org/rtnpro/transifex/changeset/b59880cadf67 . If you have an explanation for this, please comment.
One problem gets fixed and another comes to your mind. The auto-save function was being an overhead. The function would be triggered even if I press the spellcheck button, auto translate and copy source buttons in the same row. I am still editing the same string! The way it should be is that it should trigger when I am finished with editing the string.
So, what I did is that I moved the code saving the string from the function being called by the blur event of the textarea to a new function. Whenever a textarea being edited receives the blur event, I save the edited string, its id and a must_push flag for future use. Now, whenever any other textarea receives focus, depending on the must_push flag, the string save function is called. This was just one part of the problem I fixed. Now, I have to deal with the click events that might take place in various parts of the page and it should save the edited string from the textarea that just lost focus. My save function is already ready and it deals with the required checks on whether to save or not. I just need to call the new save function. I just browsed through the html tree, found a list of elements and bound their click event to the save function. As for the table rows, I bound the click event of all the rows other than the current row to the save function. Here is the commit implementing the new auto-save feature : https://bitbucket.org/rtnpro/transifex/changeset/5a7c2a2e13ea . I had quite some jquery drill to fix these issues
.
Well, now Lotte with new auto-save feature is ready. Nice and elegant. I hope it makes up to the expectations of the translators. That’s what people strive at Transifex.
Just writing tests for your Django codebase is not enough. You need to check how much of the code is covered in your tests. For this, there are some tools available. Again, it is not just the number of lines of code tested that matters. What matters is “Are these lines important?”. Well, for this, we have to use our head.
covergae is a tool for checking test coverage of python applications. django-test-coverage was built on top of coverage.py to meet requirements of django tests.
I was able to plugin django-test-coverage in Transifex. For some test cases it ran, for others, it failed. It raised a warning saying that a module was being imported more than once. But, the stats generated by it were misleading. Except for files with 0 lines of code (like __init__.py), it showed code coverage % as 0 and 100 only for the files having 0 line of code. I hacked into its code and was able to run it for cases where it had failed previously. But still the statistics were misleading. Time was running out. So, I decided that I would revisit its code some time later.
I resorted to use coverage.py. You can find an introduction about coverage.py at here. Using coverage boils down to 3 steps:
If the test module is large, the report generated by coverage is also large. I usually save the report to a file : $coverage -r -m > report.txt. Now, I can use grep to shortlist the report to see the details of the files which concerns me now. That’s pretty easy.
coverage.py gives you very useful informations like percentage code coverage of a file, missing statements, etc. Although a higher percentage code coverage is better, but the importance of the lines also matters a lot. You could increase the code coverage by including 10 not so important lines rather than including 1 important line. So, code coverage statistics helps us to write tests to cover more codes, but it is not a replacement to thinking. The final judgement is to be done by us.
Last week, I have been working on fixing the existing unittests for Transifex. The Transifex codebase is constantly being updated. So, some of the previous test cases failed. Before this, I had already written a unittest or two for some of the codes that I contributed to Transifex. But I did not study the Django unittest framework deeply for that.
This time, it was different. I took my time to go through the Django documentation on testing. And then I started to work on fixing the existing tests. To avoid confusion, I ran test on each component separately. Only a few were containing errors like projects, lotte, release, resources, projects, txcommon, suggestions, charts, etc.
I started working on one component at a time. After fixing it, I committed and pushed my changes. Then I proceeded to the next one. In between, I was always in touch with diegobz, kbairak, messas. They helped a lot. I once ran into a bug due to haystack module. I reported this to diegobz. He fixed the issue with haystack quickly.
There was another instance when a particular test was showing errors in my box but not for anyone else. I struggled with it for sometime. Then, kbairak told me that the Transifex code is now compatible with Django-1.2.5, but will become compatible with Django-1.3 soon. And here I was running Django-1.3. kbairak fixed some code to make it compatible with Django-1.3.
The Transifex upstream ROCKS!!!
Well, it has been quite some time since my last blog. The last days of my college, yes, they were very hectic. I had to complete my college project. Well, I had to handle a couple of preventions and seminars, mostly by myself ( although in a group). I finally implemented scatternet formation and routing and built a relay chat kind of thing on top of that. I named it Bluetooth Relay Chat. It worked quite, except for the interface not being that WOW. One can send public messages and private messages as well. I am maintaining the code as a private project in bitbucket. I will release the code soon.
Apart from that, I have been working on Transifex and fixed and improved some stuffs in between. I could not control the urge to contribute even when my exams were near. Apart from that, I have been working on another tool called wordcollections for Ankur Bangla project. It began as a fork of wordgroupz but now is going in a completely new direction.
I was finally happy the day our final semester exams were over. Finally, I can devote my entire day to open source. I stared working on Transifex from the next day. And from June 1, began my internship at Indifex. Currently, I am working on fixing the unittests. I am almost done with the fixing part. Now time to move to write new unittests.
For some days, I was not able to login to trac.transifex.org. I though that it might be a browser issue. So, I deleted the browser data and tried to login using firefox, opera and google-chrome, but I still couldn’t login.
Then, I established an ssh tunnel from my computer to a remote server and set up proxy settings in my browser to use the ssh tunnel. And now, I can login correctly. This shows that it is not a browser issue but a connection issue.
I think something is terribly wrong with BSNL 3G servers and their maintainers.
Similarly, koji-client does not work over BSNL 3G. I have been tired complaining to the BSNL 3G Customer Care about this issue. But they don’t understand the issue only and issue is never solved.
For some days, I have been working like anything for my final semester project in college, because I have to. I have also some tasks to do for transifex. When will the college be over?
But I have to find some time, anyhow.
From last week, I have not been feeling good. I was getting tired very quickly, even from a small walk. And now I have taken to bed. I am now eating only boiled food. I will be leaving for home as soon as possible. I will get quick recovery under mother’s care.