File: test_cleanup_app_support_package.py

package info (click to toggle)
python-briefcase 0.3.22-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,300 kB
  • sloc: python: 59,405; makefile: 57
file content (52 lines) | stat: -rw-r--r-- 1,661 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import shutil
from unittest import mock

from ...utils import create_file


def test_no_support_path(create_command, myapp, no_support_path_index):
    """If support_path is not listed in briefcase.toml, no cleanup will be performed."""
    create_command.tools.file.download = mock.MagicMock()
    create_command.cleanup_app_support_package(myapp)
    create_command.tools.file.download.assert_not_called()


def test_support_path_does_not_exist(
    create_command,
    myapp,
    app_requirements_path_index,
):
    """If support_path is defined, but the folder doesn't exist, no cleanup is
    needed."""
    create_command.tools.shutil = mock.MagicMock(spec_set=shutil)

    create_command.cleanup_app_support_package(myapp)

    # No cleanup was performed.
    create_command.tools.shutil.assert_not_called()


def test_cleanup_support_package(
    create_command,
    myapp,
    support_path,
    app_requirements_path_index,
):
    """If a support package already exists, it can be cleaned up."""

    # Mock an existing support file
    create_file(support_path / "old/trash.txt", "Old support file")

    # Mock shutil so we can confirm that rmtree is called,
    # but we still want the side effect of calling it
    create_command.tools.shutil = mock.MagicMock(spec_set=shutil)
    create_command.tools.shutil.rmtree.side_effect = shutil.rmtree

    # Re-install the support package
    create_command.cleanup_app_support_package(myapp)

    # The old support package was deleted
    create_command.tools.shutil.rmtree.assert_called_with(support_path)

    # Confirm that the old support files have been removed
    assert not support_path.exists()