Skip to content

Commit

Permalink
Assume string type for params by default
Browse files Browse the repository at this point in the history
With this commit we allow users to skip enclosing quotes for params
(like `track-params` or `team-params`) when the value is clearly a
string (i.e. it cannot be coerced to a number or a boolean value). It is
still possible to surround a parameter with single-quotes to enforce
treatment as a string.

Relates elastic#735
  • Loading branch information
danielmitterdorfer authored and novosibman committed Aug 12, 2019
1 parent b1e39fb commit fcc6ac2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 7 additions & 2 deletions esrally/utils/opts.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def to_bool(v):

def kv_to_map(kvs):
def convert(v):
# string
# string (specified explicitly)
if v.startswith("'"):
return v[1:-1]

Expand All @@ -59,7 +59,12 @@ def convert(v):
pass

# boolean
return to_bool(v)
try:
return to_bool(v)
except ValueError:
pass
# treat it as string by default
return v

result = {}
for kv in kvs:
Expand Down
7 changes: 6 additions & 1 deletion tests/utils/opts_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from esrally import exceptions
from esrally.utils import opts


class ConfigHelperFunctionTests(TestCase):
def test_csv_to_list(self):
self.assertEqual([], opts.csv_to_list(""))
Expand All @@ -30,7 +31,11 @@ def test_csv_to_list(self):

def test_kv_to_map(self):
self.assertEqual({}, opts.kv_to_map([]))
self.assertEqual({"k": "v"}, opts.kv_to_map(["k:'v'"]))
# explicit treatment as string
self.assertEqual({"k": "3"}, opts.kv_to_map(["k:'3'"]))
self.assertEqual({"k": 3}, opts.kv_to_map(["k:3"]))
# implicit treatment as string
self.assertEqual({"k": "v"}, opts.kv_to_map(["k:v"]))
self.assertEqual({"k": "v", "size": 4, "empty": False, "temperature": 0.5},
opts.kv_to_map(["k:'v'", "size:4", "empty:false", "temperature:0.5"]))

Expand Down

0 comments on commit fcc6ac2

Please sign in to comment.