File: test_update_emulator_config.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 (89 lines) | stat: -rw-r--r-- 2,114 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import pytest


@pytest.fixture
def test_device(tmp_path):
    """Create an AVD configuration file."""
    config_file = tmp_path / "home/.android/avd/testDevice.avd/config.ini"
    config_file.parent.mkdir(parents=True)

    # Write a default config. It contains:
    # * blank lines
    # * a key whose value explicitly contains an equals sign.
    with config_file.open("w", encoding="utf-8") as f:
        f.write(
            """
avd.ini.encoding=UTF-8
hw.device.manufacturer=Google
hw.device.name=pixel
weird.key=good=bad

PlayStore.enabled=no
avd.name=beePhone
disk.cachePartition=yes
disk.cachePartition.size=42M
"""
        )

    return config_file


def test_update_existing(android_sdk, test_device):
    """Existing keys in an Android AVD config can be updated."""
    # Update 2 keys in the config
    android_sdk.update_emulator_config(
        "testDevice",
        {
            "avd.name": "testDevice",
            "disk.cachePartition.size": "37MB",
        },
    )

    with test_device.open(encoding="utf-8") as f:
        content = f.read()

    # Keys have been updated, order is preserved.
    assert (
        content
        == """avd.ini.encoding=UTF-8
hw.device.manufacturer=Google
hw.device.name=pixel
weird.key=good=bad
PlayStore.enabled=no
avd.name=testDevice
disk.cachePartition=yes
disk.cachePartition.size=37MB
"""
    )


def test_new_content(android_sdk, test_device):
    """New keys can be added to an Android AVD config."""
    # Add 2 new keys to the config
    android_sdk.update_emulator_config(
        "testDevice",
        {
            "skin.name": "pixel_3a",
            "skin.path": "skins/pixel_3a",
        },
    )

    with test_device.open(encoding="utf-8") as f:
        content = f.read()

    # New keys are appended to the end of the file
    # Newlines have been dropped
    assert (
        content
        == """avd.ini.encoding=UTF-8
hw.device.manufacturer=Google
hw.device.name=pixel
weird.key=good=bad
PlayStore.enabled=no
avd.name=beePhone
disk.cachePartition=yes
disk.cachePartition.size=42M
skin.name=pixel_3a
skin.path=skins/pixel_3a
"""
    )