Test Failed
Push — master ( 21460f...e380d0 )
by Tomaz
01:48
created

runners/winrm_runner/tests/unit/test_winrm_base.py (105 issues)

1
# Licensed to the StackStorm, Inc ('StackStorm') under one or more
2
# contributor license agreements.  See the NOTICE file distributed with
3
# this work for additional information regarding copyright ownership.
4
# The ASF licenses this file to You under the Apache License, Version 2.0
5
# (the "License"); you may not use this file except in compliance with
6
# the License.  You may obtain a copy of the License at
7
#
8
#     http://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
15
16
from __future__ import absolute_import
17
18
import collections
19
import time
20
import mock
21
from base64 import b64encode
22
from winrm import Response
23
from winrm.exceptions import WinRMOperationTimeoutError
24
25
from st2common.runners.base import ActionRunner
26
from st2tests.base import RunnerTestCase
27
from winrm_runner.winrm_base import WinRmBaseRunner, WinRmRunnerTimoutError
28
from winrm_runner.winrm_base import WINRM_TIMEOUT_EXIT_CODE
29
from winrm_runner.winrm_base import PS_ESCAPE_SEQUENCES
30
from winrm_runner import winrm_ps_command_runner
31
32
33
class WinRmBaseTestCase(RunnerTestCase):
34
35
    def setUp(self):
36
        super(WinRmBaseTestCase, self).setUpClass()
37
        self._runner = winrm_ps_command_runner.get_runner()
38
39
    def _init_runner(self):
40
        runner_parameters = {'host': '[email protected]',
41
                             'username': '[email protected]',
42
                             'password': 'xyz987'}
43
        self._runner.runner_parameters = runner_parameters
44
        self._runner.pre_run()
45
46
    def test_win_rm_runner_timout_error(self):
47
        error = WinRmRunnerTimoutError('test_response')
48
        self.assertIsInstance(error, Exception)
49
        self.assertEquals(error.response, 'test_response')
50
        with self.assertRaises(WinRmRunnerTimoutError):
51
            raise WinRmRunnerTimoutError('test raising')
52
53
    def test_init(self):
54
        runner = winrm_ps_command_runner.WinRmPsCommandRunner('abcdef')
55
        self.assertIsInstance(runner, WinRmBaseRunner)
56
        self.assertIsInstance(runner, ActionRunner)
57
        self.assertEquals(runner.runner_id, "abcdef")
58
59
    @mock.patch('winrm_runner.winrm_base.ActionRunner.pre_run')
60
    def test_pre_run(self, mock_pre_run):
61
        runner_parameters = {'host': '[email protected]',
62
                             'username': '[email protected]',
63
                             'password': 'abc123',
64
                             'timeout': 99,
65
                             'port': 1234,
66
                             'scheme': 'http',
67
                             'transport': 'ntlm',
68
                             'verify_ssl_cert': False,
69
                             'cwd': 'C:\\Test',
70
                             'env': {'TEST_VAR': 'TEST_VALUE'},
71
                             'kwarg_op': '/'}
72
        self._runner.runner_parameters = runner_parameters
73
        self._runner.pre_run()
74
        mock_pre_run.assert_called_with()
75
        self.assertEquals(self._runner._host, '[email protected]')
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _host 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
        self.assertEquals(self._runner._username, '[email protected]')
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _username 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...
77
        self.assertEquals(self._runner._password, 'abc123')
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _password 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...
78
        self.assertEquals(self._runner._timeout, 99)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _timeout 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...
79
        self.assertEquals(self._runner._read_timeout, 100)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _read_timeout 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...
80
        self.assertEquals(self._runner._port, 1234)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _port 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...
81
        self.assertEquals(self._runner._scheme, 'http')
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _scheme 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...
82
        self.assertEquals(self._runner._transport, 'ntlm')
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _transport 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...
83
        self.assertEquals(self._runner._winrm_url, 'http://[email protected]:1234/wsman')
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _winrm_url 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...
84
        self.assertEquals(self._runner._verify_ssl, False)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _verify_ssl 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...
