Skip to content

Instantly share code, notes, and snippets.

View okken's full-sized avatar

Brian Okken okken

View GitHub Profile
@okken
okken / test_dedent.py
Last active December 8, 2021 19:26
textwrap.dedent for testing example
from textwrap import dedent
def multiline_hello_world():
print("hello")
print(" world")
def test_multiline_hello_world(capsys):
expected = dedent('''\
hello
world
# stick this in .bashrc or .zshrc
# create, activate, exit
function create {
if [[ $# -gt 0 ]]
then
virtualenv -p py39 venv -q --prompt "($1) "
else
virtualenv -p py39 venv -q
fi
@okken
okken / mcd.bash
Last active October 10, 2020 05:17
mcd: menu driven cd (intended for .bashrc)
# mcd: menu driven cd (intended for .bashrc)
function mcd {
PS3="Which directory: "
select d in '/some/common/path/i/use/'\
'/another/common/path/'\
'/and/so/forth/'
do
cd $d
break
@okken
okken / goes_in_bashrc_for_venv_use_windows.bash
Last active June 26, 2019 13:40
venv activate/exit (windows version)
# create virtual environment
#
function create {
echo "\ncreating virtual environment"
python -m venv venv --prompt ${PWD##*/}
echo "upgrading pip"
venv/Scripts/python.exe -m pip install -U pip
if [ -f requirements.txt ]
then
echo "installing dependencies from requirements.txt"
@okken
okken / test_fib.py
Created April 22, 2018 15:13
alternate test for fibonacci
import pytest
from main import fibonacci
@pytest.mark.parametrize('n, expected',
enumerate([1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144]))
def test_returns_correct_fibonacci_number(n, expected):
assert expected == fibonacci(n)
def test_raise_value_error_on_negative_input():
@okken
okken / conftest.py
Created November 14, 2017 20:13
"fixes" duration reports in both PyCharm and pytest-html
# report call duration as both setup and call duration
# "fixes" duration reports in both PyCharm and pytest-html
_node_times = {}
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_logreport(report):
if report.when == 'setup':
_node_times[report.nodeid] = report.duration
if report.when == 'call':
report.duration = report.duration + _node_times[report.nodeid]
@okken
okken / test_ids.py
Created August 23, 2016 22:32
pytest paramterized ids cannot be integers. They could in 2.9.2
mport pytest
# -----------------------------------------
# To Demonstrate numerical ids not working
# -----------------------------------------
testdata = [( 1, 2), ( 2, 4)]
@okken
okken / output session
Last active December 5, 2019 11:32
pytest parameterized ids function differences between fixtures and functions/classes
(venv) $ pytest -v test_ids.py
============================= test session starts ==============================
platform darwin -- Python 3.5.2, pytest-3.0.0, py-1.4.31, pluggy-0.3.1 -- /Users/okken/projects/book/bopytest/Book/venv/bin/python3.5
cachedir: ../.cache
rootdir: /Users/okken/projects/book/bopytest/Book/code/pytest/um_project, inifile:
collected 8 items
test_ids.py::test_ids_strings[a] PASSED
test_ids.py::test_ids_strings[b] PASSED
test_ids.py::test_ids_paramterized_function[<1>-<2>] PASSED
@okken
okken / output session
Created August 23, 2016 22:28
pytest parameterized ids function differences between fixtures and functions/classes
(venv) $ pytest -v test_ids.py
============================= test session starts ==============================
platform darwin -- Python 3.5.2, pytest-3.0.0, py-1.4.31, pluggy-0.3.1 -- /Users/okken/projects/book/bopytest/Book/venv/bin/python3.5
cachedir: ../.cache
rootdir: /Users/okken/projects/book/bopytest/Book/code/pytest/um_project, inifile:
collected 8 items
test_ids.py::test_ids_strings[a] PASSED
test_ids.py::test_ids_strings[b] PASSED
test_ids.py::test_ids_paramterized_function[<1>-<2>] PASSED