from __future__ import absolute_import
from behave.model_core import Status
from behave.formatter.base import Formatter
import base64
import six
import copy
try:
import json
except ImportError:
import simplejson as json
class CucumberJSONFormatter(Formatter):
name = 'json'
description = 'JSON dump of test run'
dumps_kwargs = {
}
json_number_types = six.integer_types + (float,)
json_scalar_types = json_number_types + (six.text_type, bool, type(None))
def __init__(self, stream_opener, config):
super(CucumberJSONFormatter, self).__init__(stream_opener, config)
self.stream = self.open()
self.feature_count = 0
self.current_feature = None
self.current_feature_data = None
self._step_index = 0
self.current_background = None
self.current_background_data = None
def reset(self):
self.current_feature = None
self.current_feature_data = None
self._step_index = 0
self.current_background = None
def uri(self, uri):
pass
def feature(self, feature):
self.reset()
self.current_feature = feature
self.current_feature_data = {
'id': self.generate_id(feature),
'uri': feature.location.filename,
'line': feature.location.line,
'description': '',
'keyword': feature.keyword,
'name': feature.name,
'tags': self.write_tags(feature.tags),
'status': feature.status.name,
}
element = self.current_feature_data
if feature.description:
element['description'