85
        self.assertEquals(self._runner._server_cert_validation, 'ignore')
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _server_cert_validation 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...
86
        self.assertEquals(self._runner._cwd, 'C:\\Test')
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _cwd 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...
87
        self.assertEquals(self._runner._env, {'TEST_VAR': 'TEST_VALUE'})
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _env 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...
88
        self.assertEquals(self._runner._kwarg_op, '/')
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _kwarg_op 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...
89
90
    @mock.patch('winrm_runner.winrm_base.ActionRunner.pre_run')
91
    def test_pre_run_defaults(self, mock_pre_run):
92
        runner_parameters = {'host': '[email protected]',
93
                             'username': '[email protected]',
94
                             'password': 'abc123'}
95
        self._runner.runner_parameters = runner_parameters
96
        self._runner.pre_run()
97
        mock_pre_run.assert_called_with()
98
        self.assertEquals(self._runner._host, '[email protected]')
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _host 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...
99
        self.assertEquals(self._runner._username, '[email protected]')
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _username 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...
100
        self.assertEquals(self._runner._password, 'abc123')
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _password 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...
101
        self.assertEquals(self._runner._timeout, 60)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _timeout 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...
102
        self.assertEquals(self._runner._read_timeout, 61)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _read_timeout 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...
103
        self.assertEquals(self._runner._port, 5986)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _port 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...
104
        self.assertEquals(self._runner._scheme, 'https')
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _scheme 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...
105
        self.assertEquals(self._runner._transport, 'ntlm')
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _transport 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...
106
        self.assertEquals(self._runner._winrm_url, 'https://[email protected]:5986/wsman')
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _winrm_url 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...
107
        self.assertEquals(self._runner._verify_ssl, True)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _verify_ssl 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...
108
        self.assertEquals(self._runner._server_cert_validation, 'validate')
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _server_cert_validation 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...
109
        self.assertEquals(self._runner._cwd, None)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _cwd 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...
110
        self.assertEquals(self._runner._env, {})
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _env 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...
111
        self.assertEquals(self._runner._kwarg_op, '-')
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _kwarg_op 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...
112
113
    @mock.patch('winrm_runner.winrm_base.ActionRunner.pre_run')
114
    def test_pre_run_5985_force_http(self, mock_pre_run):
115
        runner_parameters = {'host': '[email protected]',
116
                             'username': '[email protected]',
117
                             'password': 'abc123',
118
                             'port': 5985,
119
                             'scheme': 'https'}
120
        self._runner.runner_parameters = runner_parameters
121
        self._runner.pre_run()
122
        mock_pre_run.assert_called_with()
123
        self.assertEquals(self._runner._host, '[email protected]')
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _host 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...
124
        self.assertEquals(self._runner._username, '[email protected]')
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _username 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...
125
        self.assertEquals(self._runner._password, 'abc123')
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _password 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...
126
        self.assertEquals(self._runner._timeout, 60)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _timeout 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...
127
        self.assertEquals(self._runner._read_timeout, 61)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _read_timeout 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...
128
        # ensure port is still 5985
129
        self.assertEquals(self._runner._port, 5985)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _port 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...
130
        # ensure scheme is set back to http
131
        self.assertEquals(self._runner._scheme, 'http')
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _scheme 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...
132
        self.assertEquals(self._runner._transport, 'ntlm')
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _transport 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...
133
        self.assertEquals(self._runner._winrm_url, 'http://[email protected]:5985/wsman')
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _winrm_url 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...
134
        self.assertEquals(self._runner._verify_ssl, True)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _verify_ssl 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...
135
        self.assertEquals(self._runner._server_cert_validation, 'validate')
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _server_cert_validation 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...
136
        self.assertEquals(self._runner._cwd, None)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _cwd 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...
137
        self.assertEquals(self._runner._env, {})
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _env 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...
138
        self.assertEquals(self._runner._kwarg_op, '-')
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _kwarg_op 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...
139
140
    @mock.patch('winrm_runner.winrm_base.ActionRunner.pre_run')
141
    def test_pre_run_none_env(self, mock_pre_run):
142
        runner_parameters = {'host': '[email protected]',
143
                             'username': '[email protected]',
144
                             'password': 'abc123',
145
                             'env': None}
146
        self._runner.runner_parameters = runner_parameters
147
        self._runner.pre_run()
148
        mock_pre_run.assert_called_with()
