From 91a761424e3ed08d745922e95d1eb6a0a2edb050 Mon Sep 17 00:00:00 2001 From: fgoudreault Date: Thu, 22 Jun 2017 13:22:18 -0400 Subject: [PATCH] Added tests for checkups --- auxiclean/unittests/test_candidate.py | 33 +++++++++++++ auxiclean/unittests/test_course.py | 58 +++++++++++++++++++++++ auxiclean/unittests/test_excel_manager.py | 31 ++++++++++++ auxiclean/unittests/test_selector.py | 1 + tests.py | 47 +++++++++++------- 5 files changed, 153 insertions(+), 17 deletions(-) create mode 100644 auxiclean/unittests/test_candidate.py create mode 100644 auxiclean/unittests/test_course.py diff --git a/auxiclean/unittests/test_candidate.py b/auxiclean/unittests/test_candidate.py new file mode 100644 index 0000000..bd3cdc9 --- /dev/null +++ b/auxiclean/unittests/test_candidate.py @@ -0,0 +1,33 @@ +from .test_selector import TestBase +from auxiclean import Selector +from unittest.mock import patch + + +@patch('auxiclean.user_input.get_user_input') +class TestCandidateNoGPA(TestBase): + # two different courses + courses = {"Electro": {"code": "1441", + "disponibilities": 1, + "discipline": "générale"}} + # two candidates each applying for a different course. + # they are equals. so we must choose 1 + candidates = {"Albert A": {"maximum": 2, + "scolarity": 2, + "courses given": [], + "nobels": 0, + "discipline": "générale", + "choices": ["1441", ], + "gpa": ""}, # no gpa + "Claude C": {"maximum": 2, + "scolarity": 2, + "courses given": [], + "nobels": 0, + "discipline": "générale", + "choices": ["1441", ], + "gpa": ""}, } # no gpa + + 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) diff --git a/auxiclean/unittests/test_course.py b/auxiclean/unittests/test_course.py new file mode 100644 index 0000000..ea3bbb0 --- /dev/null +++ b/auxiclean/unittests/test_course.py @@ -0,0 +1,58 @@ +from .test_selector import TestBase +from auxiclean import Selector + + +class TestCourseRaise(TestBase): + courses = {"Electro": {"code": "", # no code + "disponibilities": 1, + "discipline": "générale"}} + candidates = {"Albert A": {"maximum": 2, + "scolarity": 2, + "courses given": ["1441", "2710", "2710", + "2710", "2710", "1620"], + "nobels": 0, + "discipline": "générale", + "choices": ["1441", ], + "gpa": 2.6}} + + def test_no_code(self): + with self.assertRaises(ValueError): + self.selector = Selector(self.data_path) + + +class TestCourseNoName(TestBase): + courses = {"": {"code": "1441", # no name + "disponibilities": 1, + "discipline": "générale"}} + candidates = {"Albert A": {"maximum": 2, + "scolarity": 2, + "courses given": ["1441", "2710", "2710", + "2710", "2710", "1620"], + "nobels": 0, + "discipline": "générale", + "choices": ["1441", ], + "gpa": 2.6}} + + def test_no_name(self): + self.selector = Selector(self.data_path) + course = self.selector.excel_mgr.courses[0] + self.assertEqual(course.name, course.code) + + +class TestCourseNoDiscipline(TestBase): + courses = {"Electro": {"code": "1441", + "disponibilities": 1, + "discipline": ""}} # no discipline + candidates = {"Albert A": {"maximum": 2, + "scolarity": 2, + "courses given": ["1441", "2710", "2710", + "2710", "2710", "1620"], + "nobels": 0, + "discipline": "générale", + "choices": ["1441", ], + "gpa": 2.6}} + + 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") diff --git a/auxiclean/unittests/test_excel_manager.py b/auxiclean/unittests/test_excel_manager.py index 726f3d6..525f7ed 100644 --- a/auxiclean/unittests/test_excel_manager.py +++ b/auxiclean/unittests/test_excel_manager.py @@ -79,3 +79,34 @@ def test_distribution_sheet_already_exists(self): ws = wb["Distribution"] self.assertEqual(ws["A1"].value, safe_string) del wb + + +class TestExcelCandidateChoiceError(TestBase): + # two different courses + courses = OrderedDict({"Electro": {"code": "1441", + "disponibilities": 1, + "discipline": "générale"}, + "Astro": {"code": "2710", + "disponibilities": 1, + "discipline": "générale"}}) + # two candidates each applying for a different course. No conflict + # one of a candidate's choice not in the course list. + candidates = {"Albert A": {"maximum": 2, + "scolarity": 2, + "courses given": ["1441", "2710", "2710", + "2710", "2710", "1620"], + "nobels": 0, + "discipline": "générale", + "choices": ["1441", "1234"], # not in courses + "gpa": 2.6}, + "Claude C": {"maximum": 2, + "scolarity": 3, + "courses given": ["1651", "3131"], + "nobels": 0, + "discipline": "générale", + "choices": ["2710", ], + "gpa": 3.0}} + + def test_raise_choice_error(self): + with self.assertRaises(ValueError): + self.selector = Selector(self.data_path) diff --git a/auxiclean/unittests/test_selector.py b/auxiclean/unittests/test_selector.py index 9e47a07..60857ee 100644 --- a/auxiclean/unittests/test_selector.py +++ b/auxiclean/unittests/test_selector.py @@ -16,6 +16,7 @@ class TestBase(unittest.TestCase): candidates = {} def setUp(self): + self.selector = None # use temporary file to do the tests self.tempdir = tempfile.TemporaryDirectory() self.data_path = os.path.join(self.tempdir.name, diff --git a/tests.py b/tests.py index 9d9251a..affb052 100644 --- a/tests.py +++ b/tests.py @@ -1,24 +1,36 @@ -import sys import nose import os -modules = ["auxiclean.unittests.test_coding_standards", - "auxiclean.unittests.test_selector.TestSelector", - "auxiclean.unittests.test_selector.TestSortingSelector", - "auxiclean.unittests.test_selector.TestMultiplePosition", - "auxiclean.unittests.test_selector.TestSecondChoiceIsBetter", - "auxiclean.unittests.test_selector.TestSecondChoiceIsBetterButNoMoreDispo", - "auxiclean.unittests.test_selector.TestNoDispo", - "auxiclean.unittests.test_selector.TestNoSpaceInClass", - "auxiclean.unittests.test_selector.TestUserInput", - "auxiclean.unittests.test_selector.TestSwitch", - "auxiclean.unittests.test_selector.TestCourseGiven", - "auxiclean.unittests.test_selector.TestScholarity", - "auxiclean.unittests.test_selector.TestNobel", - "auxiclean.unittests.test_selector.TestProgram", - "auxiclean.unittests.test_selector.TestGPA", - "auxiclean.unittests.test_excel_manager.TestExcelManager"] +common = "auxiclean.unittests." + +mods = {"test_coding_standards": ["", ], + "test_selector.": ["TestSelector", + "TestSortingSelector", + "TestMultiplePosition", + "TestSecondChoiceIsBetter", + "TestSecondChoiceIsBetterButNoMoreDispo", + "TestNoDispo", + "TestNoSpaceInClass", + "TestUserInput", + "TestSwitch", + "TestCourseGiven", + "TestScholarity", + "TestNobel", + "TestProgram", + "TestGPA", ], + "test_excel_manager.": ["TestExcelManager", + "TestExcelCandidateChoiceError", ], + "test_course.": ["TestCourseRaise", + "TestCourseNoName", + "TestCourseNoDiscipline", ], + "test_candidate.": ["TestCandidateNoGPA", ], + } + +modules = [] +for test_module, test_list in mods.items(): + for test_class in test_list: + modules.append(common + test_module + test_class) def run(tests): @@ -29,5 +41,6 @@ def run(tests): os.environ["NOSE_COVER_TESTS"] = "1" nose.main(defaultTest=tests) + if __name__ == "__main__": run(modules)