Completed
Pull Request — master (#43)
by Wojtek
06:31
created

TestParticle.setUp()   B

Complexity

Conditions 5

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 17
rs 8.5454
cc 5
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
from grortir.main.pso.velocity_calculator import VelocityCalculator
9
10
11
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...
12
    def setUp(self):
13
        self.particle_mock = Mock()
14
        self.stages = [Mock(), Mock()]
15
        self.position_updaters = {stage: Mock() for stage in self.stages}
16
        self.velocity_calculators = {stage: Mock() for stage in self.stages}
17
        for i in range(len(self.stages)):
18
            stage = self.stages[i]
19
            self.velocity_calculators[
20
                stage].calculate_initial_velocity.return_value = 0.01 * (i + 1)
21
        self.particle_mock.stages = self.stages
22
        self.particle_mock.position_updaters = self.position_updaters
23
        self.particle_mock.velocity_calculators = self.velocity_calculators
24
        self.particle_mock.current_velocities = {}
25
        self.particle_mock.current_quality = {stage: 100 for stage in
26
                                              self.stages}
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)
38
        self.assertIsNotNone(particle)
39
        self.assertEqual(particle.best_quality, np.inf)
40
41
    def test__set_initial_positons(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...
42
        Particle._set_initial_positions(self.particle_mock)
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...
43
        for stage in self.stages:
44
            self.position_updaters[
45
                stage].set_initial_control_params.assert_any_call()
46
47
    def test__set_initial_velocities(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...
48
        Particle._set_initial_velocities(self.particle_mock)
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...
49
        i = 0
50
        for stage in self.stages:
51
            self.assertEqual(self.particle_mock.current_velocities[stage],
52
                             0.01 * (i + 1))
53
            i += 1
54
55
    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...
56
        Particle.initialize(self.particle_mock)
57
        for stage in self.stages:
58
            self.assertEqual(self.particle_mock.position_updaters[stage].stage,
59
                             stage)
60
            self.assertIsInstance(self.particle_mock.position_updaters[stage],
61
                                  PositionUpdater)
62
            self.assertEqual(
63
                self.particle_mock.velocity_calculators[stage].stage,
64
                stage)
65
            self.assertIsInstance(
66
                self.particle_mock.velocity_calculators[stage],
67
                VelocityCalculator)
68
        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...
69
        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...
70
71
    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...
72
        Particle.update_values(self.particle_mock)
73
        self.particle_mock.update_input_vectors.assert_any_call()
74
        self.particle_mock.calculate_current_quality.assert_any_call()
75
        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...
76