149
        # ensure that env is set to {} even though we passed in None
150
        self.assertEquals(self._runner._env, {})
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _env 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...
151
152
    @mock.patch('winrm_runner.winrm_base.ActionRunner.pre_run')
153
    def test_pre_run_ssl_verify_true(self, mock_pre_run):
154
        runner_parameters = {'host': '[email protected]',
155
                             'username': '[email protected]',
156
                             'password': 'abc123',
157
                             'verify_ssl_cert': True}
158
        self._runner.runner_parameters = runner_parameters
159
        self._runner.pre_run()
160
        mock_pre_run.assert_called_with()
161
        self.assertEquals(self._runner._verify_ssl, True)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _verify_ssl 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...
162
        self.assertEquals(self._runner._server_cert_validation, 'validate')
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _server_cert_validation 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...
163
164
    @mock.patch('winrm_runner.winrm_base.ActionRunner.pre_run')
165
    def test_pre_run_ssl_verify_false(self, mock_pre_run):
166
        runner_parameters = {'host': '[email protected]',
167
                             'username': '[email protected]',
168
                             'password': 'abc123',
169
                             'verify_ssl_cert': False}
170
        self._runner.runner_parameters = runner_parameters
171
        self._runner.pre_run()
172
        mock_pre_run.assert_called_with()
173
        self.assertEquals(self._runner._verify_ssl, False)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _verify_ssl 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...
174
        self.assertEquals(self._runner._server_cert_validation, 'ignore')
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _server_cert_validation 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...
175
176
    @mock.patch('winrm_runner.winrm_base.Session')
177
    def test_create_session(self, mock_session):
178
        self._runner._winrm_url = 'https://[email protected]:5986/wsman'
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _winrm_url 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...
179
        self._runner._username = '[email protected]'
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _username 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...
180
        self._runner._password = 'abc123'
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _password 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...
181
        self._runner._transport = 'ntlm'
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _transport 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...
182
        self._runner._server_cert_validation = 'validate'
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _server_cert_validation 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...
183
        self._runner._timeout = 60
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _timeout 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...
184
        self._runner._read_timeout = 61
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _read_timeout 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...
185
        mock_session.return_value = "session"
186
187
        result = self._runner._create_session()
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _create_session 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...
188
        self.assertEquals(result, "session")
189
        mock_session.assert_called_with('https://[email protected]:5986/wsman',
190
                                        auth=('[email protected]', 'abc123'),
191
                                        transport='ntlm',
192
                                        server_cert_validation='validate',
193
                                        operation_timeout_sec=60,
194
                                        read_timeout_sec=61)
195
196
    def test_get_command_output(self):
197
        self._runner._timeout = 0
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _timeout 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...
198
        mock_protocol = mock.MagicMock()
199
        mock_protocol._raw_get_command_output.side_effect = [
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _raw_get_command_output 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...
200
            (b'output1', b'error1', 123, False),
201
            (b'output2', b'error2', 456, False),
202
            (b'output3', b'error3', 789, True)
203
        ]
204
205
        result = self._runner._winrm_get_command_output(mock_protocol, 567, 890)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _winrm_get_command_output 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...
206
207
        self.assertEquals(result, (b'output1output2output3', b'error1error2error3', 789))
208
        mock_protocol._raw_get_command_output.assert_has_calls = [
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _raw_get_command_output 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...
209
            mock.call(567, 890),
210
            mock.call(567, 890),
211
            mock.call(567, 890)
212
        ]
213
214
    def test_get_command_output_timeout(self):
215
        self._runner._timeout = 0.1
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _timeout 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...
216
217
        mock_protocol = mock.MagicMock()
218
219
        def sleep_for_timeout(*args, **kwargs):
220
            time.sleep(0.2)
221
            return (b'output1', b'error1', 123, False)
222
223
        mock_protocol._raw_get_command_output.side_effect = sleep_for_timeout
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _raw_get_command_output 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...
224
225
        with self.assertRaises(WinRmRunnerTimoutError) as cm:
226
            self._runner._winrm_get_command_output(mock_protocol, 567, 890)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _winrm_get_command_output 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...
227
228
        timeout_exception = cm.exception
