raw_amount = " 1250 "
amount_cents = int(raw_amount.strip())
missing = None
assert amount_cents == 1250
assert type(True) is not int
assert missing is None
print(type(amount_cents).__name__)


lignes_recues = 120
lignes_recues = lignes_recues + 5
double = lignes_recues * 2
lignes_recues = 0
assert double == 250 and lignes_recues == 0
assert type(12) is int and type(12.5) is float

import keyword
assert keyword.iskeyword("for") and keyword.iskeyword("True")
assert not keyword.iskeyword("true")

nom_source = 'l\'entrepôt'
chemin_lot = "C:\\donnees\\lot.csv"
assert nom_source == "l'entrepôt"
assert chemin_lot.count("\\") == 2


entrepot = "l'entrepôt"
lignes = '''premier lot
deuxième lot'''
assert entrepot.startswith("l'")
assert lignes.splitlines() == ["premier lot", "deuxième lot"]
recu = 5
recu += 1
ancien, nouveau = "lot-1", "lot-2"
ancien, nouveau = nouveau, ancien
assert recu == 6 and (ancien, nouveau) == ("lot-2", "lot-1")
assert type("lot") is str and len("lot") == 3

import keyword

lignes_recues = 120
ancien_total = lignes_recues
lignes_recues = lignes_recues + 5
double_lignes = lignes_recues * 2
assert (ancien_total, lignes_recues, double_lignes) == (120, 125, 250)
assert "lot_2".isidentifier() and not keyword.iskeyword("lot_2")
assert not "2_lot".isidentifier()
assert "if".isidentifier() and keyword.iskeyword("if")
assert "True" in keyword.kwlist and not keyword.iskeyword("true")
assert keyword.issoftkeyword("match") and not keyword.iskeyword("match")
match = "lot-2026"
assert match == "lot-2026"

assert type(52.0) is float and type(52) is int
message_source = "capteur nord" + "-A"
assert message_source == "capteur nord-A" and "lot" * 2 == "lotlot"
message_lignes = "nord\nsud"
assert len(message_lignes.splitlines()) == 2
assert repr(message_lignes) == "'nord\\nsud'"
rejets = traites = 0
traites += 1
assert (traites, rejets) == (1, 0)
source = []
autre_nom = source
source.append("lot-1")
assert autre_nom == ["lot-1"]

lots = ["A"]
alias_lots = lots
lots += ["B"]
assert lots is alias_lots and alias_lots == ["A", "B"]
lots = lots + ["C"]
assert lots == ["A", "B", "C"]
assert alias_lots == ["A", "B"] and lots is not alias_lots

from contextlib import redirect_stdout
from io import StringIO

message_lot = "Nord\nSud"
sortie_message = StringIO()
with redirect_stdout(sortie_message):
    print(message_lot)
assert repr(message_lot) == "'Nord\\nSud'"
assert sortie_message.getvalue() == "Nord\nSud\n"

# Une expression sur plusieurs lignes reste un seul calcul.
total_lignes = (
    120
    + 35
    - 8
)
total_avec_antislash = 120 + 35 \
    - 8
assert total_lignes == total_avec_antislash == 147

recus, rejetes = 6, 2
sortie_compteurs = StringIO()
with redirect_stdout(sortie_compteurs):
    print("reçus =", recus, "rejets =", rejetes)
assert sortie_compteurs.getvalue() == "reçus = 6 rejets = 2\n"

assert 3 * 2 == 6
assert "lot-" * 3 == "lot-lot-lot-"
try:
    "lot-" * 1.5
except TypeError:
    pass
else:
    raise AssertionError("Le nombre de répétitions doit être entier")

from io import StringIO

sortie_demo = StringIO()
resultat_print = print("lot-A", 12, sep=";", end="!", file=sortie_demo)
assert sortie_demo.getvalue() == "lot-A;12!"
assert resultat_print is None

cle_K = 12
assert cle_K == 12  # Python normalise le nom de variable dans le code.
sources = {"cle_K": 12, "cle_K": 20}
assert len(sources) == 2 and sources["cle_K"] != sources["cle_K"]

def illustrer_nom_masque():
    list = ["nord"]
    try:
        list(("sud",))
    except TypeError:
        return "constructeur masqué"
    raise AssertionError("Une liste ne peut pas être appelée")

assert illustrer_nom_masque() == "constructeur masqué"
sources = ["nord"]
autres_sources = list(("sud",))
assert sources + autres_sources == ["nord", "sud"]
