def test_run_with_trace(self): def rainbow(node): return Color.hsv(node.time.fraction * 0.8, 0.4, 0.9) def greyscale(node): return Color.hsv(0, 0, node.time.fraction / 2 + 0.4) def orange_green(node): return Color( 0.2 + node.time.fraction * 0.8, 0.2 + node.calls.fraction * 0.4 , 0.2) from pycallgraph.output import GraphvizOutput from pycallgraph import PyCallGraph graphviz = GraphvizOutput() graphviz.output_file = 'basic.png' graphviz.edge_color_func = lambda e: Color(0, 0, 0) #graphviz.node_color_func = rainbow #orange_green # greyscale config = Config(include_stdlib=True)#max_depth=10) config.trace_filter = GlobbingFilter(include=['osbot*','pbx*','boto3*']) with PyCallGraph(output=graphviz, config=config): try: self.handler.run(Test_Data.api_gw_payload_help) except Exception as error: Dev.pprint(error)
def main(): graphviz = GraphvizOutput() pycallgraph = PyCallGraph(output=graphviz, config=Config(include_stdlib=True)) pycallgraph.start() from html.parser import HTMLParser # noqa pycallgraph.stop() # Set the edge colour to black for all examples graphviz.edge_color_func = lambda e: Color(0, 0, 0) # Default node colouring graphviz.output_file = "colours-default.png" graphviz.done() def run(func, output_file): graphviz.node_color_func = func graphviz.output_file = output_file graphviz.done() run(rainbow, "colors-rainbow.png") run(greyscale, "colors-greyscale.png") run(orange_green, "colors-orange-green.png") run(rand, "colors-random.png")
def rainbow(node): '''Colour using only changes in hue. It will go from 0 to 0.8 which is red, orange, yellow, green, cyan, blue, then purple. See http://en.wikipedia.org/wiki/Hue for more information on hue. ''' return Color.hsv(node.time.fraction * 0.8, 0.4, 0.9)
def orange_green(node): """Make a higher total time have an orange colour and a higher number of calls have a green colour using RGB. """ return Color( 0.2 + node.time.fraction * 0.8, 0.2 + node.calls.fraction * 0.4 + node.time.fraction * 0.4, 0.2, )
def rainbow(node): """Colour using only changes in hue. It will go from 0 to 0.8 which is red, orange, yellow, green, cyan, blue, then purple. See http://en.wikipedia.org/wiki/Hue for more information on hue. """ return Color.hsv(node.time.fraction * 0.8, 0.4, 0.9)
def test_bad_range(): with pytest.raises(ColorException): Color(0, 5, 0, 0) with pytest.raises(ColorException): Color(0, 0, -1, 0)
def test_str(): assert str(Color(0.071, 0.204, 0.338, 0.471)) == "<Color #12345678>"
def test_rgb_csv(): assert Color(0.3, 0.4, 0.5, 0.6).rgb_csv() == "76,102,127"
def test_hsv(): c = Color.hsv(0.1, 0.5, 0.75, 0.25) assert c.r == 0.75 assert abs(c.g - 0.6) < 0.1 # Floating point comparison inaccurate assert abs(c.b - 0.375) < 0.1 assert c.a == 0.25
def rand(node): return Color.hsv( random.random(), node.calls.fraction * 0.5 + 0.5, node.calls.fraction * 0.5 + 0.5, )
def greyscale(node): '''Goes from dark grey to a light grey.''' return Color.hsv(0, 0, node.time.fraction / 2 + 0.4)
def greyscale(node): """Goes from dark grey to a light grey.""" return Color.hsv(0, 0, node.time.fraction / 2 + 0.4)
def orange_green(node): return Color( 0.2 + node.time.fraction * 0.8, 0.2 + node.calls.fraction * 0.4 , 0.2)
def greyscale(node): return Color.hsv(0, 0, node.time.fraction / 2 + 0.4)
def rainbow(node): return Color.hsv(node.time.fraction * 0.8, 0.4, 0.9)