|
4 | 4 | import tempfile
|
5 | 5 | import json
|
6 | 6 |
|
7 |
| -from py.test import ensuretemp |
8 |
| -from pytest import mark |
| 7 | +from pytest import mark, fixture |
| 8 | + |
9 | 9 | from docker.utils import config
|
10 | 10 |
|
11 | 11 | try:
|
|
15 | 15 |
|
16 | 16 |
|
17 | 17 | class FindConfigFileTest(unittest.TestCase):
|
18 |
| - def tmpdir(self, name): |
19 |
| - tmpdir = ensuretemp(name) |
20 |
| - self.addCleanup(tmpdir.remove) |
21 |
| - return tmpdir |
| 18 | + |
| 19 | + @fixture(autouse=True) |
| 20 | + def tmpdir(self, tmpdir): |
| 21 | + self.mkdir = tmpdir.mkdir |
22 | 22 |
|
23 | 23 | def test_find_config_fallback(self):
|
24 |
| - tmpdir = self.tmpdir('test_find_config_fallback') |
| 24 | + tmpdir = self.mkdir('test_find_config_fallback') |
25 | 25 |
|
26 | 26 | with mock.patch.dict(os.environ, {'HOME': str(tmpdir)}):
|
27 | 27 | assert config.find_config_file() is None
|
28 | 28 |
|
29 | 29 | def test_find_config_from_explicit_path(self):
|
30 |
| - tmpdir = self.tmpdir('test_find_config_from_explicit_path') |
| 30 | + tmpdir = self.mkdir('test_find_config_from_explicit_path') |
31 | 31 | config_path = tmpdir.ensure('my-config-file.json')
|
32 | 32 |
|
33 | 33 | assert config.find_config_file(str(config_path)) == str(config_path)
|
34 | 34 |
|
35 | 35 | def test_find_config_from_environment(self):
|
36 |
| - tmpdir = self.tmpdir('test_find_config_from_environment') |
| 36 | + tmpdir = self.mkdir('test_find_config_from_environment') |
37 | 37 | config_path = tmpdir.ensure('config.json')
|
38 | 38 |
|
39 | 39 | with mock.patch.dict(os.environ, {'DOCKER_CONFIG': str(tmpdir)}):
|
40 | 40 | assert config.find_config_file() == str(config_path)
|
41 | 41 |
|
42 | 42 | @mark.skipif("sys.platform == 'win32'")
|
43 | 43 | def test_find_config_from_home_posix(self):
|
44 |
| - tmpdir = self.tmpdir('test_find_config_from_home_posix') |
| 44 | + tmpdir = self.mkdir('test_find_config_from_home_posix') |
45 | 45 | config_path = tmpdir.ensure('.docker', 'config.json')
|
46 | 46 |
|
47 | 47 | with mock.patch.dict(os.environ, {'HOME': str(tmpdir)}):
|
48 | 48 | assert config.find_config_file() == str(config_path)
|
49 | 49 |
|
50 | 50 | @mark.skipif("sys.platform == 'win32'")
|
51 | 51 | def test_find_config_from_home_legacy_name(self):
|
52 |
| - tmpdir = self.tmpdir('test_find_config_from_home_legacy_name') |
| 52 | + tmpdir = self.mkdir('test_find_config_from_home_legacy_name') |
53 | 53 | config_path = tmpdir.ensure('.dockercfg')
|
54 | 54 |
|
55 | 55 | with mock.patch.dict(os.environ, {'HOME': str(tmpdir)}):
|
56 | 56 | assert config.find_config_file() == str(config_path)
|
57 | 57 |
|
58 | 58 | @mark.skipif("sys.platform != 'win32'")
|
59 | 59 | def test_find_config_from_home_windows(self):
|
60 |
| - tmpdir = self.tmpdir('test_find_config_from_home_windows') |
| 60 | + tmpdir = self.mkdir('test_find_config_from_home_windows') |
61 | 61 | config_path = tmpdir.ensure('.docker', 'config.json')
|
62 | 62 |
|
63 | 63 | with mock.patch.dict(os.environ, {'USERPROFILE': str(tmpdir)}):
|
|
0 commit comments