def test_add_issue(self):
        known_bugs = {
            IssuesManager.SUMMARY_OUT_BUGS_ROOT: [{
                'id': 'https://bugs.launchpad.net/bugs/1',
                'desc': None,
                'origin': 'testplugin.01part'
            }]
        }
        with open(os.path.join(self.plugin_tmp_dir, 'known_bugs.yaml'),
                  'w') as fd:
            fd.write(yaml.dump(known_bugs))

        mgr = IssuesManager()
        mgr.add(LaunchpadBug(2, None))
        ret = mgr.load_bugs()
        expected = {
            IssuesManager.SUMMARY_OUT_BUGS_ROOT: [{
                'id': 'https://bugs.launchpad.net/bugs/1',
                'desc': None,
                'origin': 'testplugin.01part'
            }, {
                'id': 'https://bugs.launchpad.net/bugs/2',
                'desc': None,
                'origin': 'testplugin.01part'
            }]
        }
        self.assertEqual(ret, expected)
Beispiel #2
0
    def run(self):
        mgr = IssuesManager()
        for scenario in self.scenarios:
            results = {}
            log.debug("running scenario: %s", scenario.name)
            # run all conclusions and use highest priority result(s). One or
            # more conclusions may share the same priority. All conclusions
            # that match and share the same priority will be used.
            for name, conc in scenario.conclusions.items():
                if conc.reached(scenario.checks):
                    if conc.priority:
                        priority = conc.priority.value
                    else:
                        priority = 1

                    if priority in results:
                        results[priority].append(conc)
                    else:
                        results[priority] = [conc]

                    log.debug("conclusion reached: %s (priority=%s)", name,
                              priority)

            if results:
                highest = max(results.keys())
                log.debug("selecting highest priority=%s conclusions (%s)",
                          highest, len(results[highest]))
                for conc in results[highest]:
                    mgr.add(conc.issue, context=conc.context)
            else:
                log.debug("no conclusions reached")
 def test_issue_not_machine_readable(self):
     mgr = IssuesManager()
     mgr.add(MemoryWarning("test"))
     ret = mgr.load_issues()
     self.assertEqual(
         ret, {
             IssuesManager.SUMMARY_OUT_ISSUES_ROOT: {
                 'MemoryWarnings': ['test (origin=testplugin.01part)']
             }
         })
 def test_add_issue_first(self):
     mgr = IssuesManager()
     mgr.add(LaunchpadBug(1, None))
     ret = mgr.load_bugs()
     self.assertEqual(
         ret, {
             IssuesManager.SUMMARY_OUT_BUGS_ROOT:
             [{
                 'id': 'https://bugs.launchpad.net/bugs/1',
                 'desc': None,
                 'origin': 'testplugin.01part'
             }]
         })
 def test_issue_machine_readable(self):
     setup_config(MACHINE_READABLE=True)
     mgr = IssuesManager()
     mgr.add(MemoryWarning("test"))
     ret = mgr.load_issues()
     self.assertEqual(
         ret, {
             IssuesManager.SUMMARY_OUT_ISSUES_ROOT:
             [{
                 'type': 'MemoryWarning',
                 'desc': 'test',
                 'origin': 'testplugin.01part'
             }]
         })
 def test_add_issue_w_empty_context(self):
     setup_config(MACHINE_READABLE=True)
     ctxt = IssueContext()
     mgr = IssuesManager()
     mgr.add(MemoryWarning("test"), ctxt)
     ret = mgr.load_issues()
     self.assertEqual(
         ret, {
             IssuesManager.SUMMARY_OUT_ISSUES_ROOT:
             [{
                 'type': 'MemoryWarning',
                 'desc': 'test',
                 'origin': 'testplugin.01part'
             }]
         })
 def test_add_issue_empty_context(self):
     setup_config(MACHINE_READABLE=True)
     ctxt = IssueContext()
     ctxt.set(linenumber=123, path='/foo/bar')
     mgr = IssuesManager()
     mgr.add(MemoryWarning("test"), ctxt)
     ret = mgr.load_issues()
     self.assertEqual(
         ret, {
             IssuesManager.SUMMARY_OUT_ISSUES_ROOT:
             [{
                 'type': 'MemoryWarning',
                 'desc': 'test',
                 'context': {
                     'path': '/foo/bar',
                     'linenumber': 123
                 },
                 'origin': 'testplugin.01part'
             }]
         })