Compare commits
6 Commits
4-execute-
...
v11
Author | SHA1 | Date | |
---|---|---|---|
60e09751da
|
|||
1fc558a2ad
|
|||
df223bd19e
|
|||
7c2d082cf4
|
|||
1ba9934438
|
|||
d4d595ed68
|
@ -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 pytest-cov --no-cache-dir
|
||||
script: pytest --showlocals --cov=main --cov=main_test --cov-report=term-missing .
|
||||
|
25
main.py
Normal file → Executable file
25
main.py
Normal file → Executable 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,20 +24,27 @@ 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():
|
||||
"""
|
||||
Affiche l'aide
|
||||
"""
|
||||
print("aide\t\tAffiche l'aide")
|
||||
print("seminaire\tLance le séminaire")
|
||||
print("blague\t\tRaconte une blague")
|
||||
print("calcul\t\tVérifie une opération arithmétique. "
|
||||
"Par exemple, check(1, 2, 3, '+') renvoie True")
|
||||
print("tri\t\tTrie une liste d'entiers.")
|
||||
print("stop\t\tQuitte le programme")
|
||||
return "aide\t\tAffiche l'aide\n" \
|
||||
"seminaire\tLance le séminaire\n" \
|
||||
"blague\t\tRaconte une blague\n" \
|
||||
"calcul\t\tVérifie une opération arithmétique. " \
|
||||
"Par exemple, check(1, 2, 3, '+') renvoie True\n" \
|
||||
"tri\t\tTrie une liste d'entiers.\n" \
|
||||
"stop\t\tQuitte le programme"
|
||||
|
||||
|
||||
def seminaire():
|
||||
|
29
main_test.py
Executable file
29
main_test.py
Executable file
@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
"""
|
||||
Exécution des tests du script.
|
||||
"""
|
||||
|
||||
import unittest
|
||||
|
||||
import main
|
||||
|
||||
|
||||
class TestMain(unittest.TestCase):
|
||||
"""
|
||||
Cette classe permet d'executer l'ensemble des scripts
|
||||
"""
|
||||
|
||||
def test_aide(self):
|
||||
"""
|
||||
On essaie d'afficher l'aide, et on vérifie si ça affiche la bonne chose.
|
||||
"""
|
||||
res = main.commande("aide")
|
||||
lines = res.split("\n")
|
||||
self.assertEqual(len(lines), 6)
|
||||
self.assertTrue(lines[0].startswith("aide"))
|
||||
self.assertTrue(lines[1].startswith("seminaire"))
|
||||
self.assertTrue(lines[2].startswith("blague"))
|
||||
self.assertTrue(lines[3].startswith("calcul"))
|
||||
self.assertTrue(lines[4].startswith("tri"))
|
||||
self.assertTrue(lines[5].startswith("stop"))
|
Reference in New Issue
Block a user