File: test_merge_or_copy_pyproject.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 (40 lines) | stat: -rw-r--r-- 1,429 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
import tomli_w

try:
    import tomllib
except ModuleNotFoundError:
    import tomli as tomllib


def test_copy_pyproject_toml(convert_command, tmp_path):
    base_config_file = convert_command.base_path / "pyproject.toml"
    briefcase_config_file = tmp_path / "input" / "pyproject.toml"

    briefcase_config_file.parent.mkdir(parents=True)
    briefcase_config_file.write_text("placeholder", encoding="utf-8")
    convert_command.merge_or_copy_pyproject(briefcase_config_file)

    assert base_config_file.is_file()
    with open(base_config_file, encoding="utf-8") as file:
        assert file.read() == "placeholder"


def test_merge_pyproject(convert_command, tmp_path):
    base_config_file = convert_command.base_path / "pyproject.toml"
    briefcase_config_file = tmp_path / "input" / "pyproject.toml"

    base_config_content = {"placeholder1": "a"}
    briefcase_config_content = {"placeholder2": "b"}
    merged_dict = {**base_config_content, **briefcase_config_content}

    with open(base_config_file, "wb") as file:
        tomli_w.dump(base_config_content, file)

    briefcase_config_file.parent.mkdir(parents=True)
    with open(briefcase_config_file, "wb") as file:
        tomli_w.dump(briefcase_config_content, file)

    convert_command.merge_or_copy_pyproject(briefcase_config_file)

    merged_content = base_config_file.read_text(encoding="utf-8")
    assert merged_dict == tomllib.loads(merged_content)