Skip to content

Commit fe16200

Browse files
tests: Simplify TestFindConfig with use of Path
1 parent e656eb4 commit fe16200

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

tests/test_config.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import logging
22
import os
3-
from os.path import join
43
from pathlib import Path
54
import pytest
6-
from shutil import rmtree
75
from typing import Optional
86
from unittest import mock
97

@@ -89,32 +87,31 @@ def test_find_config_parent_dir(self, in_tmp_path: Path) -> None:
8987
"""find_config cuba can find the config in the parent directory"""
9088
SCUBA_YML.write_text("image: bosybux")
9189

92-
os.mkdir("subdir")
93-
os.chdir("subdir")
90+
subdir = Path("subdir")
91+
subdir.mkdir()
92+
os.chdir(subdir)
9493

9594
# Verify our current working dir
96-
assert_paths_equal(os.getcwd(), in_tmp_path.joinpath("subdir"))
95+
assert_paths_equal(Path.cwd(), in_tmp_path / subdir)
9796

9897
path, rel, _ = scuba.config.find_config()
9998
assert_paths_equal(path, in_tmp_path)
100-
assert_paths_equal(rel, "subdir")
99+
assert_paths_equal(rel, subdir)
101100

102101
def test_find_config_way_up(self, in_tmp_path: Path) -> None:
103102
"""find_config can find the config way up the directory hierarchy"""
104103
SCUBA_YML.write_text("image: bosybux")
105104

106-
subdirs = ["foo", "bar", "snap", "crackle", "pop"]
107-
108-
for sd in subdirs: # TODO
109-
os.mkdir(sd)
110-
os.chdir(sd)
105+
subdir = Path("foo/bar/snap/crackle/pop")
106+
subdir.mkdir(parents=True)
107+
os.chdir(subdir)
111108

112109
# Verify our current working dir
113-
assert_paths_equal(os.getcwd(), in_tmp_path.joinpath(*subdirs))
110+
assert_paths_equal(Path.cwd(), in_tmp_path / subdir)
114111

115112
path, rel, _ = scuba.config.find_config()
116113
assert_paths_equal(path, in_tmp_path)
117-
assert_paths_equal(rel, join(*subdirs))
114+
assert_paths_equal(rel, subdir)
118115

119116
def test_find_config_nonexist(self) -> None:
120117
"""find_config raises ConfigError if the config cannot be found"""

0 commit comments

Comments
 (0)