Procházet zdrojové kódy

ajoute un exemple de projet python avec CI gitlab

olivier.massot před 8 roky
rodič
revize
36d70f1bf0

+ 11 - 0
Exemples/Python/hello_world/.gitignore

@@ -0,0 +1,11 @@
+*.pyc
+
+# Eclipse pydev project
+.project
+.pydevproject
+.settings/
+
+# tests
+htmlcov/
+.coverage
+

+ 8 - 0
Exemples/Python/hello_world/.gitlab.yml

@@ -0,0 +1,8 @@
+
+before_script:
+  - python -V      # print the python version, for debugging
+  - pip install -r requirements.txt
+  
+ test:
+  script:
+  - nose2

+ 27 - 0
Exemples/Python/hello_world/README.md

@@ -0,0 +1,27 @@
+Un script python hello_world.
+
+hello_world.py` : Script python, instancie une fonction `main()` qui renvoie un message de salutations. 
+
+`__init__.py` : Fichier qui peut rester vide, mais nécessaire pour que le répertoire soit reconu comme une librairie python.
+
+`test.py` : Contient les tests unitaires
+
+`nose2.cfg` : (facultatif) configuration de nose2
+
+Pour exécuter les tests, ouvrir une console (invite de commande):
+
+Installer les librairies nécessaires:
+
+	pip install -r requirements.txt
+
+Tests unitaires et couverture
+
+	nose2
+
+ Syntaxe
+
+	pylint
+
+
+
+ 

+ 6 - 0
Exemples/Python/hello_world/__init__.py

@@ -0,0 +1,6 @@
+"""
+    Module Hello world
+"""
+
+__version__ = "0.0.1"
+

+ 15 - 0
Exemples/Python/hello_world/hello_world.py

@@ -0,0 +1,15 @@
+"""
+    Implementation de Hello World
+
+    Usage:
+
+    >>> from hello_world import main
+    >>> main()
+"""
+
+
+def main():
+	return "Hello World!"
+
+if __name__ == "__main__":
+	print(main())

+ 7 - 0
Exemples/Python/hello_world/nose2.cfg

@@ -0,0 +1,7 @@
+[unittest]
+with-coverage = True
+
+[coverage]
+always-on = True
+coverage = .
+coverage-report = html

+ 3 - 0
Exemples/Python/hello_world/requirements.txt

@@ -0,0 +1,3 @@
+nose2
+cov-core
+coverage

+ 14 - 0
Exemples/Python/hello_world/test.py

@@ -0,0 +1,14 @@
+'''
+    Tests unitaires
+'''
+import unittest
+
+import hello_world
+
+class Test(unittest.TestCase):
+
+    def test_main(self):
+        self.assertEqual(hello_world.main(), "Hello World!")
+
+if __name__ == "__main__":
+    unittest.main()

+ 42 - 0
Exemples/Python/python-ci.md

@@ -0,0 +1,42 @@
+
+# Tester, contrôler, et déployer son code python en intégration continue
+
+> Testé avec python 3.4, et python 3.6
+
+## Pré-requis:
+
+Installer les librairies suivantes sur la machine de test:
+
+Requis:
+
+* nose2 > `pip install nose2`
+* cov-core > `pip install cov-core`
+
+* pylint > `pip install pylint` (préinstallé en 3.6)
+> si ImportError au lancement de pylint, executer aussi:
+> `pip install wrapt lazy_object_proxy --upgrade`
+
+
+Autres:
+* junit-xml > `pip install junit-xml`
+
+## nose2 - Tests unitaires et couverture
+
+[**nose2**](https://nose2.readthedocs.io/en/latest/) executera les tests de tous les fichiers dont le nom commence par 'test_'  
+
+En ligne de commande windows: `nose2 --with-coverage --coverage=<module>`
+
+Pour générer des rapports en html: 
+`nose2 --with-coverage --coverage=<module> --coverage-report html`
+
+## PyLint - Qualité du code
+
+[**pylint**](https://www.pylint.org/) contrôle la qualité du code
+
+En ligne de commande windows: `pylint <module>`
+
+## Distribuer
+
+* [pynsist](https://pypi.python.org/pypi/pynsist)
+* [py2exe](http://py2exe.org/)
+* [cx_Freeze](https://pypi.python.org/pypi/cx_Freeze)