From b4f5634f2b78bc3c0fe313422df6a63186fe23b7 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Thu, 21 Apr 2022 22:54:06 +0200 Subject: [PATCH] Fix some unit tests --- app/comp/moy_ue.py | 8 ++++---- tests/unit/sco_fake_gen.py | 2 +- tests/unit/test_but_ues.py | 29 +++++++++++++++++++---------- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/app/comp/moy_ue.py b/app/comp/moy_ue.py index 6d80f0b7b..2d337a3d0 100644 --- a/app/comp/moy_ue.py +++ b/app/comp/moy_ue.py @@ -271,7 +271,7 @@ def compute_ue_moys_apc( ) # Annule les coefs des modules NaN modimpl_coefs_etuds_no_nan = np.where(np.isnan(sem_cube), 0.0, modimpl_coefs_etuds) - if modimpl_coefs_etuds_no_nan.dtype == np.object: # arrive sur des tableaux vides + if modimpl_coefs_etuds_no_nan.dtype == object: # arrive sur des tableaux vides modimpl_coefs_etuds_no_nan = modimpl_coefs_etuds_no_nan.astype(np.float) # # Version vectorisée @@ -356,7 +356,7 @@ def compute_ue_moys_classic( modimpl_coefs_etuds_no_nan = np.where( np.isnan(sem_matrix), 0.0, modimpl_coefs_etuds ) - if modimpl_coefs_etuds_no_nan.dtype == np.object: # arrive sur des tableaux vides + if modimpl_coefs_etuds_no_nan.dtype == object: # arrive sur des tableaux vides modimpl_coefs_etuds_no_nan = modimpl_coefs_etuds_no_nan.astype(np.float) # --------------------- Calcul des moyennes d'UE ue_modules = np.array( @@ -367,7 +367,7 @@ def compute_ue_moys_classic( ) # nb_ue x nb_etuds x nb_mods : coefs prenant en compte NaN et inscriptions: coefs = (modimpl_coefs_etuds_no_nan_stacked * ue_modules).swapaxes(1, 2) - if coefs.dtype == np.object: # arrive sur des tableaux vides + if coefs.dtype == object: # arrive sur des tableaux vides coefs = coefs.astype(np.float) with np.errstate(invalid="ignore"): # ignore les 0/0 (-> NaN) etud_moy_ue = ( @@ -462,7 +462,7 @@ def compute_mat_moys_classic( modimpl_coefs_etuds_no_nan = np.where( np.isnan(sem_matrix), 0.0, modimpl_coefs_etuds ) - if modimpl_coefs_etuds_no_nan.dtype == np.object: # arrive sur des tableaux vides + if modimpl_coefs_etuds_no_nan.dtype == object: # arrive sur des tableaux vides modimpl_coefs_etuds_no_nan = modimpl_coefs_etuds_no_nan.astype(np.float) etud_moy_mat = (modimpl_coefs_etuds_no_nan * sem_matrix_inscrits).sum( diff --git a/tests/unit/sco_fake_gen.py b/tests/unit/sco_fake_gen.py index a07e81169..0c9931ad1 100644 --- a/tests/unit/sco_fake_gen.py +++ b/tests/unit/sco_fake_gen.py @@ -204,7 +204,7 @@ class ScoFake(object): abbrev=None, ects=None, code_apogee=None, - module_type=None, + module_type=scu.ModuleType.STANDARD, ) -> int: oid = sco_edit_module.do_module_create(locals()) oids = sco_edit_module.module_list(args={"module_id": oid}) diff --git a/tests/unit/test_but_ues.py b/tests/unit/test_but_ues.py index 0898bec84..bc0ad6225 100644 --- a/tests/unit/test_but_ues.py +++ b/tests/unit/test_but_ues.py @@ -2,20 +2,15 @@ Test calcul moyennes UE """ import numpy as np -from numpy.lib.nanfunctions import _nanquantile_1d -import pandas as pd from tests.unit import setup -from tests.unit import sco_fake_gen from app import db -from app import models -from app.comp import moy_mod from app.comp import moy_ue from app.comp import inscr_mod from app.models import FormSemestre, Evaluation, ModuleImplInscription -from app.models.etudiants import Identite -from app.scodoc import sco_codes_parcours, sco_saisie_notes -from app.scodoc.sco_utils import NOTES_ATTENTE, NOTES_NEUTRALISE +from app.scodoc import sco_saisie_notes +from app.scodoc.sco_codes_parcours import UE_SPORT +from app.scodoc.sco_utils import NOTES_NEUTRALISE from app.scodoc import sco_exceptions @@ -69,9 +64,20 @@ def test_ue_moy(test_client): _ = sco_saisie_notes.notes_add(G.default_user, evaluation2.id, [(etudid, n2)]) # Recalcul des moyennes sem_cube, _, _ = moy_ue.notes_sem_load_cube(formsemestre) + # Masque de tous les modules _sauf_ les bonus (sport) + modimpl_mask = [ + modimpl.module.ue.type != UE_SPORT + for modimpl in formsemestre.modimpls_sorted + ] etuds = formsemestre.etuds.all() etud_moy_ue = moy_ue.compute_ue_moys_apc( - sem_cube, etuds, modimpls, ues, modimpl_inscr_df, modimpl_coefs_df + sem_cube, + etuds, + modimpls, + ues, + modimpl_inscr_df, + modimpl_coefs_df, + modimpl_mask, ) return etud_moy_ue @@ -113,8 +119,11 @@ def test_ue_moy(test_client): # Recalcule les notes: sem_cube, _, _ = moy_ue.notes_sem_load_cube(formsemestre) etuds = formsemestre.etuds.all() + modimpl_mask = [ + modimpl.module.ue.type != UE_SPORT for modimpl in formsemestre.modimpls_sorted + ] etud_moy_ue = moy_ue.compute_ue_moys_apc( - sem_cube, etuds, modimpls, ues, modimpl_inscr_df, modimpl_coefs_df + sem_cube, etuds, modimpls, ues, modimpl_inscr_df, modimpl_coefs_df, modimpl_mask ) assert etud_moy_ue[ue1.id][etudid] == n1 assert etud_moy_ue[ue2.id][etudid] == n1