229
        self.assertEqual(timeout_exception.response.std_out, b'output1')
230
        self.assertEqual(timeout_exception.response.std_err, b'error1')
231
        self.assertEqual(timeout_exception.response.status_code, WINRM_TIMEOUT_EXIT_CODE)
232
        mock_protocol._raw_get_command_output.assert_called_with(567, 890)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _raw_get_command_output 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...
233
234
    def test_get_command_output_operation_timeout(self):
235
        self._runner._timeout = 0.1
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _timeout 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...
236
237
        mock_protocol = mock.MagicMock()
238
239
        def sleep_for_timeout_then_raise(*args, **kwargs):
240
            time.sleep(0.2)
241
            raise WinRMOperationTimeoutError()
242
243
        mock_protocol._raw_get_command_output.side_effect = sleep_for_timeout_then_raise
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _raw_get_command_output 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...
244
245
        with self.assertRaises(WinRmRunnerTimoutError) as cm:
246
            self._runner._winrm_get_command_output(mock_protocol, 567, 890)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _winrm_get_command_output 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...
247
248
        timeout_exception = cm.exception
249
        self.assertEqual(timeout_exception.response.std_out, b'')
250
        self.assertEqual(timeout_exception.response.std_err, b'')
251
        self.assertEqual(timeout_exception.response.status_code, WINRM_TIMEOUT_EXIT_CODE)
252
        mock_protocol._raw_get_command_output.assert_called_with(567, 890)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _raw_get_command_output 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...
253
254
    def test_winrm_run_cmd(self):
255
        mock_protocol = mock.MagicMock()
256
        mock_protocol.open_shell.return_value = 123
257
        mock_protocol.run_command.return_value = 456
258
        mock_protocol._raw_get_command_output.return_value = (b'output', b'error', 9, True)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _raw_get_command_output 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...
259
        mock_session = mock.MagicMock(protocol=mock_protocol)
260
261
        self._init_runner()
262
        result = self._runner._winrm_run_cmd(mock_session, "fake-command",
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _winrm_run_cmd 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...
263
                                             args=['arg1', 'arg2'],
264
                                             env={'PATH': 'C:\\st2\\bin'},
265
                                             cwd='C:\\st2')
266
        expected_response = Response((b'output', b'error', 9))
267
        expected_response.timeout = False
268
269
        self.assertEquals(result.__dict__, expected_response.__dict__)
270
        mock_protocol.open_shell.assert_called_with(env_vars={'PATH': 'C:\\st2\\bin'},
271
                                                    working_directory='C:\\st2')
272
        mock_protocol.run_command.assert_called_with(123, 'fake-command', ['arg1', 'arg2'])
273
        mock_protocol._raw_get_command_output.assert_called_with(123, 456)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _raw_get_command_output 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...
274
        mock_protocol.cleanup_command.assert_called_with(123, 456)
275
        mock_protocol.close_shell.assert_called_with(123)
276
277
    @mock.patch('winrm_runner.winrm_base.WinRmBaseRunner._winrm_get_command_output')
278
    def test_winrm_run_cmd_timeout(self, mock_get_command_output):
279
        mock_protocol = mock.MagicMock()
280
        mock_protocol.open_shell.return_value = 123
281
        mock_protocol.run_command.return_value = 456
282
        mock_session = mock.MagicMock(protocol=mock_protocol)
283
        mock_get_command_output.side_effect = WinRmRunnerTimoutError(Response(('', '', 5)))
284
285
        self._init_runner()
286
        result = self._runner._winrm_run_cmd(mock_session, "fake-command",
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _winrm_run_cmd 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...
287
                                             args=['arg1', 'arg2'],
288
                                             env={'PATH': 'C:\\st2\\bin'},
289
                                             cwd='C:\\st2')
290
        expected_response = Response(('', '', 5))
291
        expected_response.timeout = True
292
293
        self.assertEquals(result.__dict__, expected_response.__dict__)
294
        mock_protocol.open_shell.assert_called_with(env_vars={'PATH': 'C:\\st2\\bin'},
295
                                                    working_directory='C:\\st2')
296
        mock_protocol.run_command.assert_called_with(123, 'fake-command', ['arg1', 'arg2'])
297
        mock_protocol.cleanup_command.assert_called_with(123, 456)
