diff --git a/.appveyor.yml b/.appveyor.yml index 8cfadbc..d6bc69c 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -14,7 +14,7 @@ install: - activate test-environment - python setup.py develop test_script: - - python tests.py + - pytest # build is done in build_script build: off build_script: diff --git a/.gitignore b/.gitignore index 22383ce..f092b9a 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,4 @@ dist # ########## .coverage cover/ +cache/ diff --git a/.travis.yml b/.travis.yml index bd191b1..66e1d72 100644 --- a/.travis.yml +++ b/.travis.yml @@ -43,7 +43,7 @@ install: - python setup.py develop # execute tests script: - - python tests.py + - pytest after_success: # report coverage in coveralls only for linux build with python 3.6 - if ([[ "$TRAVIS_PYTHON_VERSION" == "3.6" ]] && diff --git a/auxiclean/unittests/test_coding_standards.py b/auxiclean/unittests/test_coding_standards.py index 9f3dd92..5fddb8b 100644 --- a/auxiclean/unittests/test_coding_standards.py +++ b/auxiclean/unittests/test_coding_standards.py @@ -1,7 +1,8 @@ import pep8 import os import auxiclean -from nose.tools import assert_equal +import unittest + # Add pep8 codes to ignore below PEP8_ADDITIONAL_IGNORE = [] @@ -9,18 +10,19 @@ EXCLUDE_FILES = [] -def test_pep8_conformance(): +class TestPEP8(unittest.TestCase): + def test_pep8_conformance(self): - dirs = [] - dirname = os.path.dirname(auxiclean.__file__) - dirs.append(dirname) + dirs = [] + dirname = os.path.dirname(auxiclean.__file__) + dirs.append(dirname) - pep8style = pep8.StyleGuide() + pep8style = pep8.StyleGuide() - # Extends the number of pep8 guidelines which are not checked - pep8style.options.ignore += tuple(PEP8_ADDITIONAL_IGNORE) - pep8style.options.exclude.extend(EXCLUDE_FILES) + # Extends the number of pep8 guidelines which are not checked + pep8style.options.ignore += tuple(PEP8_ADDITIONAL_IGNORE) + pep8style.options.exclude.extend(EXCLUDE_FILES) - result = pep8style.check_files(dirs) - msg = "Found code syntax errors (and warnings)!" - assert_equal(result.total_errors, 0, msg) + result = pep8style.check_files(dirs) + msg = "Found code syntax errors (and warnings)!" + self.assertEqual(result.total_errors, 0, msg=msg) diff --git a/auxiclean/unittests/test_excel_manager.py b/auxiclean/unittests/test_excel_manager.py index 525f7ed..359cb44 100644 --- a/auxiclean/unittests/test_excel_manager.py +++ b/auxiclean/unittests/test_excel_manager.py @@ -1,6 +1,7 @@ from .test_selector import TestBase from openpyxl import load_workbook from auxiclean import Selector +from auxiclean.exceptions import ExcelError from collections import OrderedDict import warnings @@ -108,5 +109,5 @@ class TestExcelCandidateChoiceError(TestBase): "gpa": 3.0}} def test_raise_choice_error(self): - with self.assertRaises(ValueError): + with self.assertRaises(ExcelError): self.selector = Selector(self.data_path) diff --git a/auxiclean/unittests/test_selector.py b/auxiclean/unittests/test_selector.py index 132204d..cc83cd9 100644 --- a/auxiclean/unittests/test_selector.py +++ b/auxiclean/unittests/test_selector.py @@ -150,7 +150,7 @@ class TestMultiplePosition(TestBase): "discipline": "générale"}, "Astro": {"code": "2710", "disponibilities": 1, - "discipline": "astro"}} + "discipline": "astrophysique"}} # one candidate applying for two different course. # if the candidate is the best suited, he gets both choice # assuming he has two disponibilities @@ -332,7 +332,7 @@ class TestSwitch(TestBase): "nobels": 0, "courses given": ["2710", "2710", "1441", "1441"], - "discipline": "particules"}} + "discipline": "générale"}} def test_switch(self): self.selector = Selector(self.data_path, loglevel=self.loglevel) @@ -354,14 +354,14 @@ class TestCourseGiven(TestBase): "gpa": 2.0, "nobels": 2, "courses given": ["1441", ], - "discipline": "astrophysique"}, + "discipline": "générale"}, "Claude C": {"choices": ["1441", ], "maximum": 1, "scolarity": 2, "gpa": 2.0, "nobels": 2, "courses given": ["1441", "2710", ], - "discipline": "particules"}} + "discipline": "générale"}} def test_course_given(self): self.selector = Selector(self.data_path) @@ -370,7 +370,7 @@ def test_course_given(self): self.assertEqual(dist["1441"][0].name, "Claude C") -class TestScholarity(TestBase): +class TestScolarity(TestBase): # one course for two person courses = {"Electro": {"code": "1441", "disponibilities": 1, @@ -382,16 +382,16 @@ class TestScholarity(TestBase): "gpa": 2.0, "nobels": 2, "courses given": ["1441", "1652", ], - "discipline": "astrophysique"}, + "discipline": "générale"}, "Claude C": {"choices": ["1441", ], "maximum": 1, "scolarity": 3, "gpa": 2.0, "nobels": 2, "courses given": ["1441", "2710", ], - "discipline": "particules"}} + "discipline": "générale"}} - def test_scholarity(self): + def test_scolarity(self): self.selector = Selector(self.data_path) # results dist = self.selector.distribution @@ -410,14 +410,14 @@ class TestNobel(TestBase): "gpa": 2.0, "nobels": 2, "courses given": ["1441", "1652", ], - "discipline": "astrophysique"}, + "discipline": "générale"}, "Claude C": {"choices": ["1441", ], "maximum": 1, "scolarity": 2, "gpa": 2.0, "nobels": 3, "courses given": ["1441", "2710", ], - "discipline": "particules"}} + "discipline": "générale"}} def test_nobel(self): self.selector = Selector(self.data_path) @@ -426,7 +426,7 @@ def test_nobel(self): self.assertEqual(dist["1441"][0].name, "Claude C") -class TestProgram(TestBase): +class TestDiscipline(TestBase): # one course for two person courses = {"Astro": {"code": "2710", "disponibilities": 1, @@ -438,7 +438,7 @@ class TestProgram(TestBase): "gpa": 2.0, "nobels": 2, "courses given": ["1441", "1652", ], - "discipline": "particules"}, + "discipline": "générale"}, "Claude C": {"choices": ["2710", ], "maximum": 1, "scolarity": 2, @@ -467,14 +467,14 @@ class TestGPA(TestBase): "gpa": 2.0, "nobels": 2, "courses given": ["1441", "1652", ], - "discipline": "astrophysique"}, + "discipline": "générale"}, "Claude C": {"choices": ["1441", ], "maximum": 1, "scolarity": 2, "gpa": 3.0, "nobels": 2, "courses given": ["1441", "2710", ], - "discipline": "particules"}} + "discipline": "générale"}} def test_gpa(self): self.selector = Selector(self.data_path, loglevel=self.loglevel) @@ -497,7 +497,7 @@ class TestUserInput(TestBase): "gpa": 2.0, "nobels": 2, "courses given": ["1441", "1652", ], - "discipline": "astrophysique"}), + "discipline": "générale"}), ("Bernard B", {"choices": ["1441", ], "maximum": 1, "scolarity": 2, @@ -505,7 +505,7 @@ class TestUserInput(TestBase): "nobels": 2, "courses given": ["1441", "2710", ], - "discipline": "particules"})] + "discipline": "générale"})] def test_user_input_simple(self, user_input_mock): # test that user input chooses first candidate over second. diff --git a/setup.cfg b/setup.cfg index 1583bda..0190436 100644 --- a/setup.cfg +++ b/setup.cfg @@ -5,3 +5,6 @@ versionfile_source = auxiclean/_version.py versionfile_build = auxiclean/_version.py tag_prefix = parentdir_prefix = auxiclean + +[tool:pytest] +addopts = -ra -v --cov=auxiclean --tb=long diff --git a/setup.py b/setup.py index f02bfdb..f892708 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,7 @@ def win_pip_install(package, install_list): ] -develop_packages = ["nose", "pep8", "coverage"] +develop_packages = ["pytest-cov", "pep8", "coverage"] print("Installing auxiclean, the following packages are required:", install_packages) diff --git a/tests.py b/tests.py deleted file mode 100644 index affb052..0000000 --- a/tests.py +++ /dev/null @@ -1,46 +0,0 @@ -import nose -import os - - -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): - os.environ["NOSE_WITH_COVERAGE"] = "1" - os.environ["NOSE_COVER_PACKAGE"] = "auxiclean" - os.environ["NOSE_COVER_HTML"] = "1" - os.environ["NOSE_COVER_ERASE"] = "1" - os.environ["NOSE_COVER_TESTS"] = "1" - nose.main(defaultTest=tests) - - -if __name__ == "__main__": - run(modules)