Esempio n. 1
0
def test_possible_actions_empty():
    state = MagicMock()

    reach = ResolverReach({}, {}, frozenset(), MagicMock())
    options = list(reach.possible_actions(state))

    assert options == []
Esempio n. 2
0
def test_possible_actions_no_resources():
    state = MagicMock()

    reach = ResolverReach([MagicMock(), MagicMock()], {}, frozenset(),
                          MagicMock())
    options = list(reach.possible_actions(state))

    assert options == []
Esempio n. 3
0
def test_possible_actions_with_event():
    logic = MagicMock()
    state = MagicMock()
    event = MagicMock(spec=EventNode)
    state.has_resource.return_value = False

    # Run
    reach = ResolverReach([event], {}, frozenset(), logic)
    options = list(reach.possible_actions(state))

    # Assert
    assert options == [event]
    event.resource.assert_called_once_with()
    state.has_resource.assert_called_once_with(event.resource.return_value)
    logic.get_additional_requirements.assert_called_once_with(event)
    logic.get_additional_requirements.return_value.satisfied.assert_called_once_with(
        state.resources, state.resource_database)
Esempio n. 4
0
def test_possible_actions_no_resources():
    state = MagicMock()
    node_a = MagicMock()
    node_b = MagicMock()
    node_b.can_collect.return_value = False

    type(node_a).is_resource_node = prop_a = PropertyMock(return_value=False)
    type(node_b).is_resource_node = prop_b = PropertyMock(return_value=True)

    # Run
    reach = ResolverReach({node_a: 1, node_b: 1}, {}, frozenset(), MagicMock())
    options = list(action for action, damage in reach.possible_actions(state))

    # Assert
    assert options == []
    prop_a.assert_called_once_with()
    prop_b.assert_called_once_with()
    node_b.can_collect.assert_called_once_with(state.patches, state.resources)
Esempio n. 5
0
def test_possible_actions_with_event():
    logic = MagicMock()
    state = MagicMock()

    event = MagicMock(spec=EventNode)
    type(event).is_resource_node = prop = PropertyMock(return_value=True)
    event.can_collect.return_value = True

    # Run
    reach = ResolverReach({event: 1}, {}, frozenset(), logic)
    options = list(action for action, damage in reach.possible_actions(state))

    # Assert
    assert options == [event]
    prop.assert_called_once_with()
    event.can_collect.assert_called_once_with(state.patches, state.resources)
    logic.get_additional_requirements.assert_called_once_with(event)
    logic.get_additional_requirements.return_value.satisfied.assert_called_once_with(
        state.resources, 1)
def test_possible_actions_with_event():
    logic = MagicMock()
    state = MagicMock()

    event = MagicMock(spec=EventNode, name="event node")
    event.node_index = 0
    type(event).is_resource_node = prop = PropertyMock(return_value=True)
    event.can_collect.return_value = True

    logic.game.world_list.all_nodes = [event]

    # Run
    reach = ResolverReach({0: 1}, {}, frozenset(), logic)
    options = list(action for action, damage in reach.possible_actions(state))

    # Assert
    assert options == [event]
    prop.assert_called_once_with()
    state.node_context.assert_called_once_with()
    event.can_collect.assert_called_once_with(state.node_context.return_value)
    logic.get_additional_requirements.assert_called_once_with(event)
    logic.get_additional_requirements.return_value.satisfied.assert_called_once_with(
        state.resources, 1, state.resource_database)
def test_possible_actions_no_resources():
    state = MagicMock()
    node_a = MagicMock(name="node_a")
    node_b = MagicMock(name="node_b")
    node_b.can_collect.return_value = False
    logic = MagicMock()
    logic.game.world_list.all_nodes = [node_a, node_b]
    node_a.get_index.return_value = 0
    node_b.get_index.return_value = 1

    type(node_a).is_resource_node = prop_a = PropertyMock(return_value=False)
    type(node_b).is_resource_node = prop_b = PropertyMock(return_value=True)

    # Run
    reach = ResolverReach({0: 1, 1: 1}, {}, frozenset(), logic)
    options = list(action for action, damage in reach.possible_actions(state))

    # Assert
    assert options == []
    prop_a.assert_called_once_with()
    prop_b.assert_called_once_with()
    state.node_context.assert_called_once_with()
    node_b.can_collect.assert_called_once_with(state.node_context.return_value)