diff --git a/.travis.yml b/.travis.yml index caff68e..117eb4c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/MANIFEST.in b/MANIFEST.in index 75f84c3..cfc83ed 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,6 +1,5 @@ include *.md include *.rst recursive-include gaft *.py -recursive-include tests *.py recursive-include example *.py diff --git a/gaft/tests/__init__.py b/gaft/tests/__init__.py new file mode 100644 index 0000000..3a1213c --- /dev/null +++ b/gaft/tests/__init__.py @@ -0,0 +1,3 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + diff --git a/tests/dynamic_linear_scaling_test.py b/gaft/tests/dynamic_linear_scaling_test.py similarity index 83% rename from tests/dynamic_linear_scaling_test.py rename to gaft/tests/dynamic_linear_scaling_test.py index 7786ce2..76c826a 100644 --- a/tests/dynamic_linear_scaling_test.py +++ b/gaft/tests/dynamic_linear_scaling_test.py @@ -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): diff --git a/tests/engine_test.py b/gaft/tests/engine_test.py similarity index 88% rename from tests/engine_test.py rename to gaft/tests/engine_test.py index 5f76757..5facce0 100644 --- a/tests/engine_test.py +++ b/gaft/tests/engine_test.py @@ -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): diff --git a/tests/exponential_ranking_selection_test.py b/gaft/tests/exponential_ranking_selection_test.py similarity index 89% rename from tests/exponential_ranking_selection_test.py rename to gaft/tests/exponential_ranking_selection_test.py index c3e801e..e59df75 100644 --- a/tests/exponential_ranking_selection_test.py +++ b/gaft/tests/exponential_ranking_selection_test.py @@ -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): diff --git a/tests/flip_bit_big_mutation_test.py b/gaft/tests/flip_bit_big_mutation_test.py similarity index 81% rename from tests/flip_bit_big_mutation_test.py rename to gaft/tests/flip_bit_big_mutation_test.py index cd91145..893d294 100644 --- a/tests/flip_bit_big_mutation_test.py +++ b/gaft/tests/flip_bit_big_mutation_test.py @@ -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): diff --git a/tests/flip_bit_mutation_test.py b/gaft/tests/flip_bit_mutation_test.py similarity index 91% rename from tests/flip_bit_mutation_test.py rename to gaft/tests/flip_bit_mutation_test.py index f56ca97..6cf1487 100644 --- a/tests/flip_bit_mutation_test.py +++ b/gaft/tests/flip_bit_mutation_test.py @@ -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): diff --git a/tests/individual_test.py b/gaft/tests/individual_test.py similarity index 98% rename from tests/individual_test.py rename to gaft/tests/individual_test.py index ad091b0..fe15b0f 100644 --- a/tests/individual_test.py +++ b/gaft/tests/individual_test.py @@ -6,7 +6,7 @@ import unittest -from gaft.components import BinaryIndividual +from ..components import BinaryIndividual class IndividualTest(unittest.TestCase): diff --git a/tests/linear_ranking_selection_test.py b/gaft/tests/linear_ranking_selection_test.py similarity index 100% rename from tests/linear_ranking_selection_test.py rename to gaft/tests/linear_ranking_selection_test.py diff --git a/tests/linear_scaling_test.py b/gaft/tests/linear_scaling_test.py similarity index 100% rename from tests/linear_scaling_test.py rename to gaft/tests/linear_scaling_test.py diff --git a/tests/mpiutil_test.py b/gaft/tests/mpiutil_test.py similarity index 100% rename from tests/mpiutil_test.py rename to gaft/tests/mpiutil_test.py diff --git a/tests/population_test.py b/gaft/tests/population_test.py similarity index 100% rename from tests/population_test.py rename to gaft/tests/population_test.py diff --git a/tests/roulette_wheel_selection_test.py b/gaft/tests/roulette_wheel_selection_test.py similarity index 100% rename from tests/roulette_wheel_selection_test.py rename to gaft/tests/roulette_wheel_selection_test.py diff --git a/gaft/tests/test_all.py b/gaft/tests/test_all.py new file mode 100644 index 0000000..13b941b --- /dev/null +++ b/gaft/tests/test_all.py @@ -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') + diff --git a/tests/tournament_selection_test.py b/gaft/tests/tournament_selection_test.py similarity index 100% rename from tests/tournament_selection_test.py rename to gaft/tests/tournament_selection_test.py diff --git a/tests/uniform_crossover_test.py b/gaft/tests/uniform_crossover_test.py similarity index 100% rename from tests/uniform_crossover_test.py rename to gaft/tests/uniform_crossover_test.py diff --git a/setup.py b/setup.py index ed5837f..09ee984 100644 --- a/setup.py +++ b/setup.py @@ -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 +) diff --git a/tests/gaft_test.py b/tests/gaft_test.py deleted file mode 100644 index 97f727f..0000000 --- a/tests/gaft_test.py +++ /dev/null @@ -1,47 +0,0 @@ -#!/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(): - test_suite = unittest.TestSuite([ - unittest.TestLoader().loadTestsFromTestCase(IndividualTest), - unittest.TestLoader().loadTestsFromTestCase(PopulationTest), - unittest.TestLoader().loadTestsFromTestCase(RouletteWheelSelectionTest), - unittest.TestLoader().loadTestsFromTestCase(UniformCrossoverTest), - unittest.TestLoader().loadTestsFromTestCase(FlipBitMutationTest), - unittest.TestLoader().loadTestsFromTestCase(MPIUtilTest), - unittest.TestLoader().loadTestsFromTestCase(GAEngineTest), - unittest.TestLoader().loadTestsFromTestCase(TournamentSelectionTest), - unittest.TestLoader().loadTestsFromTestCase(LinearRankingSelectionTest), - unittest.TestLoader().loadTestsFromTestCase(ExponentialRankingSelectionTest), - unittest.TestLoader().loadTestsFromTestCase(LinearScalingTest), - unittest.TestLoader().loadTestsFromTestCase(DynamicLinearScalingTest), - unittest.TestLoader().loadTestsFromTestCase(FlipBitBigMutationTest), - ]) - - 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') -