298
        mock_protocol.close_shell.assert_called_with(123)
299
300
    @mock.patch('winrm_runner.winrm_base.WinRmBaseRunner._winrm_run_cmd')
301
    def test_winrm_run_ps(self, mock_run_cmd):
302
        mock_run_cmd.return_value = Response(('output', '', 3))
303
        script = "Get-ADUser stanley"
304
305
        result = self._runner._winrm_run_ps("session", script,
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _winrm_run_ps 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...
306
                                            env={'PATH': 'C:\\st2\\bin'},
307
                                            cwd='C:\\st2')
308
309
        self.assertEquals(result.__dict__,
310
                          Response(('output', '', 3)).__dict__)
311
        expected_ps = ('powershell -encodedcommand ' +
312
                       b64encode("Get-ADUser stanley".encode('utf_16_le')).decode('ascii'))
313
        mock_run_cmd.assert_called_with("session",
314
                                        expected_ps,
315
                                        env={'PATH': 'C:\\st2\\bin'},
316
                                        cwd='C:\\st2')
317
318
    @mock.patch('winrm_runner.winrm_base.WinRmBaseRunner._winrm_run_cmd')
319
    def test_winrm_run_ps_clean_stderr(self, mock_run_cmd):
320
        mock_run_cmd.return_value = Response(('output', 'error', 3))
321
        mock_session = mock.MagicMock()
322
        mock_session._clean_error_msg.return_value = 'e'
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _clean_error_msg 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...
323
        script = "Get-ADUser stanley"
324
325
        result = self._runner._winrm_run_ps(mock_session, script,
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _winrm_run_ps 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...
326
                                            env={'PATH': 'C:\\st2\\bin'},
327
                                            cwd='C:\\st2')
328
329
        self.assertEquals(result.__dict__,
330
                          Response(('output', 'e', 3)).__dict__)
331
        expected_ps = ('powershell -encodedcommand ' +
332
                       b64encode("Get-ADUser stanley".encode('utf_16_le')).decode('ascii'))
333
        mock_run_cmd.assert_called_with(mock_session,
334
                                        expected_ps,
335
                                        env={'PATH': 'C:\\st2\\bin'},
336
                                        cwd='C:\\st2')
337
        mock_session._clean_error_msg.assert_called_with('error')
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _clean_error_msg 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...
338
339
    @mock.patch('winrm.Protocol')
340
    def test_run_cmd(self, mock_protocol_init):
341
        mock_protocol = mock.MagicMock()
342
        mock_protocol._raw_get_command_output.side_effect = [
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _raw_get_command_output 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...
343
            (b'output1', b'error1', 0, False),
344
            (b'output2', b'error2', 0, False),
345
            (b'output3', b'error3', 0, True)
346
        ]
347
        mock_protocol_init.return_value = mock_protocol
348
349
        self._init_runner()
350
        result = self._runner.run_cmd("ipconfig /all")
351
        self.assertEquals(result, ('succeeded',
352
                                   {'failed': False,
353
                                    'succeeded': True,
354
                                    'return_code': 0,
355
                                    'stdout': b'output1output2output3',
356
                                    'stderr': b'error1error2error3'},
357
                                   None))
358
359
    @mock.patch('winrm.Protocol')
360
    def test_run_cmd_failed(self, mock_protocol_init):
361
        mock_protocol = mock.MagicMock()
362
        mock_protocol._raw_get_command_output.side_effect = [
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _raw_get_command_output 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...
363
            (b'output1', b'error1', 0, False),
364
            (b'output2', b'error2', 0, False),
365
            (b'output3', b'error3', 1, True)
366
        ]
367
        mock_protocol_init.return_value = mock_protocol
368
369
        self._init_runner()
370
        result = self._runner.run_cmd("ipconfig /all")
371
        self.assertEquals(result, ('failed',
372
                                   {'failed': True,
373
                                    'succeeded': False,
374
                                    'return_code': 1,
375
                                    'stdout': b'output1output2output3',
376
                                    'stderr': b'error1error2error3'},
377
                                   None))
378
379
    @mock.patch('winrm.Protocol')
380
    def test_run_cmd_timeout(self, mock_protocol_init):
