- Test should not leave the function context. ** Most important **
- Test should verify the calls to methods / functions with side effects
- Test should have descriptive names ( alterative to this is BDD )
- Function and methods should only get the inputs that are essential to test functionality.
- Test should be per function / method not per module / class. ( You can couple tests based on functionality )
- Test should focus on branch coverage than LOC.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import PIL.Image | |
import os | |
def getCameraModel(image_name): | |
# 272 is key for camera model | |
try: | |
camera_model = PIL.Image.open(image_name)._getexif()[272] | |
except: | |
camera_model = None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SlugifyMixin: | |
slug_source_field = None | |
slug_target_field = None | |
def __init__(self, *args, **kwargs): | |
assert self.slug_source_field is not None, 'slug_source_field is required' | |
assert self.slug_target_field is not None, 'slug_target_field is required' | |
super().__init__(*args, **kwargs) | |
def save(self, *args, **kwargs): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Tic Tac Toe | |
from typing import Optional, Tuple | |
import uuid | |
import random | |
Move = Tuple[int, int] | |
class Stats: |