Automated testing using unittest

Ref. from :
unittest is a testing framework for Python. It supports :
1. Test automation
2. Sharing of setup and shutdown code for tests
3. Aggregation of tests into collections
4. Independence of tests from the reporting framework

To implement the above mentioned functionalities, it supports some OOP based concepts:

  1. test fixture : It is something like initializing and loading all variables(everything needed) before running the real logic for testing.
  2. test case : Here we generally hard code responses for particular critical test cases.
  3. test suite : It’s a collection of various test cases and test suites.
  4. test runner : It decides the execution order during testing, interface for the user and format of output to be generated after the testing is completed.

My notes on extending Python with C/C++

  1. Without third party tools : Using C and C++
  2. With third party tools:
    1. Cython
    2. cffi
    3. SWIG
    4. Numba

Extending Python with C or C++:

Prerequisites :

  1. Programming in C
  2. Basic knowledge of Python

Functions performed by extension modules in C and C++:

  1. Implement new built-in object types
  2. Can call C library functions and system calls

All user visible entities are defined by “Python.h” have prefix Py or PY. “Python.h” imports stdio.h, string.h, errno.h and stdlib.h automatically.

static PyObject * spam_system( PyObject * self, PyObject * args )
    const char * command;
    int sts;

    if(!PyArg_ParseTuple(args, "s", &command))
       return NULL;

    sts = system(command)
    return PyLong_FromLong(sts);

Here PyArg_ParseTuple() <-- checks the argument types and converts them to C values.
It returns True if arguments are of right type (nonzero), otherwise return False(zero)
if arguments list is invalid.