This file contains 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
git_branch() { | |
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/' | |
} | |
export PS1="\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\[\033[00;33m\]\$(git_branch)\[\033[00m\]\$ " | |
alias g='git' | |
source /usr/share/bash-completion/completions/git | |
complete -o default -o nospace -F _git g |
This file contains 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
pipenv -h | |
pipenv install | |
pipenv --python3.7 | |
pipenv shell | |
pipenv install --dev sphinx | |
pipenv install --dev sphinx --skip-lock |
This file contains 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 time | |
import logging | |
import sqlite3 | |
import pytest | |
logger = logging.getLogger("ExampleDBClient") | |
RECONNECT_SLEEP = 30 | |
RECONNECT_ATTEMPTS = 3 |
This file contains 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
""" | |
Testing that your program respond as expected in negative situations is very important. | |
These tests exemplify how to check that some code raises the right Exception. | |
""" | |
# TODO BreakingPoint exception | |
import pytest | |
def raise_exception(): |
This file contains 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
num_list = [] | |
def add_num(num): | |
num_list.append(num) | |
return True |
This file contains 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
""" | |
This example has not been tested. Use it as a reference only. | |
""" | |
import psycopg2 | |
import pytest | |
USER = "postgres" | |
PASS = None |
This file contains 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
# -*- coding: utf-8 -*- | |
import random | |
import string | |
import unicodedata | |
from uuid import uuid4 | |
from functools import partial | |
from _datetime import datetime, timezone | |
from factory import Factory, Sequence, LazyFunction as LF, LazyAttribute as LA | |
from factory.fuzzy import FuzzyChoice as Choice |
This file contains 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
""" | |
A typical mock case is changing the output of time, date and datetime methods. | |
You may be tempted to make a time.sleep of N seconds. That's wasting your time. | |
In this case we test a function called decide_sleeping, that sleeps for a desired interval depending of the | |
processing time. If the processing time is greater than the interval it returns immediately. | |
This is useful for busy waiting loops. | |
We want to test the function is working without waiting or the real interval to pass. | |
In this case we mock both time.time (to return what we want) and time.sleep, to avoid waiting. |
This file contains 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
""" | |
Parametrize allows you to run the same test with different inputs and expectations. | |
Each input will result in a separated test. | |
As first parameter of the mark, you name the variables in a string, separated by commas. | |
As second parameter, you input an iterable (a list) with tuples of the values of each case variables. | |
""" | |
import pytest | |
This file contains 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 os | |
import time | |
import pytest | |
ENV_VAR_NAME = "DUMMY_VAR" | |
os.environ["CUSTOM_VAR"] = "Unchanged" | |
my_dict = {"a": 11, "b": 22} |