def AppendPatternsToFilter(test_filter, positive_patterns=None,
                           negative_patterns=None):
  """Returns a test-filter string with additional patterns.

  Args:
    test_filter: test filter string
    positive_patterns: list of positive patterns to add to string
    negative_patterns: list of negative patterns to add to string
  """
  positives = []
  negatives = []
  positive = ''
  negative = ''

  split_filter = test_filter.split('-', 1)
  if len(split_filter) == 1:
    positive = split_filter[0]
  else:
    positive, negative = split_filter

  positives += [f for f in positive.split(':') if f]
  negatives += [f for f in negative.split(':') if f]

  positives += positive_patterns if positive_patterns else []
  negatives += negative_patterns if negative_patterns else []

  final_filter = ':'.join([p.replace('#', '.') for p in positives])
  if negatives:
    final_filter += '-' + ':'.join([n.replace('#', '.') for n in negatives])
  return final_filter