def test__filter_files(expand_path_fixtures): files = sorted( [str(x) for x in transforms._filter_files(transforms._expand_paths("**/*"))] ) assert files == [ "a.txt", "b.py", "c.md", "dira/e.txt", "dira/f.py", "dirb/suba/g.py", ]
def test__move_to_dest_subdir(expand_path_fixtures): tmp_path = Path(str(expand_path_fixtures)) _tracked_paths.add(expand_path_fixtures) dest = Path(str(expand_path_fixtures / normpath("dest/dira"))) # Move to a different dir to make sure that move doesn't depend on the cwd os.chdir(tempfile.gettempdir()) transforms.move(tmp_path / "dira", dest, excludes=["f.py"]) os.chdir(str(tmp_path)) files = sorted( [str(x) for x in transforms._expand_paths("**/*", root="dest")]) # Assert destination does not contain dira/f.py (excluded) assert files == [normpath("dest/dira"), normpath("dest/dira/e.txt")]
def test__move_to_dest(expand_path_fixtures): tmp_path = Path(str(expand_path_fixtures)) _tracked_paths.add(expand_path_fixtures) dest = Path(str(expand_path_fixtures / "dest")) transforms.move(tmp_path, dest, excludes=["dira/f.py"]) files = sorted([str(x) for x in transforms._expand_paths("**/*", root="dest")]) # Assert destination does not contain dira/e.py (excluded) assert files == [ "dest/a.txt", "dest/b.py", "dest/c.md", "dest/dira", "dest/dira/e.txt", "dest/dirb", "dest/dirb/suba", "dest/dirb/suba/g.py", ]
def test__expand_paths(expand_path_fixtures, input, expected): paths = sorted([str(x) for x in transforms._expand_paths(input)]) assert paths == expected
def test__expand_paths_with_root(expand_path_fixtures, input, expected): paths = sorted( [str(x) for x in transforms._expand_paths(input, root="dira")]) assert paths == expected
"request.instances.extend(instances)", ) # https://github.com/googleapis/gapic-generator-python/issues/672 s.replace( "google/cloud/aiplatform_v1beta1/services/endpoint_service/client.py", "request.traffic_split.extend\(traffic_split\)", "request.traffic_split = traffic_split", ) # post processing to fix the generated reference doc from synthtool import transforms as st import re # https://github.com/googleapis/gapic-generator-python/issues/479 paths = st._filter_files(st._expand_paths("google/cloud/**/*.py", ".")) pattern = r"(:\w+:``[^`]+``)" expr = re.compile(pattern, flags=re.MULTILINE) replaces = [] for path in paths: with path.open("r+") as fh: content = fh.read() matches = re.findall(expr, content) if matches: for match in matches: before = match after = match.replace("``", "`") replaces.append((path, before, after)) for path, before, after in replaces: