File: conftest.py

package info (click to toggle)
twine 6.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 836 kB
  • sloc: python: 4,372; makefile: 23; sh: 6
file content (85 lines) | stat: -rw-r--r-- 2,034 bytes parent folder | download | duplicates (3)
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
import getpass
import logging.config
import textwrap

import pytest
import rich

from twine import settings
from twine import utils


@pytest.fixture(autouse=True)
def configure_output():
    """
    Disable colored output and line wrapping before each test.

    Some tests (e.g. test_main.py) will end up calling (and making assertions based on)
    twine.cli.configure_output, which overrides this configuration. This fixture should
    prevent that leaking into subsequent tests.
    """
    rich.reconfigure(
        no_color=True,
        color_system=None,
        emoji=False,
        highlight=False,
        width=500,
    )

    logging.config.dictConfig(
        {
            "version": 1,
            "handlers": {
                "console": {
                    "class": "logging.StreamHandler",
                }
            },
            "loggers": {
                "twine": {
                    "handlers": ["console"],
                },
            },
        }
    )


@pytest.fixture()
def config_file(tmpdir, monkeypatch):
    path = tmpdir / ".pypirc"
    # Mimic common case of .pypirc in home directory
    monkeypatch.setattr(utils, "DEFAULT_CONFIG_FILE", path)
    return path


@pytest.fixture
def write_config_file(config_file):
    def _write(config):
        config_file.write(textwrap.dedent(config))
        return config_file

    return _write


@pytest.fixture()
def make_settings(write_config_file):
    """Return a factory function for settings.Settings with defaults."""
    default_config = """
        [pypi]
        username:foo
        password:bar
    """

    def _settings(config=default_config, **settings_kwargs):
        config_file = write_config_file(config)

        settings_kwargs.setdefault("sign_with", None)
        settings_kwargs.setdefault("config_file", config_file)

        return settings.Settings(**settings_kwargs)

    return _settings


@pytest.fixture
def entered_password(monkeypatch):
    monkeypatch.setattr(getpass, "getpass", lambda prompt: "entered pw")