Skip to content

Commit

Permalink
Use setuptools API to run unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
PytLab committed Nov 8, 2018
1 parent 7140e90 commit c511ba9
Show file tree
Hide file tree
Showing 19 changed files with 99 additions and 86 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ install:
- python setup.py install

script:
- python tests/gaft_test.py
- python setup.py test
# Test parallel running.
- mpirun -np 2 python tests/gaft_test.py
#- mpirun -np 2 python tests/gaft_test.py

1 change: 0 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
include *.md
include *.rst
recursive-include gaft *.py
recursive-include tests *.py
recursive-include example *.py

3 changes: 3 additions & 0 deletions gaft/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
import unittest
from math import sin, cos

from gaft import GAEngine
from gaft.components import BinaryIndividual
from gaft.components import Population
from gaft.operators import RouletteWheelSelection
from gaft.operators import UniformCrossover
from gaft.operators import FlipBitMutation
from .. import GAEngine
from ..components import BinaryIndividual
from ..components import Population
from ..operators import RouletteWheelSelection
from ..operators import UniformCrossover
from ..operators import FlipBitMutation


class DynamicLinearScalingTest(unittest.TestCase):
Expand Down
12 changes: 6 additions & 6 deletions tests/engine_test.py → gaft/tests/engine_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
import unittest
from math import sin, cos

from gaft import GAEngine
from gaft.components import BinaryIndividual, DecimalIndividual
from gaft.components import Population
from gaft.operators import RouletteWheelSelection
from gaft.operators import UniformCrossover
from gaft.operators import FlipBitMutation
from .. import GAEngine
from ..components import BinaryIndividual, DecimalIndividual
from ..components import Population
from ..operators import RouletteWheelSelection
from ..operators import UniformCrossover
from ..operators import FlipBitMutation


class GAEngineTest(unittest.TestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import unittest

from gaft.components import Population, BinaryIndividual
from gaft.operators import ExponentialRankingSelection
from ..components import Population, BinaryIndividual
from ..operators import ExponentialRankingSelection

class ExponentialRankingSelectionTest(unittest.TestCase):

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
import unittest
from math import sin, cos

from gaft import GAEngine
from gaft.components import BinaryIndividual
from gaft.components import Population
from gaft.operators import RouletteWheelSelection
from gaft.operators import UniformCrossover
from gaft.operators.mutation.flip_bit_mutation import FlipBitBigMutation
from .. import GAEngine
from ..components import BinaryIndividual
from ..components import Population
from ..operators import RouletteWheelSelection
from ..operators import UniformCrossover
from ..operators.mutation.flip_bit_mutation import FlipBitBigMutation

class FlipBitBigMutationTest(unittest.TestCase):

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import unittest

from gaft.components import BinaryIndividual, DecimalIndividual
from gaft.operators.mutation.flip_bit_mutation import FlipBitMutation
from ..components import BinaryIndividual, DecimalIndividual
from ..operators.mutation.flip_bit_mutation import FlipBitMutation

class FlipBitMutationTest(unittest.TestCase):

Expand Down
2 changes: 1 addition & 1 deletion tests/individual_test.py → gaft/tests/individual_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import unittest

from gaft.components import BinaryIndividual
from ..components import BinaryIndividual

class IndividualTest(unittest.TestCase):

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
53 changes: 53 additions & 0 deletions gaft/tests/test_all.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

''' Module for all test in ga.py
'''

import unittest

from .individual_test import IndividualTest
from .population_test import PopulationTest
from .roulette_wheel_selection_test import RouletteWheelSelectionTest
from .uniform_crossover_test import UniformCrossoverTest
from .flip_bit_mutation_test import FlipBitMutationTest
from .mpiutil_test import MPIUtilTest
from .engine_test import GAEngineTest
from .tournament_selection_test import TournamentSelectionTest
from .linear_ranking_selection_test import LinearRankingSelectionTest
from .exponential_ranking_selection_test import ExponentialRankingSelectionTest
from .linear_scaling_test import LinearScalingTest
from .dynamic_linear_scaling_test import DynamicLinearScalingTest
from .flip_bit_big_mutation_test import FlipBitBigMutationTest

def suite():
''' Generate test suite for all test cases in GAFT
'''
test_cases = [
IndividualTest,
PopulationTest,
RouletteWheelSelectionTest,
UniformCrossoverTest,
FlipBitMutationTest,
MPIUtilTest,
GAEngineTest,
TournamentSelectionTest,
LinearRankingSelectionTest,
ExponentialRankingSelectionTest,
LinearScalingTest,
DynamicLinearScalingTest,
FlipBitBigMutationTest
]

test_suite = unittest.TestSuite([
unittest.TestLoader().loadTestsFromTestCase(tc) for tc in test_cases
])

return test_suite

if '__main__' == __name__:
result = unittest.TextTestRunner(verbosity=2).run(suite())

if result.errors or result.failures:
raise ValueError('Get erros and failures')

File renamed without changes.
File renamed without changes.
31 changes: 18 additions & 13 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,22 @@
'Programming Language :: Python :: 3.5',
]

setup(author=author,
author_email=author_email,
description=description,
license=license,
long_description=long_description,
install_requires=install_requires,
maintainer=maintainer,
name=name,
packages=find_packages(),
platforms=platforms,
url=url,
download_url=download_url,
version=version)
test_suite = 'gaft.tests.test_all'

setup(
author=author,
author_email=author_email,
description=description,
license=license,
long_description=long_description,
install_requires=install_requires,
maintainer=maintainer,
name=name,
packages=find_packages(),
platforms=platforms,
url=url,
download_url=download_url,
version=version,
test_suite=test_suite
)

47 changes: 0 additions & 47 deletions tests/gaft_test.py

This file was deleted.

0 comments on commit c511ba9

Please sign in to comment.