Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __redirect_streams(self):
if self.__streams_redirected:
return
if isinstance(self.screen, DummyScreen):
return
if sys.stdout.isatty():
if not is_windows():
self.__detect_console_logger()
if self.orig_streams:
raise TaurusInternalException("Console: original streams already set")
elif self.logger_handlers and not self.orig_streams:
self.log.debug("Overriding logging streams")
for handler in self.logger_handlers:
self.orig_streams[handler] = handler.stream
handler.stream = self.temp_stream
self.log.debug("Redirected logging streams, %s/%s", self.logger_handlers, self.orig_streams)
self.__streams_redirected = True
else:
self.log.info("Did not mute console logging")
def __val_to_str(self, kpi_val):
if isinstance(kpi_val, float):
return '%.5f' % kpi_val
elif isinstance(kpi_val, integer_types):
return '%d' % kpi_val
elif isinstance(kpi_val, string_types):
return kpi_val
else:
raise TaurusInternalException("Unhandled kpi type: %s" % type(kpi_val))
if not files:
return
files.sort()
self.log.debug("Files found by pattern: %s", files)
if not os.path.getsize(files[-1]):
return
self.data_file = files[-1]
self.data_file = self.engine.find_file(self.data_file)
if not os.path.exists(self.data_file):
if time.time() - self._file_check_ts < self._file_exists_wait:
self.log.debug("File not exists yet: %s", self.data_file)
return
else:
msg = "File has not appeared within %ss: %s" % (self._file_exists_wait, self.data_file)
raise TaurusInternalException(msg)
self.log.info("Will load external results from file: %s", self.data_file)
self.label = self.data_file
self.reader = self._get_reader()
if isinstance(self.engine.aggregator, ConsolidatingAggregator):
self.engine.aggregator.add_underling(self.reader)
self.engine.aggregator.add_listener(self)
reader = TSVDataReader(self.data_file, self.log)
reader.url_label = "N/A"
return reader
elif header.startswith("
def _get_resource_stats(self):
if not self.monitor:
raise TaurusInternalException('Local monitor must be instantiated')
return self.monitor.resource_stats()
# make unique & sort
self.track_percentiles = self.settings.get("percentiles", self.track_percentiles)
self.track_percentiles = list(set(self.track_percentiles))
self.track_percentiles.sort()
self.settings["percentiles"] = self.track_percentiles
self.ignored_labels = self.settings.get("ignore-labels", self.ignored_labels)
self.generalize_labels = self.settings.get("generalize-labels", self.generalize_labels)
self.min_buffer_len = dehumanize_time(self.settings.get("min-buffer-len", self.min_buffer_len))
max_buffer_len = self.settings.get("max-buffer-len", self.max_buffer_len)
try:
self.max_buffer_len = dehumanize_time(max_buffer_len)
except TaurusInternalException as exc:
self.log.debug("Exception in dehumanize_time(%s): %s", max_buffer_len, exc)
raise TaurusConfigError("Wrong 'max-buffer-len' value: %s" % max_buffer_len)
self.buffer_multiplier = self.settings.get("buffer-multiplier", self.buffer_multiplier)
count = len(self.track_percentiles)
if count == 1:
self.buffer_scale_idx = str(float(self.track_percentiles[0]))
if count > 1:
percentile = self.settings.get("buffer-scale-choice", 0.5)
percentiles = [i / (count - 1.0) for i in range(count)]
distances = [abs(percentile - percentiles[i]) for i in range(count)]
index_position = distances.index(min(distances))
self.buffer_scale_idx = str(float(self.track_percentiles[index_position]))
debug_str = 'Buffer scaling setup: percentile %s from %s selected'
def append(self, selector, node):
"""
Add node to container specified by selector. If multiple nodes will
match the selector, first of them will be used as container.
:param selector: CSS selector for container
:param node: Element instance to add
:raise TaurusInternalException: if container was not found
"""
container = self.get(selector)
if not len(container):
msg = "Failed to find TestPlan node in file: %s"
raise TaurusInternalException(msg % selector)
container[0].append(node)
def check_virtual_display(self):
if self.virtual_display:
if not self.virtual_display.is_alive():
self.log.info("Virtual display out: %s", self.virtual_display.stdout)
self.log.warning("Virtual display err: %s", self.virtual_display.stderr)
raise TaurusInternalException("Virtual display failed: %s" % self.virtual_display.return_code)
def viewitems(self):
if PY3:
raise TaurusInternalException("Invalid call")
for item in super(KPISet, self).viewitems():
yield (item[0], self.__getitem__(item[0]))
def process(self):
output_format = Configuration.JSON if self.options.json else Configuration.YAML
self.log.info('Loading SoapUI project %s', self.file_to_convert)
self.file_to_convert = os.path.abspath(os.path.expanduser(self.file_to_convert))
if not os.path.exists(self.file_to_convert):
raise TaurusInternalException("File does not exist: %s" % self.file_to_convert)
self.converter = SoapUIScriptConverter(self.log)
try:
converted_config = self.converter.convert_script(self.file_to_convert, self.options.test_case)
except BaseException:
self.log.error("Error while processing SoapUI project: %s", self.file_to_convert)
raise
self._cleanup_config(converted_config)
exporter = Configuration.from_dict(converted_config)
if self.options.file_name:
file_name = self.options.file_name
else:
file_name = self.file_to_convert + "." + output_format.lower()