def test_explain(self):
        """ Verifies explain runs if there is a success [aka _explain is implemented]."""
        group_result = ResultData()
        group_result.outcome = outcomes.FOR
        group_result.data = [self.stance]

        self.decision.MI_group = group_result
        self.decision.split_group = [self.stance, self.stance1]

        result = self.strategy.run()
        self.assertTrue(result)

        self.strategy.explain()
    def test_run_fail_no_opposing_groups(self):
        """ Verifies that run() fails if there is no groups opposing the member's credo."""

        self.stance.importance = importance.A

        credo_result = ResultData()
        credo_result.outcome = outcomes.FOR
        credo_result.data = [self.stance]

        self.decision.MI_credo = credo_result
        self.member.party = self.INDEPENDENT

        result = self.strategy.run()
        self.assertFalse(result)
        self.assertFalse(self.strategy._success)
        self.assertEquals(self.decision.result, None)
        self.assertEquals(self.decision.reason, None)
    def test_explain(self):
        """ Verifies explain runs if there is a success [aka _explain is implemented]."""
        self.stance.importance = importance.A

        credo_result = ResultData()
        credo_result.outcome = outcomes.AGN
        credo_result.data = [self.stance]

        self.decision.MI_credo = credo_result
        self.member.party = self.INDEPENDENT

        self.stance1.source = self.INDEPENDENT
        self.decision.groups_for = [self.stance1]

        result = self.strategy.run()
        self.assertTrue(result)
        self.strategy.explain()
    def test_run_success_AGN(self):
        """ Verifies that run() successfully sets an AGN decision"""
        self.stance.importance = importance.A

        credo_result = ResultData()
        credo_result.outcome = outcomes.AGN
        credo_result.data = [self.stance]

        self.decision.MI_credo = credo_result
        self.member.party = self.INDEPENDENT

        self.stance1.source = self.INDEPENDENT
        self.decision.groups_for = [self.stance1]

        result = self.strategy.run()
        self.assertTrue(result)
        self.assertTrue(self.strategy._success)
        self.assertEquals(self.decision.result, outcomes.AGN)
    def test_run_fail_no_party(self):
        """ Verifies that run() fails if there is no party."""

        self.stance.importance = importance.A

        credo_result = ResultData()
        credo_result.outcome = outcomes.FOR
        credo_result.data = [self.stance]

        self.decision.MI_credo = credo_result

        self.stance1.source = self.INDEPENDENT
        self.decision.groups_agn = [self.stance1]

        result = self.strategy.run()
        self.assertFalse(result)
        self.assertFalse(self.strategy._success)
        self.assertEquals(self.decision.result, None)
        self.assertEquals(self.decision.reason, None)
    def test_run_fail_credo_stance_not_most_importance(self):
        """ Verifies that run() fails if the member doesn't care too strongly
        about the credo stances."""

        self.stance.importance = importance.B

        credo_result = ResultData()
        credo_result.outcome = outcomes.FOR
        credo_result.data = [self.stance]

        self.decision.MI_credo = credo_result
        self.member.party = self.INDEPENDENT

        self.stance1.source = self.INDEPENDENT
        self.decision.groups_agn = [self.stance1]

        result = self.strategy.run()
        self.assertFalse(result)
        self.assertFalse(self.strategy._success)
        self.assertEquals(self.decision.result, None)
        self.assertEquals(self.decision.reason, None)
    def test_run_fail_no_split_group(self):
        """ Verifies that the strategy fails when there is no split constituency."""
        group_result = ResultData()
        group_result.outcome = outcomes.FOR
        group_result.data = [self.stance]

        credo_result = ResultData()
        credo_result.outcome = outcomes.FOR
        credo_result.data = [self.stance]

        self.decision.MI_group = group_result
        self.decision.MI_credo = credo_result

        self.decision.for_stances = [self.stance]
        result = self.strategy.run()

        self.assertFalse(result)
        self.assertFalse(self.strategy._success)
        self.assertEquals(self.decision.result, None)
        self.assertEquals(self.decision.reason, None)
    def test_run_success_AGN(self):
        """ Verifies that run() successfully sets an AGN decision"""
        group_result = ResultData()
        group_result.outcome = outcomes.AGN
        group_result.data = [self.stance]

        credo_result = ResultData()
        credo_result.outcome = outcomes.AGN
        credo_result.data = [self.stance]

        self.decision.MI_group = group_result
        self.decision.MI_credo = credo_result
        self.decision.split_group = [self.stance, self.stance1]

        self.decision.agn_stances = [self.stance, self.stance]
        result = self.strategy.run()

        self.assertTrue(result)
        self.assertTrue(self.strategy._success)
        self.assertEquals(self.decision.result, outcomes.AGN)
        self.assertEquals(self.decision.reason, self.decision.agn_stances)
    def test_run_fail_no_consensus(self):
        """ Verifies that the strategy fails when no consensus is reached."""
        group_result = ResultData()
        group_result.outcome = outcomes.FOR
        group_result.data = [self.stance]

        credo_result = ResultData()
        credo_result.outcome = outcomes.AGN
        credo_result.data = [self.stance1]

        self.decision.MI_group = group_result
        self.decision.MI_credo = credo_result
        self.decision.split_group = [self.stance, self.stance1]

        self.decision.for_stances = [self.stance]
        result = self.strategy.run()

        self.assertFalse(result)
        self.assertFalse(self.strategy._success)
        self.assertEquals(self.decision.result, None)
        self.assertEquals(self.decision.reason, None)
