Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/docstub/_path_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ def _walk_source_package(path, *, ignore_regex):
source_path : Path
Either a Python file or a stub file that takes precedence.
"""
if ignore_regex and ignore_regex.match(str(path)):
# Make sure
if ignore_regex and ignore_regex.match(str(path.resolve())):
logger.info("ignoring %s", path)
return

Expand Down
20 changes: 20 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import os
from pathlib import Path

import pytest


@pytest.fixture
def tmp_path_cwd(tmp_path):
"""Fixture: Create temporary directory and use it as working directory.

.. warning::
Not written with parallelization in mind!
"""
previous_cwd = Path.cwd()
os.chdir(tmp_path)
try:
yield tmp_path
except:
os.chdir(previous_cwd)
raise
17 changes: 0 additions & 17 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Test command line interface."""

import logging
import os
from pathlib import Path

import pytest
Expand All @@ -13,22 +12,6 @@
PROJECT_ROOT = Path(__file__).parent.parent


@pytest.fixture
def tmp_path_cwd(tmp_path):
"""Fixture: Create temporary directory and use it as working directory.

.. warning::
Not written with parallelization in mind!
"""
previous_cwd = Path.cwd()
os.chdir(tmp_path)
try:
yield tmp_path
except:
os.chdir(previous_cwd)
raise


class Test_run:
def test_no_cache(self, tmp_path_cwd, caplog):
caplog.set_level(logging.INFO)
Expand Down
17 changes: 17 additions & 0 deletions tests/test_path_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from pathlib import Path

import pytest

from docstub._path_utils import STUB_HEADER_COMMENT, walk_source_package
Expand Down Expand Up @@ -122,3 +124,18 @@ def test_ignore(self, tmp_path):

paths = sorted(walk_source_package(tmp_path, ignore=["**/*init*"]))
assert paths == [stub_in_sub_package]

def test_ignore_relative_path(self, tmp_path_cwd):
init = tmp_path_cwd / "__init__.py"
init.touch()
tests_dir = tmp_path_cwd / "tests"
tests_dir.mkdir()
sub_init = tests_dir / "__init__.py"
sub_init.touch()

relative_cwd = Path()

paths = sorted(walk_source_package(relative_cwd))
assert [p.resolve() for p in paths] == [init, sub_init]
paths = sorted(walk_source_package(relative_cwd, ignore=["**/tests"]))
assert [p.resolve() for p in paths] == [init]
Loading