Skip to content

Commit

Permalink
General improvements in the testing suite (#60)
Browse files Browse the repository at this point in the history
* test yield_sources against data/paths instead of real files.

* Cover symliking case
  • Loading branch information
hadialqattan committed Jul 29, 2021
1 parent 1580203 commit 2a3004d
Show file tree
Hide file tree
Showing 12 changed files with 12 additions and 16 deletions.
Empty file added tests/data/paths/a.py
Empty file.
Empty file added tests/data/paths/b.c
Empty file.
Empty file added tests/data/paths/dir/git/git.py
Empty file.
Empty file added tests/data/paths/dir/i.c
Empty file.
1 change: 1 addition & 0 deletions tests/data/paths/dir/r.py
Empty file added tests/data/paths/dir/s.py
Empty file.
Empty file added tests/data/paths/dir/u.py
Empty file.
Empty file added tests/data/paths/dir/utils/r.py
Empty file.
Empty file added tests/data/paths/dir/x.py
Empty file.
Empty file added tests/data/paths/dir/y.py
Empty file.
Empty file added tests/data/paths/dir/z.py
Empty file.
27 changes: 11 additions & 16 deletions tests/test_pathu.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
from pycln.utils import pathu, regexu
from pycln.utils.report import Report

from . import CONFIG_DIR

# Constants.
MOCK = "pycln.utils.report.%s"
THIS_DIR = Path(__file__).parent
DATA_DIR = Path(__file__).parent.joinpath("data")

if ISWIN:
PYVER = "Lib"
Expand All @@ -32,30 +30,27 @@ class TestPathu:
"path, include, exclude, gitignore, expec",
[
pytest.param(
Path(__file__).parent.parent,
re.compile(r"test_.*\.py$"),
re.compile(r"(.*_re.*\.py|.*s\.py|.git/|pycln/)$"),
Path(DATA_DIR / "paths" / "dir"),
re.compile(r".*\.py$"),
re.compile(r"(.*s\.py|git/)$"),
PathSpec.from_lines("gitwildmatch", ["*u.py", "utils/"]),
{
"test_main.py",
"test_scan.py",
"test_config.py",
"test_metadata.py",
"test_transform.py",
"test_cli.py",
"x.py",
"y.py",
"z.py",
},
id="path: directory",
),
pytest.param(
Path(__file__),
Path(DATA_DIR / "paths" / "a.py"),
re.compile(r".*\.py$"),
re.compile(r""),
PathSpec.from_lines("gitwildmatch", []),
{"test_pathu.py"},
{"a.py"},
id="path: file",
),
pytest.param(
CONFIG_DIR.joinpath("setup.cfg"),
Path(DATA_DIR / "paths" / "b.c"),
re.compile(r".*\.py$"),
re.compile(r""),
PathSpec.from_lines("gitwildmatch", []),
Expand All @@ -74,7 +69,7 @@ def test_yield_sources(

@mock.patch(MOCK % "Report.ignored_path")
def test_nested_gitignore(self, ignored_path):
path = Path(THIS_DIR / "data" / "nested_gitignore_tests")
path = Path(DATA_DIR / "nested_gitignore_tests")
include = regexu.safe_compile(regexu.INCLUDE_REGEX, regexu.INCLUDE)
exclude = regexu.safe_compile(regexu.EXCLUDE_REGEX, regexu.EXCLUDE)
gitignore = regexu.get_gitignore(path)
Expand Down

0 comments on commit 2a3004d

Please sign in to comment.