April Fedora Meetup, Pune

The Fedora meetup was conducted by Kushal Das on 23rd April 2016. Around 15 people attended the meetup at Kushal’s place.

In this meetup, Kushal introduced us to Unit Testing. Its a term often heard in Software development.



Testing is done to determine if there are errors in the code. It does not prove that the code is correct but it just checks that the conditions are handled correctly. Tests are as important as implementation itself.


Unit testing

Unit testing is done to evaluate a particular code component. These components can be function , class etc. It determines how well the component reacts to valid or invalid input.  Unit tests are written and executed by software developers.


unittest – an automated testing framework in Python

I installed the unittest module on my Fedora machine using:

pip install unittest

I used unittest module in my python program using:

import unittest


Basic Test Structure

There are two parts of a basic test:

  1. The code to prepare for test (test fixture)
  2. The code to test


Our first Test Case

This program tests cat command in Fedora. The cat command is used to read the contents of a file. We use the cat command in the following way:

Screenshot from 2016-04-25 14-47-30.png

This following program is the first test case. It prints:

  • the output of cat command
  • the error
  • the exit code



I saved the script with the name “firetest.py”. The simply ran the script directly from the command line:

Screenshot from 2016-04-25 15-05-45

The above result shows:

  • The output of cat command.
  • The command ran successfully so error message is empty
  • exit code is “0”(successfully completed)

After that, there is a “.” before the dashed line above which indicates that the test passed.

Next, it shows the amount of time the tests took.

After that, the test outcome i.e. OK is shown.

Every test has 3 possible outcomes:

  • OK: the test passes
  • FAILED: the test doesnot pass  and raises “AssertionError” exception
  • ERROR: the test raises error other than “AssertionError”

Now, i did modification to the above program and changed the file name to something else i.e. gave a wrong file name and then ran the script. This is the result:

Screenshot from 2016-04-25 15-18-16

Here, since the file name is wrong, the cat command throws an error. The output is empty. The error message is displayed along with the exit code “1”(unsuccessful completion).

Kushal told us that the “b” before the output and error message indicates that it is in “bytes”.

To convert the output in string, we inserted the following line before print statement:

Screenshot from 2016-04-25 15-23-47



Assert statement is used for verifying expectations or some property of code being tested is true. Assert literally means “to state as fact”.

Assert statement stops the routine and sends the error message.

There are many assert statements like:

  • assertEqual
  • assertNotEqual
  • assertTrue
  • assertFalse
  • assertIn
  • assertNotIn
  • assertIs
  • assertIsNot

In the meetup, we tried “assertIn”. assertIn(a, b) checks if a is in b.

This following is the code modification that we made. Here, the assertIn checks if the word “fedora” is present in the output.

Screenshot from 2016-04-25 15-54-57.png

This is the result:

Screenshot from 2016-04-25 15-56-31

This means that the string “Fedora” is present in the output of cat command.

We modified the string “Fedora” to generate an error in this way:

Screenshot from 2016-04-25 15-58-45

After running the script, this is the result:

Screenshot from 2016-04-25 15-59-57.png

The test fails as the string “Fedra” is not present in the output.

Kushal, Chandan Kumar and Praveen Kumar gave all of us a simple task of testing.

My task was to:

  • change a file’s SELinux permissions to root (not through mode)
  • Write a test case to check if it gives an error when i try to access it through normal user sudo chmod 700
  • Check if the error message is present in the SELinux’s log file.


In this meetup i learnt about unit testing in Python; also I learnt about SELinux for the first time while solving the task.

Thanks to Kushal for providing the yummy snacks 🙂 and conducting the meetup.

April Fedora Meetup, Pune

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s