Skip to content

Instantly share code, notes, and snippets.

View mkorpela's full-sized avatar

Mikko Korpela mkorpela

View GitHub Profile
@mkorpela
mkorpela / find_unused.py
Created January 20, 2012 11:57
Finding unused Robot Framework user keywords
import sys
from robotide.controller.chiefcontroller import ChiefController
from robotide.controller.commands import NullObserver
from robotide.controller.filecontrollers import DirectoryController
from robotide.namespace import Namespace
from robotide.spec.iteminfo import LibraryKeywordInfo
from robotide.usages.commands import FindUsages
def construct_chief_controller(datapath):
@mkorpela
mkorpela / chromejam.py
Created February 9, 2012 12:42
This seems to jam while Chrome is running
import sys
import wx
print wx.__version__
print sys.version_info
class MyFrame(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title)
@mkorpela
mkorpela / libbi.py
Created March 13, 2012 13:58
Monkey that somehow got out of his cage
from robot.libraries.BuiltIn import BuiltIn
def run_flat(name, *args):
"""
This keyword flattens robot logs. Only messages will be logged - no keyword structure.
"""
from robot.output import LOGGER
s, e = LOGGER.start_keyword, LOGGER.end_keyword
LOGGER.start_keyword = LOGGER.end_keyword = lambda *_:0
try:
@mkorpela
mkorpela / pybotprofiler.py
Created October 17, 2012 18:53
Script to help in Robot Framework test optimization
import cProfile
import pstats
from robot.run import run_cli
import os, sys
import tempfile
profile_results = tempfile.mktemp(suffix='.out', prefix='pybot-profile', dir='.')
cProfile.run('run_cli(sys.argv[1:])', profile_results)
stats = pstats.Stats(profile_results)
stats.sort_stats('cumulative').print_stats(50)
@mkorpela
mkorpela / feiluret.py
Created November 9, 2012 11:55
Log failure information to command line
# Copyright 2008-2012 Nokia Siemens Networks Oyj
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@mkorpela
mkorpela / keyword_times.py
Last active February 4, 2024 11:40
Script that shows 100 most time consuming keywords in Robot Framework output.xml
from functools import total_ordering
from robot.api import ExecutionResult, ResultVisitor
import math, re
class KeywordTimes(ResultVisitor):
VAR_PATTERN = re.compile(r'^(\$|\@)\{[^\}]+\}(, \$\{[^\}]+\})* = ')
def __init__(self):
@mkorpela
mkorpela / stacktrace_signalhandler.py
Created January 7, 2014 13:27
Print stack trace during test execution. Works on POSIX not WINDOWS.
mport signal
import sys
import traceback
def debug(sig, frame):
""" This is a modified version of the one posted to http://stackoverflow.com/a/133384/308189
This one only writes the traceback to real stdout as robot framework redirects the stdout
"""
message = "\nSignal recieved : \nTraceback:\n"
@mkorpela
mkorpela / Printter.py
Created March 5, 2014 13:55
Print execution status during robot run (pybot --listener Printter.py ..)
class Printter(object):
ROBOT_LISTENER_API_VERSION = 2
def __init__(self):
self._main_suite = True
self.passed_all = 0
self.failed_all = 0
self.passed_critical = 0
self.failed_critical = 0
import os
import re
SPLITTER = re.compile(r'\n(?=[^\s])', re.MULTILINE)
def files(path):
for root, dirs, files in os.walk(path):
for f in files:
if f.endswith('.txt') or f.endswith('.robot') or f.endswith('.tsv'):
yield os.path.join(root, f)
@mkorpela
mkorpela / test_execution_order.py
Created May 20, 2014 10:05
Pabot test execution order visualisation
from robot.api import ExecutionResult, ResultVisitor
from robot.utils import timestamp_to_secs as ts, secs_to_timestamp as st
res = ExecutionResult('output.xml')
class SuiteAndTestTimes(ResultVisitor):
def __init__(self):
self.result_by_start_time = []
self.result_by_end_time = []