From fbbbd40195803d95fb4f2a2d704f3a93118c8342 Mon Sep 17 00:00:00 2001 From: Brendan Jackman Date: Thu, 5 Jan 2017 12:24:13 +0000 Subject: stats/grammar: Raise helpful error when asked to parse absent events If you use the Parser to access events that Trappy understands, but that are not present in the trace, you currently get an inscrutable exception when trying to access `.loc[ self._window[0]:]` on the empty DataFrame in _get_data_frame. Ideally attempting to parse absent events would just return an empty DataFrame, but then we don't know what columns it should have. So instead let's just raise a more helpful error saying that the event is not present. --- tests/test_stats_grammar.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tests') diff --git a/tests/test_stats_grammar.py b/tests/test_stats_grammar.py index de62f21..5138efc 100644 --- a/tests/test_stats_grammar.py +++ b/tests/test_stats_grammar.py @@ -244,3 +244,13 @@ trappy.thermal.Thermal:temp" prs = Parser(trace, filters={"cdev_state": 3}) dfr_res = prs.solve("devfreq_out_power:freq") self.assertEquals(len(dfr_res), 1) + + def test_no_events(self): + """Test trying to parse absent data""" + trace = trappy.FTrace() + prs = Parser(trace) + + # cpu_frequency is an event we know how to parse, but it isn't present + # in the test trace. + self.assertRaisesRegexp(ValueError, "No events found for cpu_frequency", + prs.solve, "cpu_frequency:frequency") -- cgit v1.2.3