Beispiel #1
0
def test_default_file_location_with_data_path(mocked_settings):
    """
    Find an admin file in the data location.

    In this case the logic won't find a file in the sys.argv0/sys.executable
    path and will drop back to DATA_DIR
    """
    settings, filepath, items = mocked_settings
    with mock.patch.object(mu.config, "DATA_DIR", os.path.dirname(filepath)):
        settings.init()

    assert settings.filepath == filepath
    assert all(settings[k] == items[k] for k in items)
Beispiel #2
0
def test_default_file_location_not_frozen(mocked_settings):
    """
    Finds an admin file in the application location, when Mu is run as if
    NOT frozen by PyInstaller.

    In this case the logic searches in the path of sys.argv[0]
    """
    settings, filepath, items = mocked_settings
    with mock.patch.object(sys, "argv", [filepath]):
        settings.init()

    assert settings.filepath == filepath
    assert all(settings[k] == items[k] for k in items)
Beispiel #3
0
def test_default_file_location_frozen(mocked_settings):
    """
    Find an admin file in the application location when it has been frozen
    using PyInstaller.

    In this case the logic searches in the path of sys.executable
    """
    settings, filepath, items = mocked_settings
    with mock.patch.object(sys, "executable", filepath), mock.patch.object(
            sys, "frozen", True,
            create=True), mock.patch.object(platform,
                                            "system",
                                            return_value="not_Darwin"):
        settings.init()

    assert settings.filepath == filepath
    assert all(settings[k] == items[k] for k in items)
Beispiel #4
0
def test_default_file_location_frozen_osx(mocked_settings):
    """
    Find an admin file in the application location when it has been frozen
    using PyInstaller on macOS (as the path is different in the app bundle).

    In this case the logic searches three levels up from the
    path if sys.executable
    """
    settings, filepath, items = mocked_settings
    dirpath_plus_3 = os.path.join(os.path.dirname(filepath), "a", "b", "c")
    exe_filepath = os.path.join(dirpath_plus_3, "python.exe")

    with mock.patch.object(sys, "executable", exe_filepath), mock.patch.object(
            sys, "frozen", True,
            create=True), mock.patch("platform.system", return_value="Darwin"):
        settings.init()

    assert settings.filepath == filepath
    assert all(settings[k] == items[k] for k in items)