Example #1
0
 def test_user_input_NaN(self, user_input_mock):
     # test that the code still selects the good candidates
     # if user do not enter a number the first time
     user_input_mock.side_effect = ["not a number", "2", "oui"]
     self.selector = Selector(self.data_path, loglevel=self.loglevel)
     dist = self.selector.distribution
     self.assertEqual(dist["1441"][0].name, "Bernard B")
Example #2
0
 def test_user_input_less_than_1(self, user_input_mock):
     # test that the code still selects the good candidates
     # if user enters a number less than 1
     user_input_mock.side_effect = ["0", "2", "oui"]
     self.selector = Selector(self.data_path, loglevel=self.loglevel)
     dist = self.selector.distribution
     self.assertEqual(dist["1441"][0].name, "Bernard B")
Example #3
0
 def test_user_input_wrong_retry(self, user_input_mock):
     # test that the code still selects the good candidates
     # if user enters neither 'yes' or 'no' at the
     # last step to retry selection
     # (test when user changes its mind but makes a typo)
     user_input_mock.side_effect = ["1", "not yes or no", "N", "2", "y"]
     self.selector = Selector(self.data_path, loglevel=self.loglevel)
     dist = self.selector.distribution
     self.assertEqual(dist["1441"][0].name, "Bernard B")
Example #4
0
 def test_user_input_retry(self, user_input_mock):
     # test that the code still selects the good candidates
     # if user enters 'no' at the last step to retry selection
     # (test when user changes its mind)
     user_input_mock.side_effect = ["1", "no", "2", "yes"]
     self.selector = Selector(self.data_path, loglevel=self.loglevel)
     dist = self.selector.distribution
     second_name = self.selector.excel_mgr.candidates[1].name
     self.assertEqual(dist["1441"][0].name, second_name)
Example #5
0
 def test_running(self):
     # simple test that checks that both candidates receive
     # their first choice.
     self.selector = Selector(self.data_path, loglevel=self.loglevel)
     dist = self.selector.distribution
     self.assertEqual(dist["1441"][0].name, "Albert A")
     self.assertEqual(dist["2710"][0].name, "Claude C")
     # check that there is no other candidates in the distribution
     self.assertEqual(len(dist["1441"]), 1)
     self.assertEqual(len(dist["2710"]), 1)
Example #6
0
    def run_selector(self):
        path = self.pathBox.get()
        if not len(path):
            self._logger.error("Veuiller entrer un fichier Excel.")
            return

        path = os.path.abspath(path)
        if not os.path.exists(path):
            self._logger.error("%s n'existe pas!" % path)
            return
        if not os.path.isfile(path):
            self._logger.error("%s n'est pas un fichier." % path)
            return
        if not path.endswith(".xlsx") and not path.endswith(".ods"):
            self._logger.error("%s doit être un fichier excel ou ods." % path)
            return
        # path is good, save it for next time user open program
        self.config_manager.last_excel_file = path
        self.config_manager.write_config()

        start = None
        try:
            # warn user to close the excel file
            self.warn_user_excel(path)
            self._logger.info("Exécution ... ceci peut prendre"
                              " quelques minutes ...")
            # time process
            start = timer()
            Selector(path,
                     master=self.master,
                     loglevel=self.config_manager.loglevel)
        except Exception as e:
            if not int(self.debugCheckButton.get()):
                self._logger.error("%s" % e)
            else:
                # print full traceback
                tb = traceback.format_exc()
                self._logger.error(tb)
            self._logger.critical("STOP - ERREUR")
        else:
            self._forceprint("Succès!")
        finally:
            end = timer()
            if start is None:
                # an error occured before the call to the selector
                return
            self._forceprint("Temps d'exécution = %.3f secondes" %
                             (end - start))
Example #7
0
 def test_distribution_sheet_already_exists(self):
     # load workbook and add a distribution cheet
     wb = load_workbook(self.data_path)
     # create distribution sheet
     ws = wb.create_sheet("Distribution")
     safe_string = "Check that this string is not erased."
     ws["A1"].value = safe_string
     wb.save(self.data_path)
     del wb
     # call selector and check that already existing sheet is not erased
     self.selector = Selector(self.data_path)
     # reload wb
     wb = load_workbook(self.data_path)
     self.assertIn("Distribution1", wb.sheetnames)
     # check that the previous sheet was not overridden
     ws = wb["Distribution"]
     self.assertEqual(ws["A1"].value, safe_string)
     del wb
