Skip to content

Commit

Permalink
support encoding in apiritif (Blazemeter#1332)
Browse files Browse the repository at this point in the history
* genetare py file with keyword
* test
* docs
  • Loading branch information
corvustristis authored Jul 23, 2020
1 parent 35848b8 commit 7695f92
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions bzt/modules/apiritif/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,12 @@ def _gen_data_source_readers(self):
delimiter.value = ast.Str(s=source.get("delimiter"), kind="")
keywords.append(delimiter)

if "encoding" in source:
encoding = ast.keyword()
encoding.arg = "encoding"
encoding.value = ast.Str(s=source.get("encoding"), kind="")
keywords.append(encoding)

csv_file = self.scenario.engine.find_file(source["path"])
reader = ast.Assign(
targets=[ast.Name(id="reader_%s" % idx)],
Expand Down
2 changes: 2 additions & 0 deletions site/dat/docs/DataSources.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ scenarios:
- path: path/to/another.csv # this is a full form
delimiter: ','
quoted: false
encoding: "utf-8"
loop: true
variable-names: id,name
random-order: false
Expand All @@ -25,6 +26,7 @@ Explanation:
- `path` is a path to a csv file. This option is required.
- `delimiter` is a CSV delimiter. It is auto-detected by default, but you can use a symbol, i.e. `'.'` for dot, `','` for comma. Also, you can use `'tab'` for a tab symbol.
- `quoted` allows quoted data. Can be `true` of `false`. Use "auto" for auto-detection, if there's no `variable-names`.
- `encoding` allows you to specify encoding type.
- `loop` allows to loop over in case of end-of-file reached if `true`, stop thread if `false`.
- `variable-names` delimiter-separated list of variable names, empty by default. When omitted, the first line of CSV file will be used as variable names.
- `random-order` enables randomizing plugin; false by default. Available only for JMeter.
Expand Down
1 change: 1 addition & 0 deletions site/dat/docs/changes/feat-apiritif-csv-encoding.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add support of 'encoding' keyword
15 changes: 15 additions & 0 deletions tests/modules/selenium/test_apiritif_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -944,3 +944,18 @@ def test_auto_quoted(self):
self.assertIn("test_auto_quoted_double_quotes_bom.csv', loop=True, quoted=True)", test_script)
self.assertIn("test_auto_quoted_no_quotes.csv', loop=True, quoted=False)", test_script)
self.assertIn("test_auto_quoted_no_quotes_bom.csv', loop=True, quoted=False)", test_script)

def test_encoding(self):
self.configure({
"execution": [{
"test-mode": "apiritif",
"scenario": {
"requests": ["http://blazedemo.com/"],
"data-sources": [{
"path": "file.csv",
"encoding": "UTF-16"}]}}]})

self.obj.prepare()
with open(self.obj.script) as fds:
test_script = fds.read()
self.assertIn("reader_1 = apiritif.CSVReaderPerThread('file.csv', loop=True, encoding='UTF-16')", test_script)

0 comments on commit 7695f92

Please sign in to comment.