from typing import List


def ParseFilterFile(filepath: str,
                    p_filts: List[str],
                    n_filts: List[str]) -> str:
  """Takes a path to a filter file, parses it, and constructs a gtest_filter
  string for test execution.

  Args:
    filepath (str): The path to the filter file to be parsed into a
        --gtest_filter flag.
    p_filts (List[str]): An initial set of positive filters passed in a flag.
    n_filts (List[str]): An initial set of negative filters passed in a flag.

  Returns:
    str: The properly-joined together gtest_filter flag.
  """
  positive_filters = p_filts
  negative_filters = n_filts
  with open(filepath, "r") as file:
    for line in file:
      # Only take the part of a line before a # sign
      line = line.split("#", 1)[0].strip()
      if line == "":
        continue
      elif line.startswith("-"):
        negative_filters.append(line[1:])
      else:
        positive_filters.append(line)

  return "--gtest_filter={}-{}".format(":".join(positive_filters),
                                       ":".join(negative_filters))