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
11 changes: 5 additions & 6 deletions synthtool/languages/php.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,13 @@ def _merge(src: str, dest: str, path: Path):
def _find_copy_target(src: Path, version_string: str) -> typing.Optional[Path]:
"""Returns a directory contains the version subdirectory."""
logger.debug("_find_copy_target called with %s and %s", src, version_string)
entries = os.scandir(src)
if not entries:
return None
for entry in entries:
if Path(entry.path).resolve().stem.lower() == version_string:
for entry in src.iterdir():
if entry.name.lower() == version_string:
return src
if entry.is_dir():
return _find_copy_target(Path(entry.path).resolve(), version_string)
target = _find_copy_target(entry, version_string)
if target is not None:
return target
return None


Expand Down
42 changes: 42 additions & 0 deletions tests/test_php.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import pytest

from synthtool.languages import php


FIXTURES = Path(__file__).parent / "fixtures" / "php"

Expand Down Expand Up @@ -57,3 +59,43 @@ def get_diff_string(dcmp, buf=""):
for sub_dcmp in dcmp.subdirs.values():
buf += get_diff_string(sub_dcmp)
return buf


def test_find_copy_target_direct(tmp_path: Path):
(tmp_path / "V1").mkdir()
assert php._find_copy_target(tmp_path, "v1") == tmp_path


def test_find_copy_target_in_sibling(tmp_path: Path):
sibling_empty = tmp_path / "sibling_empty"
sibling_empty.mkdir()

sibling_other = tmp_path / "sibling_other"
sibling_other.mkdir()
(sibling_other / "v2").mkdir()

sibling_match = tmp_path / "sibling_match"
sibling_match.mkdir()
(sibling_match / "V1").mkdir()

assert php._find_copy_target(tmp_path, "v1") == sibling_match


def test_find_copy_target_nested(tmp_path: Path):
nested_dir = tmp_path / "a" / "b"
nested_dir.mkdir(parents=True)
(nested_dir / "v1beta1").mkdir()

assert php._find_copy_target(tmp_path, "v1beta1") == nested_dir


def test_find_copy_target_not_found(tmp_path: Path):
nested_dir = tmp_path / "a" / "b"
nested_dir.mkdir(parents=True)
(nested_dir / "v2").mkdir()

assert php._find_copy_target(tmp_path, "v1") is None


def test_find_copy_target_empty_dir(tmp_path: Path):
assert php._find_copy_target(tmp_path, "v1") is None
Loading