Example #1
0
def test_register_menu_adds_new_menu_to_menus():
    base_menu = get_base_menu()
    test_menu = get_base_menu()

    game = BaseGame(main_menu=base_menu)
    game.register_menu("test menu", test_menu)

    assert game.menus["test menu"] is test_menu
    assert len(game.menus) == 2
Example #2
0
def test_register_interactive_zone(input_zone, output_zone):

    menu = get_base_menu()

    menu.register_interactive_zone(*input_zone)

    assert output_zone in menu.get_interactive_zones()
Example #3
0
def test_button_registers_interactive_zone_correctly():

    button = Button(0, 0, 1, 1, interaction)
    menu = get_base_menu()

    button.register_with_menu(menu)

    assert (0, 0, 1, 1, button._interaction) in menu.get_interactive_zones()
Example #4
0
def test_creating_game_with_main_menu_sets_active_screen_and_menu():
    menu = get_base_menu()

    game = BaseGame(main_menu=menu)

    assert game.active_screen is menu
    assert game.active_menu is menu
    assert game.maps == {}
Example #5
0
def test_registering_interactive_zone_within_interactive_zone_raises_exception(
        zone_one, zone_two):
    """ Test that registering a zone within a zone raises an exception """

    menu = get_base_menu()
    menu.register_interactive_zone(*zone_one)

    with pytest.raises(BaseMenu.OverlappingInteractiveZoneException):
        menu.register_interactive_zone(*zone_two)
Example #6
0
def test_get_interactive_zones_cannot_alter_interactive_zones():
    menu = get_base_menu()
    zone = (0, 0, 0, 0, interaction)
    menu.register_interactive_zone(*zone)

    interactive_zones = menu.get_interactive_zones()
    interactive_zones.clear()

    assert len(menu.get_interactive_zones()) > 0
Example #7
0
def test_interactive_zone_count_returns_correct_count():
    menu = get_base_menu()
    menu.register_interactive_zone(0, 0, 0, 0, interaction)
    menu.register_interactive_zone(1, 1, 1, 1, interaction)
    menu.register_interactive_zone(2, 2, 2, 2, interaction)

    count = menu.interactive_zone_count()

    assert count == 3
Example #8
0
def test_call_interactive_zone_by_index_calls_correct_interaction():

    interaction_mock = Mock
    menu = get_base_menu()
    menu.register_interactive_zone(0, 0, 0, 0, interaction)
    menu.register_interactive_zone(1, 1, 1, 1, interaction_mock)

    menu.call_interactive_zone_by_index(1, Mock())

    assert interaction_mock.called
Example #9
0
def test_button_clicked_calls_interaction():

    interaction_mock = Mock()
    button = Button(0, 0, 1, 1, interaction_mock)
    menu = get_base_menu()
    button.register_with_menu(menu)

    menu.call_interactive_zone_by_click(0, 0, 1, 1, Mock())

    assert interaction_mock.called
Example #10
0
def test_clicking_interactive_zone_calls_interaction(click):

    interaction_mock = Mock()

    menu = get_base_menu()
    menu.register_interactive_zone(0, 0, 2, 2, interaction_mock)

    menu.call_interactive_zone_by_click(*click, Mock())

    assert interaction_mock.called
Example #11
0
def test_open_menu_sets_the_menu():
    base_menu = get_base_menu()

    game = BaseGame(main_menu=base_menu)
    game.register_menu("menu", base_menu)

    game.open_menu("menu")

    assert game.active_menu is base_menu
    assert game.active_screen is base_menu
Example #12
0
def test_open_menu_unloads_current_map(unload_map_mock):
    base_map = generate_valid_map()
    base_menu = get_base_menu()

    game = BaseGame(initial_map=base_map)
    game.register_menu("menu", base_menu)

    game.open_menu("menu")

    assert unload_map_mock.called
Example #13
0
def test_click_not_starting_or_not_ending_in_button_do_not_call_interaction(
        click):

    interaction_mock = Mock()

    menu = get_base_menu()
    menu.register_interactive_zone(1, 1, 1, 1, interaction_mock)

    menu.call_interactive_zone_by_click(*click, Mock())

    assert not interaction_mock.called
Example #14
0
def test_interaction_can_call_game_context():
    """ Test that when an interaction is called it has access to game context."""
    def game_interaction(game_context):
        game_context.call()

    context = Mock()
    menu = get_base_menu()
    menu.register_interactive_zone(0, 0, 0, 0, game_interaction)

    menu.call_interactive_zone_by_index(0, context)

    assert context.call.called
Example #15
0
def test_get_interactive_zones_returns_all_interactive_zone():
    menu = get_base_menu()

    zone_one = (0, 0, 0, 0, interaction)
    zone_two = (1, 1, 1, 1, interaction)
    zone_three = (2, 2, 2, 2, interaction)
    zone_four = (3, 3, 3, 3, interaction)

    menu.register_interactive_zone(*zone_one)
    menu.register_interactive_zone(*zone_two)
    menu.register_interactive_zone(*zone_three)
    menu.register_interactive_zone(*zone_four)

    interactive_zones = menu.get_interactive_zones()

    assert zone_one in interactive_zones
    assert zone_two in interactive_zones
    assert zone_three in interactive_zones
    assert zone_four in interactive_zones
    assert len(interactive_zones) == 4