Exemple #1
0
def test_store_filter(trace_store, trace):
    trace_store.add([trace])
    expected = CallTraceRow(
        module="tests.fixtures.examples.triangle",
        qualname="triangle",
        arg_types='{"x": {"module": "builtins", "qualname": "int"}, '
        '"y": {"module": "builtins", "qualname": "int"}, '
        '"z": {"module": "builtins", "qualname": "int"}}',
        return_type=None,
        yield_type=None,
    )
    result = trace_store.filter("", "triangle")
    assert len(result) == 1
    assert expected.__eq__(result)
Exemple #2
0
 def filter(self,
            module: str,
            qualname_prefix: Optional[str] = None,
            limit: int = 2000) -> List[CallTraceThunk]:
     sql_query, values = make_query(self.table, module, qualname_prefix,
                                    limit)
     with self.conn:
         cur = self.conn.cursor()
         cur.execute(sql_query, values)
         return [CallTraceRow(*row) for row in cur.fetchall()]
Exemple #3
0
 def add(self, traces: Iterable[CallTrace]) -> None:
     values = []
     for trace in traces:
         row = CallTraceRow.from_trace(trace)
         values.append((datetime.datetime.now(), row.module, row.qualname,
                        row.arg_types, row.return_type, row.yield_type))
     with self.conn:
         self.conn.executemany(
             'INSERT INTO {table} VALUES (?, ?, ?, ?, ?, ?)'.format(
                 table=self.table), values)
Exemple #4
0
 def test_log_failure_and_continue(self, caplog):
     traces = [
         CallTrace(dummy_func, {
             'a': int,
             'b': int
         }, int),
         CallTrace(object(), {}),  # object() will fail to serialize
         CallTrace(dummy_func, {
             'a': str,
             'b': str
         }, str),
     ]
     rows = list(serialize_traces(traces))
     expected = [
         CallTraceRow.from_trace(traces[0]),
         CallTraceRow.from_trace(traces[2]),
     ]
     assert rows == expected
     assert [r.msg for r in caplog.records] == ["Failed to serialize trace"]
Exemple #5
0
 def filter(
     self, module: str, qualname_prefix: Optional[str] = None, limit: int = 2000
 ) -> List[CallTraceThunk]:
     result: List[CallTraceThunk] = []
     for stored_module, row in self._values.items():
         is_qualname = qualname_prefix is not None and qualname_prefix in row[0]
         if stored_module == module or is_qualname:
             result.append(
                 CallTraceRow(
                     module=module,
                     qualname=row[0],
                     arg_types=row[1],
                     return_type=row[2],
                     yield_type=row[3],
                 )
             )
     return result if len(result) < limit else result[:limit]
Exemple #6
0
 def test_trace_round_trip(self):
     trace = CallTrace(dummy_func, {'a': int, 'b': int}, int)
     assert CallTraceRow.from_trace(trace).to_trace() == trace