-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
simplified the as_start_path function and remove the #todo as it it ca… #61
Open
jasonbrackman
wants to merge
6
commits into
chendaniely:main
Choose a base branch
from
jasonbrackman:simplified_as_start_path
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d7595da
siplified the as_start_path function and remove the #todo as it it ca…
jasonbrackman 02e742d
Added an expanduser() before returning path to ensure that any input …
jasonbrackman 71cb1f0
removed space from end of lines.
jasonbrackman decaf66
- add .resolve() to handle the '.' and '..' normalization for the Pat…
jasonbrackman 84ad46a
removed white space
jasonbrackman 428b331
Looks like I need to have the tests run from pyprojroot. I'll need t…
jasonbrackman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import os | ||
|
||
import pytest | ||
|
||
from pyprojroot.root import as_start_path, find_root | ||
|
||
MARKER = ".here" | ||
|
||
|
||
@pytest.fixture | ||
def temp_dir_structure(tmp_path): | ||
""" | ||
Create a pytest temp path for testing: | ||
|
||
tmp_path/ | ||
└── dir1/ | ||
├── .here <-- marker file | ||
└── dir2/ | ||
""" | ||
dir1 = tmp_path / "dir1" | ||
dir2 = dir1 / "dir2" | ||
os.makedirs(dir1 / MARKER) | ||
os.makedirs(dir2) | ||
return dir1, dir2 | ||
|
||
|
||
def test_as_start_path_normalized_path(): | ||
result01 = as_start_path("~") # Home | ||
assert result01.is_dir() | ||
|
||
result02 = as_start_path("~/.") # Still at Home | ||
assert result02.is_dir() | ||
assert result01 == result02 | ||
|
||
result03 = as_start_path("~/..") # One directory below Home | ||
assert result03.is_dir() | ||
assert result03 != result02 | ||
|
||
|
||
def test_find_root_marker_in_child(temp_dir_structure): | ||
"""Marker is in child folder, checking the parent should raise.""" | ||
dir1, _ = temp_dir_structure | ||
|
||
os.chdir(dir1) | ||
result = find_root(MARKER, start=".") | ||
assert result.is_dir() | ||
|
||
with pytest.raises(RuntimeError, match="Project root not found."): | ||
find_root(MARKER, start="..") | ||
|
||
|
||
def test_find_root_marker_in_parent(temp_dir_structure): | ||
"""Marker in parent - child and parent should successfully find a root.""" | ||
_, dir2 = temp_dir_structure | ||
os.chdir(dir2) | ||
result01 = find_root(MARKER, start=".") | ||
assert result01.is_dir() | ||
|
||
result02 = find_root(MARKER, start="..") | ||
assert result02.is_dir() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
resolve
includesexpanduser
andcwd
is always an absolute path. So these can be simplified.