Example #8
0
 def test_writing_distribution(self):
     # make distribution
     self.selector = Selector(self.data_path)
     # open excel file
     wb = load_workbook(self.data_path)
     # check that the sheet exists
     self.assertIn("Distribution", wb.sheetnames)
     # get sheet
     ws = wb["Distribution"]
     # check that first row is the titles
     self.assertEqual(ws["A1"].value.lower(), "sigle")
     self.assertEqual(ws["B1"].value.lower(), "distribution")
     # check that next rows are courses with selection
     allcodes = [x["code"] for x in self.courses.values()]
     self.assertIn(ws["A2"].value, allcodes)
     self.assertIn(ws["A3"].value, allcodes)
     # only two courses, next rows should be empty
     self.assertIs(ws["A4"].value, None)
     for row in ws.iter_rows(min_col=1, max_col=2, min_row=2, max_row=3):
         if row[0].value == "1441":
             self.assertEqual(row[1].value, "Albert A")
         else:
             self.assertEqual(row[1].value, "Claude C")
Example #9
0
 def test_user_input_simple(self, user_input_mock):
     # test that user input chooses first candidate over second.
     user_input_mock.side_effect = ["1", "oui"]
     self.selector = Selector(self.data_path, loglevel=self.loglevel)
     dist = self.selector.distribution
     self.assertEqual(dist["1441"][0].name, "Albert A")
Example #10
0
 def test_gpa(self):
     self.selector = Selector(self.data_path, loglevel=self.loglevel)
     # results
     dist = self.selector.distribution
     self.assertEqual(dist["1441"][0].name, "Claude C")
Example #11
0
 def test_program(self):
     self.selector = Selector(self.data_path)
     # results
     dist = self.selector.distribution
     self.assertEqual(dist["2710"][0].name, "Claude C")
Example #12
0
 def test_nobel(self):
     self.selector = Selector(self.data_path)
     # results
     dist = self.selector.distribution
     self.assertEqual(dist["1441"][0].name, "Claude C")
Example #13
0
 def test_no_more_space(self):
     self.selector = Selector(self.data_path)
     # results
     dist = self.selector.distribution
     self.assertEqual(dist["1441"], [])
     self.assertEqual(dist["2710"], [])
Example #14
0
 def test_second_choice_beat_first_if_better_and_has_dispo(self):
     self.selector = Selector(self.data_path)
     # results
     dist = self.selector.distribution
     self.assertEqual(dist["1441"][0].name, "Albert A")
     self.assertEqual(dist["2710"][0].name, "Claude C")
Example #15
0
 def test_no_discipline(self):
     self.selector = Selector(self.data_path)
     course = self.selector.excel_mgr.courses[0]
     self.assertEqual(course.discipline, "générale")
Example #16
0
 def test_no_name(self):
     self.selector = Selector(self.data_path)
     course = self.selector.excel_mgr.courses[0]
     self.assertEqual(course.name, course.code)
Example #17
0
 def test_no_code(self):
     with self.assertRaises(ValueError):
         self.selector = Selector(self.data_path)
Example #18
0
from auxiclean import Selector

path = "example.xlsx"
d = Selector(path)
Example #19
0
 def test_sort_by_specific_tp_experience(self):
     self.selector = Selector(self.data_path, loglevel=self.loglevel)
     # results
     dist = self.selector.distribution
     self.assertEqual(dist["1441"][0].name, "Alice")
Example #20
0
 def test_raise_choice_error(self):
     with self.assertRaises(ExcelError):
         self.selector = Selector(self.data_path)
Example #21
0
 def test_two_class_for_one_person(self):
     self.selector = Selector(self.data_path, loglevel=self.loglevel)
     # results
     dist = self.selector.distribution
     self.assertEqual(dist["1441"][0].name, "Albert A")
     self.assertEqual(dist["2710"][0].name, "Albert A")
Example #22
0
 def test_no_gpa(self, user_input):
     # test that gpa is not considered if it
     # is not given
     user_input.side_effect = ["1", "oui"]
     self.selector = Selector(self.data_path, loglevel=self.loglevel)