def testAsDict(self):
        result = mre_result.MreResult()

        with map_single_trace.TemporaryMapScript("""
      pi.FunctionRegistry.register(
          function MyMapFunction(result, model) {
            var canonicalUrl = model.canonicalUrl;
            result.addPair('result', {
                numProcesses: model.getAllProcesses().length
              });
          });
      """) as map_script:

            module = function_handle.ModuleToLoad(filename=map_script.filename)
            map_handle = function_handle.FunctionHandle(
                modules_to_load=[module], function_name='MyMapFunction')
            job = job_module.Job(map_handle, None)
            failure = failure_module.Failure(job, '2', '3', 'err', 'desc',
                                             'stack')
            result.AddFailure(failure)

            result.AddPair('foo', 'bar')

            result_dict = result.AsDict()

            self.assertEquals(result_dict['failures'], [failure.AsDict()])
            self.assertEquals(result_dict['pairs'], {'foo': 'bar'})
Example #2
0
    def testMapperDoesntAddValues(self):
        events = [{
            'pid': 1,
            'tid': 2,
            'ph': 'X',
            'name': 'a',
            'cat': 'c',
            'ts': 0,
            'dur': 10,
            'args': {}
        }, {
            'pid': 1,
            'tid': 2,
            'ph': 'X',
            'name': 'b',
            'cat': 'c',
            'ts': 3,
            'dur': 5,
            'args': {}
        }]
        trace_handle = file_handle.InMemoryFileHandle('/a.json',
                                                      json.dumps(events))

        with map_single_trace.TemporaryMapScript("""
      pi.FunctionRegistry.register(
          function MyMapFunction(results, model) {
      });
    """) as map_script:
            result = map_single_trace.MapSingleTrace(
                trace_handle, _Handle(map_script.filename))

        self.assertEquals(len(result.failures), 1)
        self.assertEquals(len(result.pairs), 0)
        f = result.failures[0]
        self.assertIsInstance(f, map_single_trace.NoResultsAddedFailure)
Example #3
0
    def testNoMapper(self):
        events = [{
            'pid': 1,
            'tid': 2,
            'ph': 'X',
            'name': 'a',
            'cat': 'c',
            'ts': 0,
            'dur': 10,
            'args': {}
        }, {
            'pid': 1,
            'tid': 2,
            'ph': 'X',
            'name': 'b',
            'cat': 'c',
            'ts': 3,
            'dur': 5,
            'args': {}
        }]
        trace_handle = file_handle.InMemoryFileHandle('/a.json',
                                                      json.dumps(events))

        with map_single_trace.TemporaryMapScript("""
    """) as map_script:
            result = map_single_trace.MapSingleTrace(
                trace_handle, _Handle(map_script.filename))

        self.assertEquals(len(result.failures), 1)
        self.assertEquals(len(result.pairs), 0)
        f = result.failures[0]
        self.assertIsInstance(f, map_single_trace.FunctionNotDefinedFailure)
Example #4
0
    def testMapperWithUnexpectedError(self):
        events = [
            {
                'pid': 1,
                'tid': 2,
                'ph': 'X',
                'name': 'a',
                'cat': 'c',
                'ts': 0,
                'dur': 10,
                'args': {}
            },
        ]
        trace_handle = file_handle.InMemoryFileHandle('/a.json',
                                                      json.dumps(events))

        with map_single_trace.TemporaryMapScript("""
          quit(100);
    """) as map_script:
            result = map_single_trace.MapSingleTrace(
                trace_handle, _Handle(map_script.filename))

        self.assertEquals(len(result.failures), 1)
        self.assertEquals(len(result.pairs), 0)
        f = result.failures[0]
        self.assertIsInstance(f, failure.Failure)
Example #5
0
    def testTraceDidntImport(self):
        trace_string = 'This is intentionally not a trace-formatted string.'
        trace_handle = file_handle.InMemoryFileHandle('/a.json', trace_string)

        with map_single_trace.TemporaryMapScript("""
      pi.FunctionRegistry.register(
          function MyMapFunction(results, model) {
          });
    """) as map_script:
            result = map_single_trace.MapSingleTrace(
                trace_handle, _Handle(map_script.filename))

        self.assertEquals(len(result.failures), 1)
        self.assertEquals(len(result.pairs), 0)
        f = result.failures[0]
        self.assertIsInstance(f, map_single_trace.TraceImportFailure)
Example #6
0
    def testPassingMapScript(self):
        events = [{
            'pid': 1,
            'tid': 2,
            'ph': 'X',
            'name': 'a',
            'cat': 'c',
            'ts': 0,
            'dur': 10,
            'args': {}
        }, {
            'pid': 1,
            'tid': 2,
            'ph': 'X',
            'name': 'b',
            'cat': 'c',
            'ts': 3,
            'dur': 5,
            'args': {}
        }]
        trace_handle = file_handle.InMemoryFileHandle('/a.json',
                                                      json.dumps(events))

        with map_single_trace.TemporaryMapScript("""
      pi.FunctionRegistry.register(
          function MyMapFunction(result, model) {
            var canonicalUrl = model.canonicalUrl;
            result.addPair('result', {
                numProcesses: model.getAllProcesses().length
              });
          });
    """) as map_script:
            result = map_single_trace.MapSingleTrace(
                trace_handle, _Handle(map_script.filename))

        self.assertFalse(result.failures)
        r = result.pairs['result']
        self.assertEquals(r['numProcesses'], 1)