-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
Copy pathconftest.py
134 lines (88 loc) · 3.08 KB
/
conftest.py
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import os
import shutil
import tempfile
from typing import Any
from typing import Dict
import httpretty
import pytest
from poetry.config.config import Config as BaseConfig
from poetry.config.dict_config_source import DictConfigSource
from poetry.utils._compat import Path
from tests.helpers import mock_clone
from tests.helpers import mock_download
class Config(BaseConfig):
def get(self, setting_name, default=None): # type: (str, Any) -> Any
self.merge(self._config_source.config)
self.merge(self._auth_config_source.config)
return super(Config, self).get(setting_name, default=default)
def raw(self): # type: () -> Dict[str, Any]
self.merge(self._config_source.config)
self.merge(self._auth_config_source.config)
return super(Config, self).raw()
def all(self): # type: () -> Dict[str, Any]
self.merge(self._config_source.config)
self.merge(self._auth_config_source.config)
return super(Config, self).all()
@pytest.fixture
def config_source():
source = DictConfigSource()
source.add_property("cache-dir", "/foo")
return source
@pytest.fixture
def auth_config_source():
source = DictConfigSource()
return source
@pytest.fixture
def config(config_source, auth_config_source, mocker):
import keyring
from keyring.backends.fail import Keyring
keyring.set_keyring(Keyring())
c = Config()
c.merge(config_source.config)
c.set_config_source(config_source)
c.set_auth_config_source(auth_config_source)
mocker.patch("poetry.factory.Factory.create_config", return_value=c)
mocker.patch("poetry.config.config.Config.set_config_source")
return c
@pytest.fixture(autouse=True)
def download_mock(mocker):
# Patch download to not download anything but to just copy from fixtures
mocker.patch("poetry.utils.inspector.Inspector.download", new=mock_download)
@pytest.fixture
def environ():
original_environ = dict(os.environ)
yield
os.environ.clear()
os.environ.update(original_environ)
@pytest.fixture(autouse=True)
def git_mock(mocker):
# Patch git module to not actually clone projects
mocker.patch("poetry.core.vcs.git.Git.clone", new=mock_clone)
mocker.patch("poetry.core.vcs.git.Git.checkout", new=lambda *_: None)
p = mocker.patch("poetry.core.vcs.git.Git.rev_parse")
p.return_value = "9cf87a285a2d3fbb0b9fa621997b3acc3631ed24"
@pytest.fixture
def http():
httpretty.enable()
yield httpretty
httpretty.disable()
@pytest.fixture
def fixture_dir():
def _fixture_dir(name):
return Path(__file__).parent / "fixtures" / name
return _fixture_dir
@pytest.fixture
def tmp_dir():
dir_ = tempfile.mkdtemp(prefix="poetry_")
yield dir_
shutil.rmtree(dir_)
@pytest.fixture
def mocked_open_files(mocker):
files = []
original = Path.open
def mocked_open(self, *args, **kwargs):
if self.name in {"pyproject.toml"}:
return mocker.MagicMock()
return original(self, *args, **kwargs)
mocker.patch("poetry.utils._compat.Path.open", mocked_open)
yield files