TestParticle   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A test_get_the_overall_quality_po() 0 5 1
A test___init__() 0 6 1
A test_update_values() 0 5 1
A setUp() 0 18 3
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
from unittest.mock import Mock
3
4
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...
5
6
from grortir.main.pso.particle import Particle
7
from grortir.main.pso.position_updater import PositionUpdater
8
9
10
class TestParticle(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...
11
    def setUp(self):
12
        self.particle_mock = Mock()
13
        self.stages = [Mock(), Mock()]
14
        self.position_updater = Mock()
15
        self.velocity_calculator = Mock()
16
        for i in range(len(self.stages)):
17
            self.velocity_calculator. \
18
                calculate_initial_velocity.return_value = 0.01 * (i + 1)
19
        self.particle_mock.stages = self.stages
20
        self.particle_mock.position_updater = self.position_updater
21
        self.particle_mock.velocity_calculator = self.velocity_calculator
22
        self.particle_mock.current_velocities = {}
23
        self.particle_mock.current_quality = {stage: 100 for stage in
24
                                              self.stages}
25
        self.particle_mock.current_control_params = {}
26
        self.particle_mock.current_input = {}
27
        self.process = Mock()
28
        self.particle_mock.process = self.process
29
30
    def test_get_the_overall_quality_po(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
        particle_mock = Mock()
32
        particle_mock.current_quality = {'a': 2, 'b': 3, 'c': -3.1234}
33
        result = Particle.get_the_overall_quality(particle_mock)
34
        self.assertEqual(result, 3)
35
36
    def test___init__(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...
37
        particle = Particle(self.stages, self.process, 7)
38
        self.assertIsInstance(particle.position_updater,
39
                              PositionUpdater)
40
        self.assertIsNotNone(particle)
41
        self.assertEqual(particle.best_quality, np.inf)
42
43
    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...
44
        Particle.initialize(self.particle_mock)
45
        self.particle_mock._set_initial_positions.assart_any_call()
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _set_initial_positions 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...
46
        self.particle_mock._set_initial_velocities.assart_any_call()
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _set_initial_velocities 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...
47
48
    def test_update_values(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...
49
        Particle.update_values(self.particle_mock)
50
        self.particle_mock.update_input_vectors.assert_any_call()
51
        self.particle_mock.calculate_current_quality.assert_any_call()
52
        self.particle_mock._update_best_position.assert_any_call()
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _update_best_position 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...
53