Skip to content

Commit

Permalink
Added tests for checkups
Browse files Browse the repository at this point in the history
  • Loading branch information
fgoudreault committed Jun 22, 2017
1 parent f438f48 commit 91a7614
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 17 deletions.
33 changes: 33 additions & 0 deletions auxiclean/unittests/test_candidate.py
Original file line number Diff line number Diff line change
@@ -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)
58 changes: 58 additions & 0 deletions auxiclean/unittests/test_course.py
Original file line number Diff line number Diff line change
@@ -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")
31 changes: 31 additions & 0 deletions auxiclean/unittests/test_excel_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 1 addition & 0 deletions auxiclean/unittests/test_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
47 changes: 30 additions & 17 deletions tests.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -29,5 +41,6 @@ def run(tests):
os.environ["NOSE_COVER_TESTS"] = "1"
nose.main(defaultTest=tests)


if __name__ == "__main__":
run(modules)

0 comments on commit 91a7614

Please sign in to comment.