Skip to content

Instantly share code, notes, and snippets.

@ksamuel
Created October 6, 2018 09:43
Show Gist options
  • Save ksamuel/43f273bc2fd7d99e1642fd4c3cbfdb97 to your computer and use it in GitHub Desktop.
Save ksamuel/43f273bc2fd7d99e1642fd4c3cbfdb97 to your computer and use it in GitHub Desktop.
Sculpter une fonction: les tests
from formatter import afficher, formater, produire
def test_afficher():
assert afficher([1, 2, 3]) == "- 1\n- 2\n- 3"
assert afficher([1, 2, 3], prefix="*") == "* 1\n* 2\n* 3"
assert afficher([1, 2, 3], template="{element} {prefix}") == "1 -\n2 -\n3 -"
assert afficher([1, 2, 3], formateur=lambda e, p, t: "bla") == "bla\nbla\nbla"
def test_formater():
assert formater(1, "*", "[{prefix}] {element}") == "[*] 1"
def test_produire():
assert list(produire([1, 2, 3])) == ["- 1", "- 2", "- 3"]
assert list(produire([1, 2, 3], prefix="*")) == ["* 1", "* 2", "* 3"]
assert list(produire([1, 2, 3], template="{element} {prefix}")) == [
"1 -",
"2 -",
"3 -",
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment