Skip to content

Commit fb0221e

Browse files
sseliverstovGilBecker-Anaplan
authored andcommitted
unicode support (fixes allure-framework#69 via allure-framework#71)
unicode fixes
1 parent e98d69b commit fb0221e

File tree

10 files changed

+32
-66
lines changed

10 files changed

+32
-66
lines changed

allure-behave/features/description.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
@wip
21
Feature: Description
32

43
Scenario: Use description

allure-behave/features/scenario.feature

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,16 @@ Feature: Scenario
1919
| passed | passed |
2020
| failed | failed |
2121
| broken | broken |
22-
| undefined | broken |
22+
| undefined | broken |
23+
24+
25+
Scenario: Scenario without name
26+
Given feature definition
27+
"""
28+
Feature: Scenario
29+
30+
Scenario:
31+
Given passed step
32+
"""
33+
When I run behave with allure formatter
34+
Then allure report has a scenario with name "Scenario"

allure-behave/features/steps/behave_steps.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,18 @@
99

1010

1111
@given(u'feature definition')
12-
def feature_definition(context):
13-
parser = Parser()
12+
@given(u'feature definition {lang}')
13+
def feature_definition(context, **kwargs):
14+
parser = Parser(language=kwargs.get('lang', None))
1415
context.feature_definition = parser.parse(context.text)
1516

1617

1718
@when(u'I run behave with allure formatter')
18-
def run_behave_with_allure(context):
19+
@when(u'I run behave with allure formatter with options "{args}"')
20+
def run_behave_with_allure(context, **kwargs):
1921
cmd_args = '-v -f allure_behave.formatter:AllureFormatter -f pretty'
20-
config = Configuration(command_args=cmd_args)
22+
cmd = '{options} {cmd}'.format(cmd=cmd_args, options=kwargs.get('args', ''))
23+
config = Configuration(command_args=cmd)
2124

2225
result_tmp_dir = mkdtemp(dir=os.environ.get('TEST_TMP', None))
2326
stream_opener = StreamOpener(filename=result_tmp_dir)

allure-behave/features/steps/report_steps.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,3 @@ def step_impl(context, item):
8484
context_matcher = getattr(context, item)
8585
matcher = partial(context_matcher, has_attachment)
8686
assert_that(context.allure_report, matcher())
87-
88-
89-
90-
91-
92-
93-
94-
Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,11 @@
11
Feature: Language
22
Scenario: Use russian
3-
Given feature definition ru
3+
Given feature definition ru
44
"""
5-
Свойство: Юникод
5+
Функционал: Язык
66
7-
Структура сценария: Солнечный круг, небо вокруг
8-
Пусть всегда будет <это>
9-
Пусть всегда буду я
10-
Примеры:
11-
| это |
12-
| солнце |
13-
| небо |
14-
| мама |
7+
Сценарий: На русском
8+
Допустим passed step
159
"""
1610
When I run behave with allure formatter with options "--lang ru"
17-
Then allure report has a scenario with name "Солнечный круг, небо вокруг"
18-
And scenario contains step "Пусть всегда будет солнце"
19-
And scenario contains step "Пусть всегда будет небо"
20-
And scenario contains step "Пусть всегда будет мама"
21-
And scenario contains step "Пусть всегда буду я"
22-
23-
24-
Scenario: Assert message in step
25-
Given feature definition ru
26-
"""
27-
Свойство: Юникод
28-
29-
Сценарий: Ошибка с utf-8 сообщением
30-
Допустим провальный шаг
31-
"""
32-
When I run behave with allure formatter with options "--lang ru"
33-
Then allure report has a scenario with name "Ошибка с utf-8 сообщением"
34-
And scenario contains step "Допустим провальный шаг"
35-
And step has status details with message "AssertionError: Фиаско!"
36-
37-
38-
Scenario: ASCII assert message in step
39-
Given feature definition ru
40-
"""
41-
Свойство: Юникод
42-
43-
Сценарий: Ошибка с utf-8 сообщением
44-
Допустим провальный шаг с ascii
45-
"""
46-
When I run behave with allure formatter with options "--lang ru"
47-
Then allure report has a scenario with name "Ошибка с utf-8 сообщением"
48-
And scenario contains step "Допустим провальный шаг с ascii"
49-
And step has status details with message "AssertionError: Фиаско!"
11+
Then allure report has a scenario with name "На русском"

allure-behave/src/listener.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def stop_scenario(self, scenario):
8080

8181
def start_step(self, step):
8282
self.current_step_uuid = uuid4()
83-
name = '{keyword} {title}'.format(keyword=step.keyword, title=step.name)
83+
name = u'{keyword} {title}'.format(keyword=step.keyword, title=step.name)
8484
parent_uuid = self.current_before_uuid or self.current_scenario_uuid
8585
allure_step = TestStepResult(name=name, start=now())
8686

allure-behave/src/utils.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,11 @@ def step_status(result):
7171

7272
def step_status_details(result):
7373
if result.exception:
74-
message = ','.join(map(str, result.exception.args))
75-
message = '{name}: {message}'.format(name=result.exception.__class__.__name__, message=message)
76-
trace = '\n'.join(traceback.format_tb(result.exc_traceback)) if result.exc_traceback else None
74+
message = u','.join(map(str, result.exception.args))
75+
message = u'{name}: {message}'.format(name=result.exception.__class__.__name__, message=message)
76+
trace = u'\n'.join(traceback.format_tb(result.exc_traceback)) if result.exc_traceback else None
7777
return StatusDetails(message=message, trace=trace)
7878
elif result.status == 'undefined':
79-
message = u"\nYou can implement step definitions for undefined steps with "
80-
message += u"these snippets:\n\n"
79+
message = u'\nYou can implement step definitions for undefined steps with these snippets:\n\n'
8180
message += make_undefined_step_snippet(result)
8281
return StatusDetails(message=message)

allure-behave/tox.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ envlist=
33
py{27,33,34,35}
44
static_check
55

6-
76
[testenv]
87
passenv =
98
HOME

allure-python-commons/src/model2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def _write(report_dir, item, glob):
1919
data = asdict(item, filter=lambda attr, value: not (type(value) != bool and not bool(value)))
2020
with io.open(os.path.join(report_dir, filename), 'w', encoding='utf8') as json_file:
2121
if sys.version_info.major < 3:
22-
json_file.write(unicode(json.dumps(data, indent=indent, ensure_ascii=False)))
22+
json_file.write(unicode(json.dumps(data, indent=indent, ensure_ascii=False, encoding='utf8')))
2323
else:
2424
json.dump(data, json_file, indent=indent, ensure_ascii=False)
2525

allure-python-commons/src/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
def md5(*args):
77
m = hashlib.md5()
88
for arg in args:
9-
part = str(arg).encode('utf-8')
9+
part = arg.encode('utf-8')
1010
m.update(part)
1111
return m.hexdigest()
1212

0 commit comments

Comments
 (0)