Esempio n. 1
0
def test_GeneratePaths_explicitly_requested_submodule(
  path_generator: path_generator_lib.PathGenerator, tempdir: pathlib.Path
):
  """Test that a git submodule is visited if it is explicitly asked for."""
  os.chdir(tempdir)
  MakeFiles(
    [
      ".git/config",  # Fake repo root, should be ignored
      "README",
      "src/a",
      "src/b",
      "src/c/d",
      "src/submod/.git",  # Fake submodule, should be ignored
      "src/submod/a",  # should be ignored
      "src/submod/b",  # should be ignored
      "src/submod/c/c",  # should be ignored
    ]
  )

  paths = set(path_generator.GeneratePaths(["src/submod"]))
  assert paths == {
    tempdir / "src/submod/a",
    tempdir / "src/submod/b",
    tempdir / "src/submod/c/c",
  }
Esempio n. 2
0
def test_GeneratePaths_ignored_in_glob_expansion(
  path_generator: path_generator_lib.PathGenerator, tempdir: pathlib.Path
):
  """Test that a git submodule is not visited if it would only be visited as
  the result of a glob expansion.
  """
  os.chdir(tempdir)
  MakeFiles(
    [
      ".git/config",  # Fake repo root, should be ignored
      "README",
      "src/a",
      "src/b",
      "src/c/d",
      "src/submod/.git",  # Fake submodule, should be ignored
      "src/submod/a",  # should be ignored
      "src/submod/b",  # should be ignored
      "src/submod/c/c",  # should be ignored
    ]
  )

  paths = list(path_generator.GeneratePaths(["src/*"]))

  assert paths == [
    tempdir / "src/a",
    tempdir / "src/b",
    tempdir / "src/c/d",
  ]
Esempio n. 3
0
def test_GeneratePaths_ignore_git_submodule(
  path_generator: path_generator_lib.PathGenerator, tempdir: pathlib.Path
):
  """Test that git submodules are not visited."""
  os.chdir(tempdir)
  MakeFiles(
    [
      ".git/config",  # Fake repo root, should be ignored
      "README",
      "src/a",
      "src/b",
      "src/c/d",
      "src/submod/.git",  # Fake submodule, should be ignored
      "src/submod/a",  # should be ignored
      "src/submod/b",  # should be ignored
      "src/submod/c/c",  # should be ignored
    ]
  )

  paths = set(path_generator.GeneratePaths(["."]))
  assert paths == {
    tempdir / "README",
    tempdir / "src/a",
    tempdir / "src/b",
    tempdir / "src/c/d",
  }
Esempio n. 4
0
def test_GeneratePaths_single_abspath(
  path_generator: path_generator_lib.PathGenerator, tempdir: pathlib.Path
):
  MakeFiles(
    [tempdir / "hello.txt",]
  )

  paths = list(path_generator.GeneratePaths([str(tempdir / "hello.txt")]))

  assert paths == [tempdir / "hello.txt"]
Esempio n. 5
0
def test_GeneratePaths_ignore_list_glob(
  path_generator: path_generator_lib.PathGenerator, tempdir: pathlib.Path
):
  MakeFiles(
    [tempdir / ".formatignore", tempdir / "a",]
  )
  fs.Write(tempdir / ".formatignore", "*".encode("utf-8"))
  paths = list(path_generator.GeneratePaths([str(tempdir)]))

  assert paths == [tempdir / ".formatignore"]
Esempio n. 6
0
def test_GeneratePaths_directory_with_file(
  path_generator: path_generator_lib.PathGenerator, tempdir: pathlib.Path
):
  MakeFiles(
    [tempdir / "a",]
  )

  paths = list(path_generator.GeneratePaths([str(tempdir)]))

  assert paths == [
    tempdir / "a",
  ]
Esempio n. 7
0
def test_GeneratePaths_ignore_list_parent_directory(
  path_generator: path_generator_lib.PathGenerator, tempdir: pathlib.Path
):
  """Test ignoring the contents of a directory."""
  os.chdir(tempdir)
  MakeFiles(
    [".formatignore", "src/a", "src/b",]
  )
  fs.Write(".formatignore", "src".encode("utf-8"))

  paths = list(path_generator.GeneratePaths(["."]))

  assert paths == [tempdir / ".formatignore"]
Esempio n. 8
0
def test_GeneratePaths_single_relpath(
  path_generator: path_generator_lib.PathGenerator, tempdir: pathlib.Path
):
  os.chdir(tempdir)

  MakeFiles(
    [tempdir / "hello.txt",]
  )

  paths = list(path_generator.GeneratePaths(["hello.txt"]))

  assert paths == [
    tempdir / "hello.txt",
  ]
Esempio n. 9
0
def test_GeneratePaths_ignore_list_glob_unignored(
  path_generator: path_generator_lib.PathGenerator, tempdir: pathlib.Path
):
  os.chdir(tempdir)
  MakeFiles(
    [".formatignore", "a", "b", "c",]
  )
  fs.Write(".formatignore", "*\n!a".encode("utf-8"))

  paths = list(path_generator.GeneratePaths(["."]))

  assert paths == [
    tempdir / ".formatignore",
    tempdir / "a",
  ]
Esempio n. 10
0
def test_GeneratePaths_ignore_list_recurisve_glob(
  path_generator: path_generator_lib.PathGenerator, tempdir: pathlib.Path
):
  """Test ignoring files in a recursive glob."""
  os.chdir(tempdir)
  MakeFiles(
    [".formatignore", "src/a", "src/b", "src/c/a/a", "src/c/a/b",]
  )
  fs.Write(".formatignore", "**/a".encode("utf-8"))

  paths = list(path_generator.GeneratePaths(["."]))
  print(paths)

  assert paths == [
    tempdir / ".formatignore",
    tempdir / "src/b",
  ]
Esempio n. 11
0
def test_GeneratePaths_empty_directory(
  path_generator: path_generator_lib.PathGenerator, tempdir: pathlib.Path
):
  paths = list(path_generator.GeneratePaths([str(tempdir)]))
  assert paths == []
Esempio n. 12
0
def test_GeneratePaths_non_existent_path(
  path_generator: path_generator_lib.PathGenerator, tempdir: pathlib.Path
):
  paths = list(path_generator.GeneratePaths([str(tempdir / "not_a_path")]))
  assert paths == []