Skip to content

Commit

Permalink
tests: Simplify TestFindConfig with use of Path
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathonReinhart committed Mar 25, 2024
1 parent e656eb4 commit fe16200
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import logging
import os
from os.path import join
from pathlib import Path
import pytest
from shutil import rmtree
from typing import Optional
from unittest import mock

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

os.mkdir("subdir")
os.chdir("subdir")
subdir = Path("subdir")
subdir.mkdir()
os.chdir(subdir)

# Verify our current working dir
assert_paths_equal(os.getcwd(), in_tmp_path.joinpath("subdir"))
assert_paths_equal(Path.cwd(), in_tmp_path / subdir)

path, rel, _ = scuba.config.find_config()
assert_paths_equal(path, in_tmp_path)
assert_paths_equal(rel, "subdir")
assert_paths_equal(rel, subdir)

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

subdirs = ["foo", "bar", "snap", "crackle", "pop"]

for sd in subdirs: # TODO
os.mkdir(sd)
os.chdir(sd)
subdir = Path("foo/bar/snap/crackle/pop")
subdir.mkdir(parents=True)
os.chdir(subdir)

# Verify our current working dir
assert_paths_equal(os.getcwd(), in_tmp_path.joinpath(*subdirs))
assert_paths_equal(Path.cwd(), in_tmp_path / subdir)

path, rel, _ = scuba.config.find_config()
assert_paths_equal(path, in_tmp_path)
assert_paths_equal(rel, join(*subdirs))
assert_paths_equal(rel, subdir)

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

0 comments on commit fe16200

Please sign in to comment.