TestSwarm   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
dl 0
loc 70
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A test_constructor() 0 5 1
A test__update_best_particle_2() 0 10 1
A test__update_velocieties() 0 6 1
A test__update_best_particle_1() 0 10 1
A setUp() 0 13 1
A test_do_single_iteration() 0 15 1
A test_initialize() 0 4 1
1
from unittest import TestCase
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
2
3
import numpy as np
0 ignored issues
show
Configuration introduced by
The import numpy could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
4
import unittest.mock as mo
5
6
from grortir.main.pso.swarm import Swarm
7
8
9
class TestSwarm(TestCase):
0 ignored issues
show
Coding Style introduced by
This class should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
best-practice introduced by
Too many instance attributes (8/7)
Loading history...
10
    def setUp(self):
11
        self.stages = mo.Mock()
12
        self.process = mo.Mock()
13
        self.number_of_particles = 40
14
        self.tested_object = Swarm(self.process, self.stages,
15
                                   self.number_of_particles)
16
        self.mock_of_swarm = mo.Mock()
17
        self.mock_of_particle_1 = mo.Mock()
18
        self.mock_of_particle_2 = mo.Mock()
19
        self.mock_of_swarm.particles = [self.mock_of_particle_1,
20
                                        self.mock_of_particle_2]
21
        self.mock_of_best_particle = mo.Mock()
22
        self.mock_of_swarm.best_particle = self.mock_of_best_particle
23
24
    def test_constructor(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
25
        self.assertIsNotNone(self.tested_object)
26
        self.assertEqual(self.stages, self.tested_object.stages)
27
        self.assertEqual(self.tested_object.number_of_particles,
28
                         self.number_of_particles)
29
30
    def test_initialize(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
31
        Swarm.initialize(self.mock_of_swarm)
32
        self.mock_of_particle_1.initialize.assert_any_call()
33
        self.mock_of_particle_2.initialize.assert_any_call()
34
35
    def test_do_single_iteration(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
36
        self.mock_of_swarm.particles = [self.mock_of_particle_1,
37
                                        self.mock_of_particle_1]
38
        expected_calls_particle = [mo.call.update_values(),
39
                                   mo.call.update_values(),
40
                                   mo.call.move(), mo.call.move()]
41
        expected_calls_swarm = [mo.call._update_best_particle(),
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _update_best_particle was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
42
                                mo.call._update_velocieties()]
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _update_velocieties was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
43
44
        Swarm.do_single_iteration(self.mock_of_swarm)
45
46
        self.assertListEqual(expected_calls_particle,
47
                             self.mock_of_particle_1.method_calls)
48
        self.assertListEqual(expected_calls_swarm,
49
                             self.mock_of_swarm.method_calls)
50
51
    def test__update_best_particle_1(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
52
        self.mock_of_swarm.best_particle_quality = np.inf
53
        self.mock_of_particle_1.best_quality = 7
54
        self.mock_of_particle_2.best_quality = 6
55
56
        Swarm._update_best_particle(self.mock_of_swarm)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _update_best_particle was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
57
58
        self.assertEqual(self.mock_of_swarm.best_particle_quality, 6)
59
        self.assertEqual(self.mock_of_swarm.best_particle,
60
                         self.mock_of_particle_2)
61
62
    def test__update_best_particle_2(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
63
        self.mock_of_swarm.best_particle_quality = np.inf
64
        self.mock_of_particle_1.best_quality = 7
65
        self.mock_of_particle_2.best_quality = 8
66
67
        Swarm._update_best_particle(self.mock_of_swarm)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _update_best_particle was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
68
69
        self.assertEqual(self.mock_of_swarm.best_particle_quality, 7)
70
        self.assertEqual(self.mock_of_swarm.best_particle,
71
                         self.mock_of_particle_1)
72
73
    def test__update_velocieties(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
74
        Swarm._update_velocieties(self.mock_of_swarm)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _update_velocieties was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
75
        self.mock_of_particle_1.update_velocities.assert_called_once_with(
76
            self.mock_of_best_particle)
77
        self.mock_of_particle_2.update_velocities.assert_called_once_with(
78
            self.mock_of_best_particle)
79