381
        mock_protocol = mock.MagicMock()
382
        self._init_runner()
383
        self._runner._timeout = 0.1
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _timeout 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...
384
385
        def sleep_for_timeout_then_raise(*args, **kwargs):
386
            time.sleep(0.2)
387
            return (b'output1', b'error1', 123, False)
388
389
        mock_protocol._raw_get_command_output.side_effect = sleep_for_timeout_then_raise
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _raw_get_command_output 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...
390
        mock_protocol_init.return_value = mock_protocol
391
392
        result = self._runner.run_cmd("ipconfig /all")
393
        self.assertEquals(result, ('timeout',
394
                                   {'failed': True,
395
                                    'succeeded': False,
396
                                    'return_code': -1,
397
                                    'stdout': b'output1',
398
                                    'stderr': b'error1'},
399
                                   None))
400
401
    @mock.patch('winrm.Protocol')
402
    def test_run_ps(self, mock_protocol_init):
403
        mock_protocol = mock.MagicMock()
404
        mock_protocol._raw_get_command_output.side_effect = [
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _raw_get_command_output 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...
405
            (b'output1', b'error1', 0, False),
406
            (b'output2', b'error2', 0, False),
407
            (b'output3', b'error3', 0, True)
408
        ]
409
        mock_protocol_init.return_value = mock_protocol
410
411
        self._init_runner()
412
        result = self._runner.run_ps("Get-Location")
413
        self.assertEquals(result, ('succeeded',
414
                                   {'failed': False,
415
                                    'succeeded': True,
416
                                    'return_code': 0,
417
                                    'stdout': b'output1output2output3',
418
                                    'stderr': 'error1error2error3'},
419
                                   None))
420
421
    @mock.patch('winrm.Protocol')
422
    def test_run_ps_failed(self, mock_protocol_init):
423
        mock_protocol = mock.MagicMock()
424
        mock_protocol._raw_get_command_output.side_effect = [
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _raw_get_command_output 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...
425
            (b'output1', b'error1', 0, False),
426
            (b'output2', b'error2', 0, False),
427
            (b'output3', b'error3', 1, True)
428
        ]
429
        mock_protocol_init.return_value = mock_protocol
430
431
        self._init_runner()
432
        result = self._runner.run_ps("Get-Location")
433
        self.assertEquals(result, ('failed',
434
                                   {'failed': True,
435
                                    'succeeded': False,
436
                                    'return_code': 1,
437
                                    'stdout': b'output1output2output3',
438
                                    'stderr': 'error1error2error3'},
439
                                   None))
440
441
    @mock.patch('winrm.Protocol')
442
    def test_run_ps_timeout(self, mock_protocol_init):
443
        mock_protocol = mock.MagicMock()
444
        self._init_runner()
445
        self._runner._timeout = 0.1
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _timeout 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...
446
447
        def sleep_for_timeout_then_raise(*args, **kwargs):
448
            time.sleep(0.2)
449
            return (b'output1', b'error1', 123, False)
450
451
        mock_protocol._raw_get_command_output.side_effect = sleep_for_timeout_then_raise
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _raw_get_command_output 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...
452
        mock_protocol_init.return_value = mock_protocol
453
454
        result = self._runner.run_ps("Get-Location")
455
        self.assertEquals(result, ('timeout',
456
                                   {'failed': True,
457
                                    'succeeded': False,
458
                                    'return_code': -1,
459
                                    'stdout': b'output1',
460
                                    'stderr': 'error1'},
461
                                   None))
462
463
    def test_translate_response_success(self):
464
        response = Response(('output1', 'error1', 0))
465
        response.timeout = False
466
467
        result = self._runner._translate_response(response)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _translate_response 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...
468
        self.assertEquals(result, ('succeeded',
469
                                   {'failed': False,
470
                                    'succeeded': True,
471
                                    'return_code': 0,
472
                                    'stdout': 'output1',
473
                                    'stderr': 'error1'},
474
                                   None))
475
476
    def test_translate_response_failure(self):
477
        response = Response(('output1', 'error1', 123))
478
        response.timeout = False
479
480
        result = self._runner._translate_response(response)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _translate_response 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...