Пример #10
0
def _compare_stances(fors, agns):
    """This functions compares the stances to see which side has the most
    compelling reasons. It does so by checking which side has the largest number
    and most important stances supporting it.
    
    Arguments:
        fors: the list of stances supporting the bill to decide on
        agns: the list of stances against the bill to decide on
                    
    Returns:
        A list containing the strongest arguments for or against the bill.
        Returns an empty list if both sides are equally compelling.

    Notes:
        Both lists are first sorted by importance. Then, it goes through and
        compares each stance.
            
        If one list runs out before the other, the longest list is considered
        to have the most compelling stances.
            
        If one list is found to have a stance of stronger importance than
        the other on a give iteration of the for loop, that list is
        considered to be the most important and is chosen.
    """
    fors.sort(key=lambda stance: stance.sort_key, reverse=True)
    agns.sort(key=lambda stance: stance.sort_key, reverse=True)

    # base_stance is used in the enum. Once an array runs out of stances,
    # this will be mapped to be compared to the stances in the other list. Since
    # Z is not an importance actually assigned in the DB, this is guaranteed to
    # fail so that the longer list will be detected as the winner.
    #
    # The sort key is also needed to properly set the default. It will take the
    # source key from whichever array will last longer. This will ensure that
    # the stance is less than the next key it will be compared to.
    temp_stance = None
    if fors and len(fors) > len(agns):
        temp_stance = fors[0]
    elif agns and len(agns) > len(fors):
        temp_stance = agns[0]

    base_stance = Stance()
    base_stance.importance = importance.Z
    base_stance.sort_key = temp_stance._sort_key if temp_stance else None

    enum = enumerate(itertools.izip_longest(fors, agns, fillvalue=base_stance))
    for index, (a_for, an_agn) in enum:
        if a_for.sort_key > an_agn.sort_key:
            result = ResultData()
            result.outcome = outcomes.FOR
            result.data = util.remove_less_important_stances(fors[index:])
            logger.LOGGER.info("MI stance is FOR the bill.")
            return result
        if an_agn.sort_key > a_for.sort_key:
            result = ResultData()
            result.outcome = outcomes.AGN
            result.data = util.remove_less_important_stances(agns[index:])
            logger.LOGGER.info("MI stance is AGN the bill.")
            return result
    logger.LOGGER.info("MI stance is neutral on the bill.")
    return None