Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
1fc558a2ad
|
|||
df223bd19e
|
|||
7c2d082cf4
|
|||
1ba9934438
|
@ -8,7 +8,7 @@ flake8:
|
|||||||
image: python:3-alpine
|
image: python:3-alpine
|
||||||
before_script:
|
before_script:
|
||||||
- pip install flake8 --no-cache-dir
|
- pip install flake8 --no-cache-dir
|
||||||
script: flake8 main.py
|
script: flake8 main.py main_test.py
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
|
||||||
|
|
||||||
@ -17,11 +17,13 @@ pylint:
|
|||||||
image: python:3-alpine
|
image: python:3-alpine
|
||||||
before_script:
|
before_script:
|
||||||
- pip install pylint --no-cache-dir
|
- pip install pylint --no-cache-dir
|
||||||
script: pylint main.py
|
script: pylint main.py main_test.py
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
|
||||||
|
|
||||||
test:
|
test:
|
||||||
stage: test
|
stage: test
|
||||||
image: python:3-alpine
|
image: python:3-alpine
|
||||||
script: pytest --show-locals .
|
before_script:
|
||||||
|
- pip install pytest --no-cache-dir
|
||||||
|
script: pytest --showlocals .
|
||||||
|
17
main.py
17
main.py
@ -28,6 +28,9 @@ def main():
|
|||||||
|
|
||||||
|
|
||||||
def commande(name: str, *args):
|
def commande(name: str, *args):
|
||||||
|
"""
|
||||||
|
Exécute la commande `name` avec les arguments donnés.
|
||||||
|
"""
|
||||||
return globals()[name](*args)
|
return globals()[name](*args)
|
||||||
|
|
||||||
|
|
||||||
@ -35,13 +38,13 @@ def aide():
|
|||||||
"""
|
"""
|
||||||
Affiche l'aide
|
Affiche l'aide
|
||||||
"""
|
"""
|
||||||
print("aide\t\tAffiche l'aide")
|
return "aide\t\tAffiche l'aide\n" \
|
||||||
print("seminaire\tLance le séminaire")
|
"seminaire\tLance le séminaire\n" \
|
||||||
print("blague\t\tRaconte une blague")
|
"blague\t\tRaconte une blague\n" \
|
||||||
print("calcul\t\tVérifie une opération arithmétique. "
|
"calcul\t\tVérifie une opération arithmétique. " \
|
||||||
"Par exemple, check(1, 2, 3, '+') renvoie True")
|
"Par exemple, check(1, 2, 3, '+') renvoie True\n" \
|
||||||
print("tri\t\tTrie une liste d'entiers.")
|
"tri\t\tTrie une liste d'entiers.\n" \
|
||||||
print("stop\t\tQuitte le programme")
|
"stop\t\tQuitte le programme"
|
||||||
|
|
||||||
|
|
||||||
def seminaire():
|
def seminaire():
|
||||||
|
27
main_test.py
27
main_test.py
@ -9,16 +9,21 @@ import unittest
|
|||||||
import main
|
import main
|
||||||
|
|
||||||
|
|
||||||
def test_aide():
|
class TestMain(unittest.TestCase):
|
||||||
"""
|
"""
|
||||||
On essaie d'afficher l'aide, et on vérifie si ça affiche la bonne chose.
|
Cette classe permet d'executer l'ensemble des scripts
|
||||||
"""
|
"""
|
||||||
res = main.commande("aide")
|
|
||||||
lines = res.split("\n")
|
def test_aide(self):
|
||||||
assert len(lines) == 6
|
"""
|
||||||
assert lines[0].startswith("aide")
|
On essaie d'afficher l'aide, et on vérifie si ça affiche la bonne chose.
|
||||||
assert lines[1].startswith("seminaire")
|
"""
|
||||||
assert lines[2].startswith("blague")
|
res = main.commande("aide")
|
||||||
assert lines[3].startswith("calcul")
|
lines = res.split("\n")
|
||||||
assert lines[4].startswith("tri")
|
self.assertEqual(len(lines), 6)
|
||||||
assert lines[5].startswith("stop")
|
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