481
        self.assertEquals(result, ('failed',
482
                                   {'failed': True,
483
                                    'succeeded': False,
484
                                    'return_code': 123,
485
                                    'stdout': 'output1',
486
                                    'stderr': 'error1'},
487
488
                                   None))
489
490
    def test_translate_response_timeout(self):
491
        response = Response(('output1', 'error1', 123))
492
        response.timeout = True
493
494
        result = self._runner._translate_response(response)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _translate_response 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...
495
        self.assertEquals(result, ('timeout',
496
                                   {'failed': True,
497
                                    'succeeded': False,
498
                                    'return_code': -1,
499
                                    'stdout': 'output1',
500
                                    'stderr': 'error1'},
501
                                   None))
502
503
    def test_multireplace(self):
504
        multireplace_map = {'a': 'x',
505
                            'c': 'y',
506
                            'aaa': 'z'}
507
        result = self._runner._multireplace('aaaccaa', multireplace_map)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _multireplace 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...
508
        self.assertEquals(result, 'zyyxx')
509
510
    def test_multireplace_powershell(self):
511
        param_str = (
512
            '\n'
513
            '\r'
514
            '\t'
515
            '\a'
516
            '\b'
517
            '\f'
518
            '\v'
519
            '"'
520
            '\''
521
            '`'
522
            '\0'
523
            '$'
524
        )
525
        result = self._runner._multireplace(param_str, PS_ESCAPE_SEQUENCES)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _multireplace 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...
526
        self.assertEquals(result, (
527
            '`n'
528
            '`r'
529
            '`t'
530
            '`a'
531
            '`b'
532
            '`f'
533
            '`v'
534
            '`"'
535
            '`\''
536
            '``'
537
            '`0'
538
            '`$'
539
        ))
540
541
    def test_param_to_ps_none(self):
542
        # test None/null
543
        param = None
544
        result = self._runner._param_to_ps(param)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _param_to_ps 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...
545
        self.assertEquals(result, '$null')
546
547
    def test_param_to_ps_string(self):
548
        # test ascii
549
        param_str = 'StackStorm 1234'
550
        result = self._runner._param_to_ps(param_str)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _param_to_ps 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...
551
        self.assertEquals(result, '"StackStorm 1234"')
552
553
        # test escaped
554
        param_str = '\n\r\t'
555
        result = self._runner._param_to_ps(param_str)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _param_to_ps 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...
556
        self.assertEquals(result, '"`n`r`t"')
557
558
    def test_param_to_ps_bool(self):
559
        # test True
560
        result = self._runner._param_to_ps(True)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _param_to_ps 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...
561
        self.assertEquals(result, '$true')
562
563
        # test False
564
        result = self._runner._param_to_ps(False)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _param_to_ps 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...
565
        self.assertEquals(result, '$false')
566
567
    def test_param_to_ps_integer(self):
568
        result = self._runner._param_to_ps(9876)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _param_to_ps 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...
569
        self.assertEquals(result, '9876')
570
571
        result = self._runner._param_to_ps(-765)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _param_to_ps 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...
572
        self.assertEquals(result, '-765')
573
574
    def test_param_to_ps_float(self):
575
        result = self._runner._param_to_ps(98.76)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _param_to_ps 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...
576
        self.assertEquals(result, '98.76')
577
578
        result = self._runner._param_to_ps(-76.5)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _param_to_ps 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...
579
        self.assertEquals(result, '-76.5')
580
581
    def test_param_to_ps_list(self):
582
        input_list = ['StackStorm Test String',
583
                      '`\0$',
584
                      True,
585
                      99]
586
        result = self._runner._param_to_ps(input_list)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _param_to_ps 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...
587
        self.assertEquals(result, '@("StackStorm Test String", "```0`$", $true, 99)')
588
589
    def test_param_to_ps_list_nested(self):
590
        input_list = [['a'], ['b'], [['c']]]
591
        result = self._runner._param_to_ps(input_list)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _param_to_ps 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...
592
        self.assertEquals(result, '@(@("a"), @("b"), @(@("c")))')
593
594
    def test_param_to_ps_dict(self):
595
        input_list = collections.OrderedDict(
596
            [('str key', 'Value String'),
597
             ('esc str\n', '\b\f\v"'),
598
             (False, True),
599
             (11, 99),
600
             (18.3, 12.34)])
