Python

Assertion

The proper use of assertions is to inform developers about unrecoverable errors in a program. Assertions are not intended to signal expected error conditions. Assertions are meant to be internal self-checks for your program.

2022-12-03

Effective Python Testing With Pytest

What Makes pytest So Useful? With pytest, common tasks require less code and advanced tasks can be achieved through a variety of time-saving commands and plugins. It’ll even run your existing tests out of the box, including those written with unittest.

2022-12-02

Getting Started with Python Testing

Testing Your Code Automated vs. Manual Testing Exploratory testing A form of testing that is done without a plan. You’re just exploring the application. To have a complete set of manual tests, all you need to do is make a list of all the features your application has, the different types of input it can accept, and the expected results.

2022-12-02

Testing

2022-12-02

Magic Method

I came across an error with incaution when using the round() function: def get_discount_price(ori_price, discount): discount_price = ori_price * (1 - discount) # forget to return `discount_price` >>> round(get_discount_price(50, 0.2)) --------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-2-abb2b34126d0> in <module> ----> 1 round(get_discount_price(50, 0.

2022-11-20

Issue & Solution

Issues as well as problems encountered during Python development and their solutions.

2022-11-20

Decorator: Advance

In Decorator: Basics, we have seen the basics of decorators. import functools def decorator(func): @functools.wraps(func) def wrapper_decorator(*args, **kwargs): # Do something before value = func(*args, **kwargs) # Do something after return value return wrapper_decorator The key is to remember the following two expressions are equivalent (the latter uses the syntactic sugar):

2022-05-23

Decorator: Basics

TL;DR Decorators define reusable building blocks you can apply to a callable to modify its behavior without permanently modifying the callable itself. The @ syntax is just a shorthand (syntax sugar) for calling the decorator on an input function.

2022-05-21

Operator Overloading

In Python, methods with __ (double underscore) prefix and suffix (e.g., __init__()) are special methods.They are called magic methods or dunder methods (dunder for “double underscore”). They can help override functionality for built-in functions for custom classes.

2022-05-04

OOP Basics

The concept of OOP in Python focuses on creating reusable code. This concept is also known as DRY (Don’t Repeat Yourself). Class A class is a blueprint for the object.

2022-05-04