TEST: Pass Or Fail!

turing_testThis is not concerned to any examination on test that a normal human take in his socially active and academically not so happening life. This is about the test which every code has to go through. Every line of code, each innocent variable , every conditional is a prime suspect of breaking the code unless and until they pass test to be precise enough unit test.

Every code is guilty , you have to assume that and then only you can write good test cases you have to think about every possibility that can break your code.

During Pycon DevSprint  2015 Kushal said something and that is what I am reminded of whenever I write test case , he said,

Test case which fails when your code is not there is the best test for the code you write.

I was introduce recently to unit test when recently I had to write test case for the feature I am writing for Pagure , you can check the previous articles for that.

Then coincidentally Kushal gave me and Trishna opportunity to write non-gating tests for fedora Atomic and cloud images. This intrigued me much, Tunir is basically a tool that Kushal wrote to automate the whole testing process for cloud images , you can read more about Tunir at Life of Tunir.

 

Well after that I began to explore more about unittest and wrote some test for Tunir , even you can volunteer for that check out the repo and Trishna’s Blog for more information.

Okay lets get our hands dirty and write some unit test :

This is very basic of unit test :

Step 1: Write this code in a file here  I am writing it in python_program.py :

 

Selection_008
File to be tested

Step 2: Now create a different file and name it test_python_program.py:

Selection_009
Test Cases

Selection_007
How it should run!

 

Now you can see the the output the way you should run the test in python. 

Try making self.assertEqual("Hey", out) 

and thou shalt pass!
If above changes are done the test will pass as assertEquals just compares out and "Hey". This is one of the simplest test that you can write and experiment with it. Hope that helps you.
Keep Testing!

git commit -m”Best Practices”

git commit -m”Best Practices”

All of us who use some kind of revision control system have this problem especially the one who are new to the whole git commit thing . Well the question I use to have what do I write what I just did and how can it be helpful to others.

I got all those question answered when I was working on moving my patch from master branch to feature branch. Pingou asked me to squash commits and make the commit message more reasonable.

Selection_005
Not so good way of writing a commit

Some of the references I used was Peter Hunter’s Blog and Chris Beam’s Blog. And I landed up with these seven rules .

The seven rules of a great git commit message

  1. Separate subject from body with a blank line
  2. Limit the subject line to 50 characters
  3. Capitalize the subject line
  4. Do not end the subject line with a period
  5. Use the imperative mood in the subject line
  6. Wrap the body at 72 characters
  7. Use the body to explain what and why vs. how

 

But for all the single commits which is doing a minor change you can still use git commit -m “your message”. ( Try to keep message in imperative mood)

Selection_006
A better way of writing commits

For bigger changes you need an editor so you might want to use a switch -a. For more details on how you can do that in pro git. Finally I am changing my habits of those shabby commit messages. So, think twice before you commit. 😉

Pagure Part 2

Pagure Part 2

Hey people, So I have been working on this project called pagure , I have briefed about that project in one of my earlier post.

I have been involved in writing this feature which facilitates the user and admin to edit comment on the pull request. Yeah! sounds so simple and straight forward . Wish it was that simple but it is not . Things I have to go through and things I learnt is really vast.

I experimented and kind got use to something called alembic which is a database migration tool. It gets really complicated if you don’t know how to use it. Alembic is basically used to update rather upgrade a pre-existing database.

I went through a lot of refactoring of code , managing code base placing code at the right place and then comes updating of git repo.

The funniest part of the whole experience is working with pingou and puiterwijk, well this is their IRC nicks, but these guys are crazy amazing . I get to learn a ton of things when puiterwijk reviews my code and he is surely a Japanese Robot 😉 and pingou is the one who keeps guiding me , motivating me .

Pingou says “Hitting the wall is just another step to find the door. The trick is don’t hit the wall so many times that it breaks your head that is the time you should ask for help”

It’s been really awesome working on the feature I am able to get the proper functioning of the feature but then there has to be much of improvement over it, there are various things that has to be integrated I am still working on them, hope this gets ready by next release.

Spreading the MozFire!

Spreading the MozFire!

My experience with Mozilla started with FSMK camp last year, for the first time I came to know that we can do something for Mozilla. I remember it was Galaxy and Abhiram that came in the camp and introduced us to the FOSS side of it.

I started looking for tutorials and stuff so that even I can start doing something for the community , at that time I was not that exposed to IRC so eventually I landed up bugging  Abhiram on how to contribute code he tried to help me a lot,

But not to any of our success , I still didn’t start contributing , I remember it was Viggy who told me to start looking into the code base and that rang a bell for me. No sooner did he tell me this than I began looking through the code and one week down the line I began working on a patch.

After a month it got accepted , I cannot put that happiness in words , form then to now I have been fixing bugs and looking into different issues.

Last week I got a chance to go on behalf of Mozilla and spread the word in PACE Mangalore. Mangalore has been all about Love, Food and Learning for me. Thank you Abhiram for giving us(Abraar and Me) this opportunity , I really loved the whole experience. Thank you Shreelaksmi Ma’m yoDSC_1770 (1)ur home and family is one of the best people I ever met.

PACE conducts this annual event called BytestrDSC_1773uck to encourage school kids towards FOSS and help them know more about technology which in my opinion is an amazing job. Event was really well organized. Abraar gave them a really nice intro and carried out the session brilliantly , I tried assisting him on doing all things well .
I would really like to thank the PACE team Praful, Sahil, Manisha, Rameez, John and all  others who all I didn’t mention you made my first visit to Mangalore memorable.

Peace out! And Keep Rocking the Open Web!

KICKSTARTERS

KICKSTARTERS

On 4th of this month we the Jnaapti team planned a small workshop to get 9th and 10th standard kids to get them started with programming . We visited Florence Public School and it was really a pleasant  experience to see such fresh minds exercising their mind.

I was really amazed to watch them apfps_kickstartersproach the problems we gave them, we have a rigid mind and we are really bad at thinking out of the box and that is because we have been taught rather conditioned to go in one direction.

But these kids they never knew this problem so they have a very different approach to these problem and I learnt about 7 new ways to approach the famous N-Queens problem.

Then came my favorite part “LABY”laby its a game which teaches programming in a fun way, so the whole idea is to make an ant to reach the door. There are various obstacles that needs to be handled and you know what you are going to use for that ?  CODE what else but its super fun to do that and we could see that in those kids. I learnt a lot that day like how will you explain conditionals , I am telling you it is not as easy as it looks.

Thanks to Gautham Sir, Shreelaksmi ma’m and Abraar for getting me this opportunity to do something this amazing , hope we will do more of such programs.