diff --git a/.DS_Store b/.DS_Store index 8696372..dd5ab7b 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0a27357..3311baa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,12 +7,20 @@ on: branches: [ "main" ] jobs: - build: + test: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v4 - - name: Example step - run: echo "Add your build/test steps here!" + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.11" + + - name: Install dependencies + run: pip install -r requirements.txt + + - name: Run tests + run: pytest oop/ -v diff --git a/.gitignore b/.gitignore index 78e7733..f735c74 100644 --- a/.gitignore +++ b/.gitignore @@ -1,44 +1,45 @@ -# Local .terraform directories -.terraform/ - -# .tfstate files -*.tfstate -*.tfstate.* - -# Crash log files -crash.log -crash.*.log - -# Exclude all .tfvars files, which are likely to contain sensitive data, such as -# password, private keys, and other secrets. These should not be part of version -# control as they are data points which are potentially sensitive and subject -# to change depending on the environment. -*.tfvars -*.tfvars.json - -# Ignore override files as they are usually used to override resources locally and so -# are not checked in -override.tf -override.tf.json -*_override.tf -*_override.tf.json - -# Ignore transient lock info files created by terraform apply -.terraform.tfstate.lock.info - -# Include override files you do wish to add to version control using negated pattern -# !example_override.tf - -# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan -# example: *tfplan* - -# Ignore CLI configuration files -.terraformrc -terraform.rc - -# Optional: ignore graph output files generated by `terraform graph` -# *.dot - -# Optional: ignore plan files saved before destroying Terraform configuration -# Uncomment the line below if you want to ignore planout files. -# planout \ No newline at end of file +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# Virtual environments +venv/ +.venv/ +env/ +.env/ +ENV/ + +# Jupyter Notebook checkpoints +.ipynb_checkpoints/ +*/.ipynb_checkpoints/ + +# Distribution / packaging +dist/ +build/ +*.egg-info/ +*.egg + +# Environment variables +.env +.envrc + +# IDE / editors +.vscode/ +.idea/ +*.swp +*.swo + +# macOS +.DS_Store + +# pytest cache +.pytest_cache/ +*.pytest_cache + +# Coverage +.coverage +htmlcov/ + +# Logs +*.log diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f727ac4 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 Aldéric Hoarau + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index e403b0d..934135b 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Ce projet contient une série de notebooks Jupyter pour apprendre les bases de P ## Contenu des Notebooks - **0 - Installation Python.pptx** : Présentation sur l'installation de Python. -- **1-introduction.ipynb** : Introduction à Python. +- **1-introduction.ipynb** : Introduction à Python (scripts vs notebooks, commentaires, raccourcis). - **2-les-variables.ipynb** : Les variables en Python. - **3-data-structures.ipynb** : Les structures de données en Python. - **3b-data-structures.ipynb** : Suite des structures de données. @@ -14,18 +14,33 @@ Ce projet contient une série de notebooks Jupyter pour apprendre les bases de P - **5b-lambda.ipynb** : Les fonctions lambda. - **5c-le_typage.ipynb** : Le typage en Python. - **6-les-packages.ipynb** : Gestion des packages et environnements virtuels. -- **7-functions-args.ipynb** : Les arguments de fonctions. +- **7-functions-args.ipynb** : Les arguments de fonctions avancés (*args, **kwargs). - **8-fonction-recursive.ipynb** : Les fonctions récursives. - **9-falsy-values.ipynb** : Les valeurs falsy en Python. - **exos.ipynb** : Exercices pratiques. ## Programmation Orientée Objet (POO) -Le dossier `oop` contient des notebooks et des scripts pour apprendre la programmation orientée objet en Python : +Le dossier `oop/` contient des notebooks et des scripts pour apprendre la programmation orientée objet en Python : -- **1-Introduction_POO.ipynb** : Introduction à la POO. -- **class_to_test.py** : Script de classe à tester. -- **correction_conce_bis.py** : Correction des exercices de conception. +- **1-Introduction_POO.ipynb** : Introduction à la POO (classes, attributs, méthodes, héritage). +- **class_to_test.py** : Classe servant de support aux tests unitaires. +- **test_class_to_test.py** : Tests unitaires avec pytest. +- **correction.py** : Corrections des exercices (encapsulation, @property, classes abstraites, zoo). +- **correction_conce_bis.py** : Correction alternative de l'exercice de conception. +- **correction_concessionnaire.py** : Correction de l'exercice concessionnaire. +- **correction_exercice_blog.py** : Correction de l'exercice blog. +- **correction_toolbox.py** / **correction_toolbox_bis.py** : Corrections de l'exercice toolbox. +- **correction_zoo.py** : Correction de l'exercice zoo. +- **Correction_exercice_concessionnaire.ipynb** : Correction notebook concessionnaire. +- **Correction_forum.ipynb** : Correction notebook forum. +- **img/** : Diagrammes de classes (héritage, premier diagramme). + +## Fichiers de support (imports) + +- **Same_level.py** : Fonctions de démonstration pour les imports depuis le même répertoire (utilisé dans le notebook 6). +- **other_folder/other_folder_file.py** : Fonction de démonstration pour les imports depuis un sous-dossier (utilisé dans le notebook 6). +- **recursif.py** : Script de démonstration pour les fonctions récursives. ## Utilisation des Environnements Virtuels @@ -53,6 +68,12 @@ Pour installer les dépendances nécessaires, utilisez la commande suivante apr pip install -r requirements.txt ``` +## Lancer les tests + +```bash +pytest oop/ -v +``` + ## Contribuer Les contributions sont les bienvenues ! Veuillez soumettre une pull request ou ouvrir une issue pour discuter des changements que vous souhaitez apporter. diff --git a/oop/correction.txt b/oop/correction.py similarity index 52% rename from oop/correction.txt rename to oop/correction.py index 70498bc..948f8e8 100644 --- a/oop/correction.txt +++ b/oop/correction.py @@ -1,38 +1,44 @@ -classe héritage: https://github.com/OpenClassrooms-Student-Center/7150626-Apprenez-la-programmation-orientee-objet-avec-Python/blob/main/exercices/p2c2_forum.py +# ============================================================ +# Corrections des exercices POO +# ============================================================ - -user_creation (encapsulation) +# ------------------------------------------------------------ +# Encapsulation — User (version 1 : getters/setters manuels) +# ------------------------------------------------------------ class User: - def __init__(self,profil): + def __init__(self, profil): self.profil = profil self._password = "" self._user_name = "" self.__validation_code = "AB2X" - - def set_password(self,new_password): + + def set_password(self, new_password): self._password = new_password def get_password(self): - return self._password + return self._password def get_user_name(self): return self._user_name - def __check_validation_code(self,code): + def __check_validation_code(self, code): return code == self.__validation_code - - def set_user_name(self,code,user_name): + + def set_user_name(self, code, user_name): if self.__check_validation_code(code): self._user_name = user_name else: print("error code") -user_creation_bis -class User: - def __init__(self,profil, password="", code_value = ("AB2X","")): +# ------------------------------------------------------------ +# Encapsulation — User (version 2 : @property) +# ------------------------------------------------------------ + +class UserBis: + def __init__(self, profil, password="", code_value=("AB2X", "")): self.profil = profil self.password = password self.__validation_code = "AB2X" @@ -40,37 +46,38 @@ def __init__(self,profil, password="", code_value = ("AB2X","")): @property def password(self): - return self._password - + return self._password + @password.setter - def password(self,new_password): + def password(self, new_password): self._password = new_password - @property def user_name(self): return self._user_name @user_name.setter - def user_name(self,code_value): - code,value = code_value - print(code) - print(self.__validation_code) + def user_name(self, code_value): + code, value = code_value if self.__check_validation_code(code): self._user_name = value else: - print("error code") - - def __check_validation_code(self,code): + print("error code") + + def __check_validation_code(self, code): return code == self.__validation_code - -Zoo +# ------------------------------------------------------------ +# Héritage & classes abstraites — Zoo +# Référence : https://github.com/OpenClassrooms-Student-Center/ +# 7150626-Apprenez-la-programmation-orientee-objet-avec-Python +# ------------------------------------------------------------ from abc import ABCMeta, abstractmethod -class Animal (metaclass = ABCMeta ): + +class Animal(metaclass=ABCMeta): def __init__(self, name): self.name = name @@ -78,59 +85,68 @@ def __init__(self, name): def manger(self): pass -class Felin(Animal, metaclass = ABCMeta): - def manger (self,value): + +class Felin(Animal, metaclass=ABCMeta): + def manger(self, value): if value == "viande": print("le félin est nourri") else: print("cela ne correspond pas à un félin") -class Poisson(Animal, metaclass = ABCMeta): - def manger (self,value): + +class Poisson(Animal, metaclass=ABCMeta): + def manger(self, value): if value == "nourriture pour poisson": print("le poisson est nourri") else: print("cela ne correspond pas à un poisson") - + @abstractmethod - def nager(): - pass + def nager(self): + pass -class Oiseau(Animal, metaclass = ABCMeta): - def manger (self,value): + +class Oiseau(Animal, metaclass=ABCMeta): + def manger(self, value): if value == "graine": print("l'oiseau est nourri") else: print("cela ne correspond pas à un oiseau") - + @abstractmethod - def piailler(): - pass + def piailler(self): + pass class Lion(Felin): - def rugier(self): + def rugir(self): print("RRRRRrrrr") + class Chat(Felin): def miauler(self): print("Miaou") -class Panthère(Felin): + +class Panthere(Felin): pass + class Canari(Oiseau): - def piaillier(self): + def piailler(self): print("cuicui") + class Autruche(Oiseau): - def piaillier(self): + def piailler(self): print("CUICUI") + class Raie(Poisson): def nager(self): pass + class Dauphin(Poisson): def nager(self): pass diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..2eacebe --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +jupyter +notebook +ipykernel +pytest