|
54 | 54 |
|
55 | 55 |
|
56 | 56 | @pytest.fixture |
57 | | -def configure_supported_files(): |
58 | | - original = defaults.config_files.copy() |
| 57 | +def config_files_manager(request, tmpdir): |
| 58 | + with tmpdir.as_cwd(): |
| 59 | + filename = request.param |
| 60 | + with open(filename, "w") as f: |
| 61 | + if "toml" in filename: |
| 62 | + f.write(PYPROJECT) |
| 63 | + yield |
59 | 64 |
|
60 | | - # patch the defaults to include tests |
61 | | - defaults.config_files = [os.path.join("tests", f) for f in defaults.config_files] |
62 | | - yield |
63 | | - defaults.config_files = original |
64 | | - |
65 | | - |
66 | | -@pytest.fixture |
67 | | -def config_files_manager(request): |
68 | | - filename = request.param |
69 | | - filepath = os.path.join("tests", filename) |
70 | | - with open(filepath, "w") as f: |
71 | | - if "toml" in filename: |
72 | | - f.write(PYPROJECT) |
73 | | - yield |
74 | | - os.remove(filepath) |
75 | | - |
76 | | - |
77 | | -@pytest.fixture |
78 | | -def empty_pyproject_ok_cz(): |
79 | | - pyproject = "tests/pyproject.toml" |
80 | | - with open(pyproject, "w") as f: |
81 | | - f.write("") |
82 | | - yield |
83 | | - os.remove(pyproject) |
84 | | - |
85 | | - |
86 | | -@pytest.mark.parametrize( |
87 | | - "config_files_manager", defaults.config_files.copy(), indirect=True |
88 | | -) |
89 | | -def test_load_conf(config_files_manager, configure_supported_files): |
90 | | - cfg = config.read_cfg() |
91 | | - assert cfg.settings == _settings |
92 | 65 |
|
| 66 | +def test_find_git_project_root(tmpdir): |
| 67 | + assert git.find_git_project_root() == Path(os.getcwd()) |
93 | 68 |
|
94 | | -def test_conf_returns_default_when_no_files(configure_supported_files): |
95 | | - cfg = config.read_cfg() |
96 | | - assert cfg.settings == defaults.DEFAULT_SETTINGS |
| 69 | + with tmpdir.as_cwd() as _: |
| 70 | + assert git.find_git_project_root() is None |
97 | 71 |
|
98 | 72 |
|
99 | 73 | @pytest.mark.parametrize( |
100 | 74 | "config_files_manager", defaults.config_files.copy(), indirect=True |
101 | 75 | ) |
102 | | -def test_set_key(configure_supported_files, config_files_manager): |
| 76 | +def test_set_key(config_files_manager): |
103 | 77 | _conf = config.read_cfg() |
104 | 78 | _conf.set_key("version", "2.0.0") |
105 | 79 | cfg = config.read_cfg() |
106 | 80 | assert cfg.settings == _new_settings |
107 | 81 |
|
108 | 82 |
|
109 | | -def test_find_git_project_root(tmpdir): |
110 | | - assert git.find_git_project_root() == Path(os.getcwd()) |
111 | | - |
112 | | - with tmpdir.as_cwd() as _: |
113 | | - assert git.find_git_project_root() is None |
| 83 | +class TestReadCfg: |
| 84 | + @pytest.mark.parametrize( |
| 85 | + "config_files_manager", defaults.config_files.copy(), indirect=True |
| 86 | + ) |
| 87 | + def test_load_conf(_, config_files_manager): |
| 88 | + cfg = config.read_cfg() |
| 89 | + assert cfg.settings == _settings |
| 90 | + |
| 91 | + def test_conf_returns_default_when_no_files(_, tmpdir): |
| 92 | + with tmpdir.as_cwd(): |
| 93 | + cfg = config.read_cfg() |
| 94 | + assert cfg.settings == defaults.DEFAULT_SETTINGS |
| 95 | + |
| 96 | + def test_load_empty_pyproject_toml_and_cz_toml_with_config(_, tmpdir): |
| 97 | + with tmpdir.as_cwd(): |
| 98 | + p = tmpdir.join("pyproject.toml") |
| 99 | + p.write("") |
| 100 | + p = tmpdir.join(".cz.toml") |
| 101 | + p.write(PYPROJECT) |
| 102 | + |
| 103 | + cfg = config.read_cfg() |
| 104 | + assert cfg.settings == _settings |
114 | 105 |
|
115 | 106 |
|
116 | 107 | class TestTomlConfig: |
|
0 commit comments