Skip to content

[BACK] Support running on sample input and run in CI#46

Merged
acornet merged 8 commits intomainfrom
back/ac/test-mode
Feb 24, 2025
Merged

[BACK] Support running on sample input and run in CI#46
acornet merged 8 commits intomainfrom
back/ac/test-mode

Conversation

@acornet
Copy link
Contributor

@acornet acornet commented Feb 20, 2025

  • Add test config to run against a test sample input.
    • read / write intermediary results to other locations
  • Add GH action to run the pipeline
    • skip pre-commit and test run for changes in front/
    • skip test run for changes in data-analyst
  • Fix side effect of save_csv function, which was modifying the dataframe

@acornet acornet force-pushed the back/ac/test-mode branch 2 times, most recently from 5bea548 to 039d8f0 Compare February 20, 2025 23:01
@acornet acornet changed the base branch from main to back/ac/simple-sql-export February 20, 2025 23:02
@acornet acornet requested a review from cgoudet February 20, 2025 23:27
@acornet acornet marked this pull request as ready for review February 20, 2025 23:27
@acornet
Copy link
Contributor Author

acornet commented Feb 20, 2025

@cgoudet qu'en penses-tu? c'était deux fois plus rapide sur mon mac, 5 minutes j'ai peur que cela soit un peu long.

Base automatically changed from back/ac/simple-sql-export to main February 21, 2025 10:05
@acornet
Copy link
Contributor Author

acornet commented Feb 21, 2025

@cgoudet j'ai fait quelques optimisation supplémentaires et désormais la CI passe en 3 minutes, ce qui acceptable selon moi :)

@acornet
Copy link
Contributor Author

acornet commented Feb 21, 2025

note: splitting the workflow in two, to be more granular on when things are ran

@acornet acornet force-pushed the back/ac/test-mode branch 3 times, most recently from 6022559 to 2ea5fcb Compare February 21, 2025 15:41
Copy link
Collaborator

@cgoudet cgoudet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je suis assez sceptique sur la strategie. Au final on a un code avec énormément de ìf TestHelper.usingFullInput()`. Cela nuit à la lisibilité du code et le code est très dépendant du fait d'être en phase de test.

Je pense qu'il faut réorganizer le test voir le code pour que le code lui meme soit agnostique d'être en phase test, dégradé ou prod.

Voici une contre proposition :

  • le test se déclenche via pytest d'un fichier du type tests/back/test_end_to_end.py
  • On fourni à l'entrée de la pipeline un fichier de configuration dédié : les fichiers d'input comme les chemins de sauvegarde.
  • On mock les appels API : ton travail pour remplacer des appels web par des lectures de fichier est nickel pour ca.
  • On mock get_data_path par un fichier temporaire avec tempfile.

A dispo pour échanger!

@@ -0,0 +1,145 @@
Exercice;Outre-mer;Code Insee 2023 Région;Nom 2023 Région;Code Insee 2023 Département;Nom 2023 Département;Code Siren 2023 EPCI;Nom 2023 EPCI;Strate population 2023;Commune rurale;Commune de montagne;Commune touristique;Tranche revenu par habitant;Présence QPV;Code Insee 2023 Commune;Nom 2023 Commune;Catégorie;Code Siren Collectivité;Code Insee Collectivité;Libellé Budget;Agrégat;Montant BP;Montant BA;Montant flux BP-BA;Montant;Montant en millions;Population totale;Montant en € par habitant;Compte 2023 Disponible;ordre_analyse1_section1;ordre_analyse1_section2;ordre_analyse1_section3;ordre_analyse2_section1;ordre_analyse2_section2;ordre_analyse2_section3;ordre_analyse3_section1;ordre_analyse3_section2;ordre_analyse3_section3;ordre_analyse4_section1;annee_join;Population totale du dernier exercice;siren
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je conseillerais de mettre ce fichier dans tests/back/fixtures/. La bonne pratique est de ne pas mélanger le code et les tests. Et techniquement ce fichier est un input pour un test.

# Get the content type of the file from the headers
response = requests.head(file_url)
content_type = response.headers.get("content-type")
# logger.info(f"Content type : {content_type}")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is dead code and can be removed.


def normalize_column_names(df):
"""This modify the dataframe in place."""
df.columns = [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C'est une mauvaise pratique de modifier des datasets en place.

Il faudrait plutot return df.rename(columns=lambda x : re.sub(r"[.-]", "_", c.lower()).

Après je valide le fait d'avoir cette logique dans une fonction dédiée.

Peux tu ajouter les type hint tand que l'on y est?

Copy link
Contributor Author

@acornet acornet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merci beaucoup pour les retours @cgoudet , je suis d'accord avec toi que la solution n'était pas satisfaite et difficile à maintenir. j'ai changé d'approche et j'ai capitalisé sur le travail de @RiwsPy dans #47 en créant un fichier de config de test, ce qui minimise les changements apporté dans le code. dis moi ce que tu en penses!

@acornet acornet requested a review from cgoudet February 24, 2025 12:17
Copy link
Collaborator

@cgoudet cgoudet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minimal style comments.

Path.cwd() / "back" / "data" / "test" / "ofgl-base-communes-consolidee.test.csv",
sep=";",
index=False,
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe make this module callable by wrapping it into a function and add the entreypoint at the end.

@acornet acornet merged commit a92a7f4 into main Feb 24, 2025
2 checks passed
@acornet acornet deleted the back/ac/test-mode branch February 24, 2025 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants