3 Commits

Author SHA1 Message Date
7c2d082cf4 On lint le fichier de tests également
Signed-off-by: Yohann D'ANELLO <ynerant@crans.org>
2021-01-26 17:39:54 +01:00
1ba9934438 Pytest est requis
Signed-off-by: Yohann D'ANELLO <ynerant@crans.org>
2021-01-26 17:08:30 +01:00
d4d595ed68 Ajout d'un fichier de test avec pytest
Signed-off-by: Yohann D'ANELLO <ynerant@crans.org>
2021-01-26 17:07:12 +01:00
3 changed files with 36 additions and 5 deletions

View File

@ -8,7 +8,7 @@ flake8:
image: python:3-alpine
before_script:
- pip install flake8 --no-cache-dir
script: flake8 main.py
script: flake8 main.py main_test.py
allow_failure: true
@ -17,11 +17,13 @@ pylint:
image: python:3-alpine
before_script:
- pip install pylint --no-cache-dir
script: pylint main.py
script: pylint main.py main_test.py
allow_failure: true
test:
stage: test
image: python:3-alpine
script: python main.py
before_script:
- pip install pytest --no-cache-dir
script: pytest --showlocals .

11
main.py Normal file → Executable file
View File

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
"""
Ce script est utilisé en guise d'appui pour le séminaire Crans d'introduction
@ -24,7 +24,14 @@ def main():
while True:
command = input("> ")
args = command.split(" ")
print(globals()[args[0]](*args[1:]))
print(commande(args[0], *args[1:]))
def commande(name: str, *args):
"""
Exécute la commande `name` avec les arguments donnés.
"""
return globals()[name](*args)
def aide():

22
main_test.py Executable file
View File

@ -0,0 +1,22 @@
#!/usr/bin/env python3
"""
Exécution des tests du script.
"""
import main
def test_aide():
"""
On essaie d'afficher l'aide, et on vérifie si ça affiche la bonne chose.
"""
res = main.commande("aide")
lines = res.split("\n")
assert len(lines) == 6
assert lines[0].startswith("aide")
assert lines[1].startswith("seminaire")
assert lines[2].startswith("blague")
assert lines[3].startswith("calcul")
assert lines[4].startswith("tri")
assert lines[5].startswith("stop")