Skip to content

Commit

Permalink
Switching testing to pytest
Browse files Browse the repository at this point in the history
- removed tests.py unnecessary file
- switch to pytest everywhere
- fixed unittests after new errors where added
  • Loading branch information
fgoudreault committed Aug 25, 2017
1 parent e422ec6 commit f39b908
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 78 deletions.
2 changes: 1 addition & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ dist
# ##########
.coverage
cover/
cache/
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]] &&
Expand Down
26 changes: 14 additions & 12 deletions auxiclean/unittests/test_coding_standards.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
import pep8
import os
import auxiclean
from nose.tools import assert_equal
import unittest


# Add pep8 codes to ignore below
PEP8_ADDITIONAL_IGNORE = []
# add files to ignore below
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)
3 changes: 2 additions & 1 deletion auxiclean/unittests/test_excel_manager.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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)
32 changes: 16 additions & 16 deletions auxiclean/unittests/test_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -497,15 +497,15 @@ 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,
"gpa": 2.0,
"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.
Expand Down
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
46 changes: 0 additions & 46 deletions tests.py

This file was deleted.

0 comments on commit f39b908

Please sign in to comment.