601
        result = self._runner._param_to_ps(input_list)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _param_to_ps 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...
602
        expected_str = (
603
            '@{"str key" = "Value String"; '
604
            '"esc str`n" = "`b`f`v`\""; '
605
            '$false = $true; '
606
            '11 = 99; '
607
            '18.3 = 12.34}'
608
        )
609
        self.assertEquals(result, expected_str)
610
611
    def test_param_to_ps_dict_nexted(self):
612
        input_list = collections.OrderedDict(
613
            [('a', {'deep_a': 'value'}),
614
             ('b', {'deep_b': {'deep_deep_b': 'value'}})])
615
        result = self._runner._param_to_ps(input_list)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _param_to_ps 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...
616
        expected_str = (
617
            '@{"a" = @{"deep_a" = "value"}; '
618
            '"b" = @{"deep_b" = @{"deep_deep_b" = "value"}}}'
619
        )
620
        self.assertEquals(result, expected_str)
621
622
    def test_param_to_ps_deep_nested_dict_outer(self):
623
        ####
624
        # dict as outer container
625
        input_dict = collections.OrderedDict(
626
            [('a', [{'deep_a': 'value'},
627
                    {'deep_b': ['a', 'b', 'c']}])])
628
        result = self._runner._param_to_ps(input_dict)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _param_to_ps 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...
629
        expected_str = (
630
            '@{"a" = @(@{"deep_a" = "value"}, '
631
            '@{"deep_b" = @("a", "b", "c")})}'
632
        )
633
        self.assertEquals(result, expected_str)
634
635
    def test_param_to_ps_deep_nested_list_outer(self):
636
        ####
637
        # list as outer container
638
        input_list = [{'deep_a': 'value'},
639
                      {'deep_b': ['a', 'b', 'c']},
640
                      {'deep_c': [{'x': 'y'}]}]
641
        result = self._runner._param_to_ps(input_list)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _param_to_ps 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...
642
        expected_str = (
643
            '@(@{"deep_a" = "value"}, '
644
            '@{"deep_b" = @("a", "b", "c")}, '
645
            '@{"deep_c" = @(@{"x" = "y"})})'
646
        )
647
        self.assertEquals(result, expected_str)
648
649
    def test_transform_params_to_ps(self):
650
        positional_args = [1, 'a', '\n']
651
        named_args = collections.OrderedDict(
652
            [('a', 'value1'),
653
             ('b', True),
654
             ('c', ['x', 'y']),
655
             ('d', {'z': 'w'})]
656
        )
657
658
        result_pos, result_named = self._runner._transform_params_to_ps(positional_args,
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _transform_params_to_ps 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...
659
                                                                        named_args)
660
        self.assertEquals(result_pos, ['1', '"a"', '"`n"'])
661
        self.assertEquals(result_named, collections.OrderedDict([
662
            ('a', '"value1"'),
663
            ('b', '$true'),
664
            ('c', '@("x", "y")'),
665
            ('d', '@{"z" = "w"}')]))
666
667
    def test_transform_params_to_ps_none(self):
668
        positional_args = None
669
        named_args = None
670
671
        result_pos, result_named = self._runner._transform_params_to_ps(positional_args,
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _transform_params_to_ps 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...
672
                                                                        named_args)
673
        self.assertEquals(result_pos, None)
674
        self.assertEquals(result_named, None)
675
676
    def test_create_ps_params_string(self):
677
        positional_args = [1, 'a', '\n']
678
        named_args = collections.OrderedDict(
679
            [('-a', 'value1'),
680
             ('-b', True),
681
             ('-c', ['x', 'y']),
682
             ('-d', {'z': 'w'})]
683
        )
684
685
        result = self._runner.create_ps_params_string(positional_args, named_args)
686
687
        self.assertEquals(result,
688
                          '-a "value1" -b $true -c @("x", "y") -d @{"z" = "w"} 1 "a" "`n"')
689
690
    def test_create_ps_params_string_none(self):
691
        positional_args = None
692
        named_args = None
693
694
        result = self._runner.create_ps_params_string(positional_args, named_args)
695
        self.assertEquals(result, "")
696