def test_randomize_all(m_rand_stats, m_edit_prom, m_rand_char, m_mod_stats, m_app):
    """ Test the _randomize_all method in the controller """
    handle = RandomizerHandler(m_app)
    # Test not editing promotions
    with mock.patch.dict(
        "controller.CONFIG",
        {"randomize": {"classes": {"all_master_seals": {"enabled": False}}}},
    ):
        handle._randomize_all()
        m_edit_prom.assert_not_called()
        for obj in {m_rand_stats, m_rand_char, m_mod_stats}:
            obj.assert_called_once()
            obj.reset_mock()

    # Test not editing promotions
    with mock.patch.dict(
        "controller.CONFIG",
        {"randomize": {"classes": {"all_master_seals": {"enabled": True}}}},
    ):
        handle._randomize_all()
        for obj in {m_edit_prom, m_rand_stats, m_rand_char, m_mod_stats}:
            obj.assert_called_once()
            obj.reset_mock()

    # Test invalid config error
    m_rand_stats.side_effect = InvalidConfigError("foo")
    # Mock out the QDialog box
    with mock.patch("controller.QMessageBox"):
        handle._randomize_all()
示例#2
0
def create_buttons(parent):
    """ Create all the push buttons """

    buttons = {
        "randomize": QPushButton("Randomize!", parent),
        "browse": QPushButton("Browse Rom Path", parent),
    }

    buttons["browse"].clicked.connect(lambda: browse_handler(parent))
    buttons["randomize"].clicked.connect(
        lambda: RandomizerHandler(parent).randomize())

    return buttons
def test_randomize(m_config, m_app):
    """ Test the randomize method of controller """
    handle = RandomizerHandler(m_app)
    m_rom_data = (VERSION_LOCATION + 1) * b"0"
    m_open = mock.mock_open(read_data=m_rom_data)
    with mock.patch("builtins.open", m_open):
        with mock.patch("dialogs.VersionPrompt") as m_version:
            with mock.patch("controller.RandomizerHandler._randomize_all"):
                handle.randomize()
                # Check that data was read in correctly
                assert handle.rom_data == m_rom_data
                # Version should be unkown. Make sure user was prompted
                assert m_version.exec_.called_once()

    # Test handling IOError
    with mock.patch("builtins.open", side_effect=IOError("foo")):
        handle.randomize()
        m_app.labels["status"].setText.assert_called_with("Status: Error! foo")

    # Test handling random generic exceptions
    with mock.patch("builtins.open", m_open):
        with mock.patch(
            "controller.RandomizerHandler._randomize_all", side_effect=Exception("bar")
        ):
            with mock.patch("dialogs.VersionPrompt"):
                handle.randomize()
                m_app.labels["status"].setText.assert_called_with("Status: Error! bar")

    # Test FE7 sav file was also moved during FE7 randomization
    with mock.patch("builtins.open", m_open):
        with mock.patch("controller.RandomizerHandler._randomize_all"):
            with mock.patch("controller.get_fe_version") as m_fe_version:
                m_fe_version.return_value = FEVersions.FE7
                with mock.patch("shutil.copy") as m_copy:
                    handle.randomize()
                    m_copy.assert_called()

                # Test IOError during final write
                with mock.patch("shutil.copy", side_effect=IOError("baz")):
                    handle.randomize()
                    m_app.labels["status"].setText.assert_called_with(
                        "Status: Error! baz"
                    )
def test_edit_promotions(m_app):
    """ Test the modify_stats method in controller """
    handle = RandomizerHandler(m_app)
    with mock.patch("controller.create_prom_editor"):
        handle._edit_promotions()
def test_modify_stats(m_app, m_get_filters):
    """ Test the modify_stats method in controller """
    handle = RandomizerHandler(m_app)
    with mock.patch("controller.create_stat_modifier"):
        handle._modify_stats()
def test_randomize_characters(m_app, m_get_filters):
    """ Test the randomize_characters method in controller """
    handle = RandomizerHandler(m_app)
    with mock.patch("controller.create_character_editor"):
        handle._randomize_characters()