Skip to content
Snippets Groups Projects
Commit a2067a74 authored by erichard's avatar erichard
Browse files

Add doctest for get_ids and get_elements.

parent c4f829a3
No related branches found
No related tags found
2 merge requests!61Packager labelstower,!60WIP: Implement sqlalchemy
...@@ -7,6 +7,13 @@ def get_elements(id_mandatory_labels: int, id_forbiden_labels: str, number_of_ma ...@@ -7,6 +7,13 @@ def get_elements(id_mandatory_labels: int, id_forbiden_labels: str, number_of_ma
:param id_forbiden_labels: str :param id_forbiden_labels: str
:param number_of_mandatory_labels: int :param number_of_mandatory_labels: int
:return: List[Dict[int, str]] :return: List[Dict[int, str]]
EXEMPLE
-------
>>> print(get_elements("","",0)) # si aucun labels n'est interdit ou obligatoire
[{'id': 4, 'name': 'peugeot, 2000'}, {'id': 3, 'name': 'renault, 2000'}, {'id': 2, 'name': 'renault, bleu, 2000'}, {'id': 1, 'name': 'renault, rouge, 2000'}]
>>> print(get_elements("9","",1)) # si la voiture doit-être bleu
[{'id': 2, 'name': 'renault, bleu, 2000'}]
""" """
#query slightly vary if number_of_mandatory_labels > 0 or not #query slightly vary if number_of_mandatory_labels > 0 or not
if(number_of_mandatory_labels): if(number_of_mandatory_labels):
...@@ -145,6 +152,13 @@ def get_ids(objects: List[Dict[int, str]]) -> str : ...@@ -145,6 +152,13 @@ def get_ids(objects: List[Dict[int, str]]) -> str :
:param objects: list[Dict[str, str]] :param objects: list[Dict[str, str]]
:param attribut: str :param attribut: str
:return: str :return: str
EXEMPLE
-------
>>> print(get_ids([{"id":1, "name":"a"},{"id":2, "name":"b"}]))
1,2
>>> print(get_ids([]))
<BLANKLINE>
""" """
objects_ids = "" objects_ids = ""
for object in objects: for object in objects:
...@@ -166,3 +180,7 @@ def send_query_to_db(query: str) -> List[Dict[int, str]] : ...@@ -166,3 +180,7 @@ def send_query_to_db(query: str) -> List[Dict[int, str]] :
for row in response: for row in response:
result.append({"id": row[0], "name": row[1]}) result.append({"id": row[0], "name": row[1]})
return result return result
if __name__ == "__main__":
import doctest
doctest.testmod(verbose=True)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment