Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid using protected members outside scope #1083

Merged
merged 7 commits into from
Nov 11, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ disable=print-statement,
R0904,
R0916,
W0201,
W0212,
W0404,
W0613,
W0621,
Expand Down
1 change: 1 addition & 0 deletions esrally/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ def add_all(self, source, section):
:param source: The source config object.
:param section: A section in the source config object. Ignored if it does not exist.
"""
# pylint: disable=protected-access
for k, v in source._opts.items():
scope, source_section, key = k
if source_section == section:
Expand Down
13 changes: 5 additions & 8 deletions esrally/track/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,31 +430,28 @@ def __init__(self, track, params, templates, **kwargs):
if not filter_template or template.name == filter_template:
body = template.content
if body and "template" in body:
body = CreateComposableTemplateParamSource._create_or_merge(template.content,
["template", "settings"], settings)
body = self.create_or_merge(template.content, ["template", "settings"], settings)
self.template_definitions.append((template.name, body))
else:
raise exceptions.InvalidSyntax("Please set the properties 'template' and 'body' for the "
f"{params.get('operation-type')} operation or declare composable and/or component "
"templates in the track")

@staticmethod
def _create_or_merge(content, path, new_content):
def create_or_merge(self, content, path, new_content):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to do this anymore - See #1106

original_content = content
if new_content:
for sub_path in path:
if sub_path not in content:
content[sub_path] = {}
content = content[sub_path]
CreateComposableTemplateParamSource.__merge(content, new_content)
self.merge(content, new_content)
return original_content

@staticmethod
def __merge(dct, merge_dct):
def merge(self, dct, merge_dct):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above

for k in merge_dct.keys():
if (k in dct and isinstance(dct[k], dict)
and isinstance(merge_dct[k], collections.Mapping)):
CreateComposableTemplateParamSource.__merge(dct[k], merge_dct[k])
self.merge(dct[k], merge_dct[k])
else:
dct[k] = merge_dct[k]

Expand Down
1 change: 1 addition & 0 deletions tests/driver/scheduler_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# pylint: disable=protected-access

import random
from unittest import TestCase
Expand Down
2 changes: 2 additions & 0 deletions tests/mechanic/launcher_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# pylint: disable=protected-access

import io
import os
import sys
Expand Down
1 change: 1 addition & 0 deletions tests/mechanic/provisioner_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# pylint: disable=protected-access

import os
import tempfile
Expand Down
1 change: 1 addition & 0 deletions tests/mechanic/supplier_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# pylint: disable=protected-access

import collections
import datetime
Expand Down
1 change: 1 addition & 0 deletions tests/metrics_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# pylint: disable=protected-access

import collections
import datetime
Expand Down
29 changes: 20 additions & 9 deletions tests/track/params_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# pylint: disable=protected-access

import random
from unittest import TestCase
Expand Down Expand Up @@ -1903,28 +1904,38 @@ def test_create_composable_index_template_from_track(self):
}, body)

def test_create_or_merge(self):
content = params.CreateComposableTemplateParamSource._create_or_merge({"parent": {}}, ["parent", "child", "grandchild"],
{"name": "Mike"})
source = params.CreateComposableTemplateParamSource(track=track.Track(name="unit-test"), params={
"template": "test",
"body": {
"index_patterns": ["my*"],
"template": {
"settings" : {
"index.number_of_shards" : 3
}
},
"composed_of": ["ct1", "ct2"]
}
})

content = source.create_or_merge({"parent": {}}, ["parent", "child", "grandchild"], {"name": "Mike"})
assert content["parent"]["child"]["grandchild"]["name"] == "Mike"
content = params.CreateComposableTemplateParamSource._create_or_merge({"parent": {"child": {}}}, ["parent", "child", "grandchild"],
{"name": "Mike"})
content = source.create_or_merge({"parent": {"child": {}}}, ["parent", "child", "grandchild"], {"name": "Mike"})
assert content["parent"]["child"]["grandchild"]["name"] == "Mike"
content = params.CreateComposableTemplateParamSource._create_or_merge({"parent": {"child": {"grandchild": {}}}},
["parent", "child", "grandchild"], {"name": "Mike"})
content = source.create_or_merge({"parent": {"child": {"grandchild": {}}}}, ["parent", "child", "grandchild"], {"name": "Mike"})
assert content["parent"]["child"]["grandchild"]["name"] == "Mike"
content = params.CreateComposableTemplateParamSource._create_or_merge(
content = source.create_or_merge(
{"parent": {"child": {"name": "Mary", "grandchild": {"name": "Dale", "age": 38}}}},
["parent", "child", "grandchild"], {"name": "Mike"})
assert content["parent"]["child"]["name"] == "Mary"
assert content["parent"]["child"]["grandchild"]["name"] == "Mike"
assert content["parent"]["child"]["grandchild"]["age"] == 38
content = params.CreateComposableTemplateParamSource._create_or_merge(
content = source.create_or_merge(
{"parent": {
"child": {"name": "Mary", "grandchild": {"name": {"first": "Dale", "last": "Smith"}, "age": 38}}}},
["parent", "child", "grandchild"], {"name": "Mike"})
assert content["parent"]["child"]["grandchild"]["name"] == "Mike"
assert content["parent"]["child"]["grandchild"]["age"] == 38
content = params.CreateComposableTemplateParamSource._create_or_merge(
content = source.create_or_merge(
{"parent": {
"child": {"name": "Mary", "grandchild": {"name": {"first": "Dale", "last": "Smith"}, "age": 38}}}},
["parent", "child", "grandchild"], {"name": {"first": "Mike"}})
Expand Down
2 changes: 2 additions & 0 deletions tests/utils/io_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# pylint: disable=protected-access

import logging
import os
import subprocess
Expand Down
1 change: 1 addition & 0 deletions tests/utils/net_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def test_gcs_object_url(self, seed):
bucket_path = random.choice(["path/to/object", "/path/to/object",
"/path/to/object/", "path/to/object/"])

# pylint: disable=protected-access
assert net._build_gcs_object_url(bucket_name, bucket_path) == \
"https://storage.googleapis.com/storage/v1/b/unittest-bucket.test.me/o/path%2Fto%2Fobject?alt=media"

Expand Down