Skip to content

Commit 8f88231

Browse files
authored
Fix style issues (softlayer#768)
* Fix style issues
1 parent 50189a4 commit 8f88231

6 files changed

Lines changed: 79 additions & 73 deletions

File tree

setup.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
from __future__ import print_function
2-
import sys
3-
from codecs import open
2+
import codecs
43
import os
54

65
from setuptools import setup, find_packages
76

87
DESCRIPTION = "A library for SoftLayer's API"
98

109
if os.path.exists('README.rst'):
11-
with open('README.rst', 'r', 'utf-8') as readme_file:
10+
with codecs.open('README.rst', 'r', 'utf-8') as readme_file:
1211
LONG_DESCRIPTION = readme_file.read()
1312
else:
1413
LONG_DESCRIPTION = DESCRIPTION

tests/CLI/helper_tests.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,7 @@ class ResolveIdTests(testing.TestCase):
251251

252252
def test_resolve_id_one(self):
253253
resolver = lambda r: [12345]
254-
id = helpers.resolve_id(resolver, 'test')
255-
self.assertEqual(id, 12345)
254+
self.assertEqual(helpers.resolve_id(resolver, 'test'), 12345)
256255

257256
def test_resolve_id_none(self):
258257
resolver = lambda r: []

tests/CLI/modules/call_api_tests.py

Lines changed: 57 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -13,67 +13,73 @@
1313
import pytest
1414

1515

16-
class BuildFilterTests(testing.TestCase):
16+
def test_filter_empty():
17+
assert call_api._build_filters([]) == {}
1718

18-
def test_empty(self):
19-
assert call_api._build_filters([]) == {}
2019

21-
def test_basic(self):
22-
result = call_api._build_filters(['property=value'])
23-
assert result == {'property': {'operation': '_= value'}}
20+
def test_filter_basic():
21+
result = call_api._build_filters(['property=value'])
22+
assert result == {'property': {'operation': '_= value'}}
2423

25-
def test_nested(self):
26-
result = call_api._build_filters(['nested.property=value'])
27-
assert result == {'nested': {'property': {'operation': '_= value'}}}
2824

29-
def test_multi(self):
30-
result = call_api._build_filters(['prop1=value1', 'prop2=prop2'])
31-
assert result == {
32-
'prop1': {'operation': '_= value1'},
33-
'prop2': {'operation': '_= prop2'},
34-
}
25+
def test_filter_nested():
26+
result = call_api._build_filters(['nested.property=value'])
27+
assert result == {'nested': {'property': {'operation': '_= value'}}}
3528

36-
def test_in(self):
37-
result = call_api._build_filters(['prop IN value1,value2'])
38-
assert result == {
39-
'prop': {
40-
'operation': 'in',
41-
'options': [{'name': 'data', 'value': ['value1', 'value2']}],
42-
}
43-
}
4429

45-
def test_in_multi(self):
46-
result = call_api._build_filters([
47-
'prop_a IN a_val1,a_val2',
48-
'prop_b IN b_val1,b_val2',
49-
])
50-
assert result == {
51-
'prop_a': {
52-
'operation': 'in',
53-
'options': [{'name': 'data', 'value': ['a_val1', 'a_val2']}],
54-
},
55-
'prop_b': {
56-
'operation': 'in',
57-
'options': [{'name': 'data', 'value': ['b_val1', 'b_val2']}],
58-
},
59-
}
30+
def test_filter_multi():
31+
result = call_api._build_filters(['prop1=value1', 'prop2=prop2'])
32+
assert result == {
33+
'prop1': {'operation': '_= value1'},
34+
'prop2': {'operation': '_= prop2'},
35+
}
36+
6037

61-
def test_in_with_whitespace(self):
62-
result = call_api._build_filters(['prop IN value1 , value2 '])
63-
assert result == {
64-
'prop': {
65-
'operation': 'in',
66-
'options': [{'name': 'data', 'value': ['value1', 'value2']}],
67-
}
38+
def test_filter_in():
39+
result = call_api._build_filters(['prop IN value1,value2'])
40+
assert result == {
41+
'prop': {
42+
'operation': 'in',
43+
'options': [{'name': 'data', 'value': ['value1', 'value2']}],
6844
}
45+
}
46+
47+
48+
def test_filter_in_multi():
49+
result = call_api._build_filters([
50+
'prop_a IN a_val1,a_val2',
51+
'prop_b IN b_val1,b_val2',
52+
])
53+
assert result == {
54+
'prop_a': {
55+
'operation': 'in',
56+
'options': [{'name': 'data', 'value': ['a_val1', 'a_val2']}],
57+
},
58+
'prop_b': {
59+
'operation': 'in',
60+
'options': [{'name': 'data', 'value': ['b_val1', 'b_val2']}],
61+
},
62+
}
63+
64+
65+
def test_filter_in_with_whitespace():
66+
result = call_api._build_filters(['prop IN value1 , value2 '])
67+
assert result == {
68+
'prop': {
69+
'operation': 'in',
70+
'options': [{'name': 'data', 'value': ['value1', 'value2']}],
71+
}
72+
}
73+
74+
75+
def test_filter_invalid_operation():
76+
with pytest.raises(exceptions.CLIAbort):
77+
call_api._build_filters(['prop N/A value1'])
6978

70-
def test_invalid_operation(self):
71-
with pytest.raises(exceptions.CLIAbort):
72-
call_api._build_filters(['prop N/A value1'])
7379

74-
def test_only_whitespace(self):
75-
with pytest.raises(exceptions.CLIAbort):
76-
call_api._build_filters([' '])
80+
def test_filter_only_whitespace():
81+
with pytest.raises(exceptions.CLIAbort):
82+
call_api._build_filters([' '])
7783

7884

7985
class CallCliTests(testing.TestCase):

tests/CLI/modules/config_tests.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ def set_up(self):
5353
@mock.patch('SoftLayer.CLI.formatting.confirm')
5454
@mock.patch('SoftLayer.CLI.environment.Environment.getpass')
5555
@mock.patch('SoftLayer.CLI.environment.Environment.input')
56-
def test_setup(self, input, getpass, confirm_mock):
56+
def test_setup(self, mocked_input, getpass, confirm_mock):
5757
with tempfile.NamedTemporaryFile() as config_file:
5858
confirm_mock.return_value = True
5959
getpass.return_value = 'A' * 64
60-
input.side_effect = ['user', 'public', 0]
60+
mocked_input.side_effect = ['user', 'public', 0]
6161

6262
result = self.run_command(['--config=%s' % config_file.name,
6363
'config', 'setup'])
@@ -76,11 +76,11 @@ def test_setup(self, input, getpass, confirm_mock):
7676
@mock.patch('SoftLayer.CLI.formatting.confirm')
7777
@mock.patch('SoftLayer.CLI.environment.Environment.getpass')
7878
@mock.patch('SoftLayer.CLI.environment.Environment.input')
79-
def test_setup_cancel(self, input, getpass, confirm_mock):
79+
def test_setup_cancel(self, mocked_input, getpass, confirm_mock):
8080
with tempfile.NamedTemporaryFile() as config_file:
8181
confirm_mock.return_value = False
8282
getpass.return_value = 'A' * 64
83-
input.side_effect = ['user', 'public', 0]
83+
mocked_input.side_effect = ['user', 'public', 0]
8484

8585
result = self.run_command(['--config=%s' % config_file.name,
8686
'config', 'setup'])
@@ -90,32 +90,33 @@ def test_setup_cancel(self, input, getpass, confirm_mock):
9090

9191
@mock.patch('SoftLayer.CLI.environment.Environment.getpass')
9292
@mock.patch('SoftLayer.CLI.environment.Environment.input')
93-
def test_get_user_input_private(self, input, getpass):
93+
def test_get_user_input_private(self, mocked_input, getpass):
9494
getpass.return_value = 'A' * 64
95-
input.side_effect = ['user', 'private', 0]
95+
mocked_input.side_effect = ['user', 'private', 0]
9696

9797
username, secret, endpoint_url, timeout = (
9898
config.get_user_input(self.env))
9999

100100
self.assertEqual(username, 'user')
101101
self.assertEqual(secret, 'A' * 64)
102102
self.assertEqual(endpoint_url, consts.API_PRIVATE_ENDPOINT)
103+
self.assertEqual(timeout, 0)
103104

104105
@mock.patch('SoftLayer.CLI.environment.Environment.getpass')
105106
@mock.patch('SoftLayer.CLI.environment.Environment.input')
106-
def test_get_user_input_custom(self, input, getpass):
107+
def test_get_user_input_custom(self, mocked_input, getpass):
107108
getpass.return_value = 'A' * 64
108-
input.side_effect = ['user', 'custom', 'custom-endpoint', 0]
109+
mocked_input.side_effect = ['user', 'custom', 'custom-endpoint', 0]
109110

110111
_, _, endpoint_url, _ = config.get_user_input(self.env)
111112

112113
self.assertEqual(endpoint_url, 'custom-endpoint')
113114

114115
@mock.patch('SoftLayer.CLI.environment.Environment.getpass')
115116
@mock.patch('SoftLayer.CLI.environment.Environment.input')
116-
def test_get_user_input_default(self, input, getpass):
117+
def test_get_user_input_default(self, mocked_input, getpass):
117118
self.env.getpass.return_value = 'A' * 64
118-
self.env.input.side_effect = ['user', 'public', 0]
119+
mocked_input.side_effect = ['user', 'public', 0]
119120

120121
_, _, endpoint_url, _ = config.get_user_input(self.env)
121122

tests/config_tests.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,10 @@ def test_no_section(self, config_parser):
8686

8787
self.assertIsNone(result)
8888

89-
@mock.patch('six.moves.configparser.RawConfigParser')
90-
def test_config_file(self, config_parser):
91-
config.get_client_settings_config_file(config_file='path/to/config')
92-
config_parser().read.assert_called_with([mock.ANY,
93-
mock.ANY,
94-
'path/to/config'])
89+
90+
@mock.patch('six.moves.configparser.RawConfigParser')
91+
def test_config_file(config_parser):
92+
config.get_client_settings_config_file(config_file='path/to/config')
93+
config_parser().read.assert_called_with([mock.ANY,
94+
mock.ANY,
95+
'path/to/config'])

tests/transport_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def test_identifier(self, request):
121121
req.identifier = 1234
122122
self.transport(req)
123123

124-
args, kwargs = request.call_args
124+
_, kwargs = request.call_args
125125
self.assertIn(
126126
"""<member>
127127
<name>id</name>

0 commit comments

Comments
 (0)