Python: Data driven testing

I love doing TDD – Test driven development.

Sharing a small code construct to include variety of data set in a concise manner without depending on any library

def double(n):
    return n*2

test_data = [
    (2 ,4),
    (4 ,8),

for given, expected in test_data:
    assert expected == double(given)
    print(f"Test passed for: given {given} and expected = {expected}")

Output on console
Test passed for: given 2 and expectation = 4
Test passed for: given 4 and expectation = 8

How to sort custom objects in Type Script

Imagine you have a student class and you need to sort it reverse order of marks field to calculate ranks of students in the class.

class Student{
    constructor(name:string, marks:number) { = name
        this.marks = marks

Student objects as part of the array. 

var students:Array<Student> = [
    new Student("aseem",47),
    new Student("prem",97),
    new Student("john",100)


sort students by comparing them based on marks field. 

console.log(students.sort( (a,b)=> a.marks > b.marks ? -1:1 ))

here, we used the arrow function which takes a and b objects as params, then we used the ternary operator to compare marks and return the number as -1 or 1 as the result of comparison. 

Is semicolon needed in Java Script? horror of ;

Short answer is NO in recent times, here is why
The semicolon is used to separate statements, but it can be omitted if the statement is followed by a line break.
The semicolon is needed, only when you have two or more statements on the same line, not other wise 🙂 

    var i = 0; i++        // <-- semicolon obligatory
                          //     (but optional before newline)
    var i = 0             // <-- semicolon optional
        i++               // <-- semicolon optional

Python script to take mongodb backup

@Author: Aseem Jain

import os
import pymongo

# configure credentials / db name
db_user = os.environ["MONGO_ATLAS_USER"]
db_pass = os.environ["MONGO_ATLAS_PASSWORD"]
db_name = "sample_mflix"

connection_string = f"mongodb+srv://{db_user}:{db_pass}{db_name}?retryWrites=true&w=majority"

client = pymongo.MongoClient(connection_string)
db = client[db_name]

# create database back directory with db_name
os.makedirs(db_name, exist_ok=True)

# list all tables in database
tables = db.list_collection_names()

# dump all tables in db
for table in tables:
print("exporting data for table", table )
data = list(db[table].find())
# write data in json file
with open(f"{}/{table}.json","w") as writer:


User defined custom object sorting in python

@Author: Aseem Jain

Title: Sort the class or custom object and not regular int / string using in build sort funcitons
Sort custom object can be done in 2 ways
1. Static way : class implementing < less then __lt__(self,other)
2. Dynamic way is by providing lambda func with key.
class User:
def __init__(self,name,age): = name
self.age = age

def __repr__(self):
return + str(self.age)

def __lt__(self, other):
return self.age < other.age

# Sorting String
ls = ["zeema", "aseemjain", "see",str(3),str(13),"$$"]
#output: ['$$', '3', 'aseemjain', 'see', 'zeema']

# Reverse soring
# output: ['zeema', 'see', 'aseemjain', '3', '$$']

# sorting Custom object
users = [User("aseem",16),User("aseemprem",56),User("premaseem",23),User("zseem",36),User("nseem",106) ]
users.sort(key = lambda x:
# output : [aseem16, aseemprem56, nseem106, premaseem23, zseem36]

# create new sorted list
newlist = sorted(users, key=lambda x: x.age, reverse=True)
# output: [nseem106, aseemprem56, zseem36, premaseem23, aseem16]

Github link:

Yoga Instructor Certificate

I am now a certified Yoga Teacher, thanks to Sri Sri Yoga, a certified school under the Ministry of AYUSH, Govt. of India & Yoga Alliance Registered Yoga School. I scored 97% marks in exams.

It was a 200 hour, 8 weeks online Yoga teachers training program. I was able to lose extra weight from my body and mind ( ie stress / Chitta Vritattis / Vikalpa) and got an entirely new way of life. All my digestion related issues are gone. I feel calmer throughout the day. Learned so much about my own body ( muscles, bone, ligaments, tendons ) and mind (modulations, stresses, obstacles).

After finishing the training, I realized why the entire world is learning and practicing yoga to maintain their mental and physical health.

If you’re interested in learning, how Yoga can help you, feel free to contact me.

My online yoga studio link:

My Facebook yoga page:

My youtube channel link:

With love,
Prem Aseem Jain

Wish you Happy New Year 2021

I wish you all a happy and healthy new year 2021.

Tell me what do you feel about 2020 in the comments.

2020 wasn’t bad for me, it was just different and taught us a lot especially how to leverage technology to connect and get the job done.

I used 2020 to go within myself

I felt a deeper connection with family members in 2020.

I also finished another programming certification in 2020.

I finish Sri sri yoga teachers training program, which helped me get rid of extra weight on the body and stress on the mind.

I did several Art of living meditation programs

I hope 2021 would come with freedom without restriction to wear masks 😉

#newyear2020 #programming #yoga #mentalhealthmatters #premaseem

Certificate – PCAP – Certified Associate in Python Programming

I have been programming in python since last 5 to 8 years. I have cleared he exam with 92%.

I have uploaded the PCAP mock exams on my youtube channel: 

Python PCAM Mock Practice Exams I practiced before my exam:

My top 5 Clifton Strengths

Strengths, Not Skills, Are the Difference Makers for Winning Teams,

Here are my top 5 strengths.

1. Adaptability – I tend to be a “now” person and Able to switch my mind and focus based on priority. 

2. Positivity- I have infectious energy and enthusiasm to motivate and inspire my team. 

3. Connectedness – I build bridges between people and groups.

4. Developer – I encouragement helps others learn, grow and improve.

5. Input – My strength to collect and organize knowledge empowers me to make credible and well-informed decisions for my team.