tools/metrics/histograms/expand_owners_unittest.py
def testExpandOwnersForOWNERSFileWithDuplicateComponents(
      self, mock_dirmd_extract):
    """Checks that only one component tag is added if there are duplicates."""
    mock_dirmd_extract.return_value = None
    absolute_path = _MakeOwnersFile('OWNERS', self.temp_dir)
    src_relative_path = _GetSrcRelativePath(absolute_path)

    with open(absolute_path, 'w') as owners_file:
      owners_file.write('\n'.join(['amy@chromium.org']))

    duplicate_owner_absolute_path = (
        _MakeOwnersFile('duplicate_owner_OWNERS', self.temp_dir))
    duplicate_owner_src_relative_path = (
        _GetSrcRelativePath(duplicate_owner_absolute_path))

    with open(duplicate_owner_absolute_path, 'w') as owners_file:
      owners_file.write('\n'.join(['rae@chromium.org']))

    histograms = xml.dom.minidom.parseString("""
<histograms>

<histogram name="Caffeination" units="mg">
  <owner>joe@chromium.org</owner>
  <owner>{}</owner>
  <owner>{}</owner>
  <summary>I like coffee.</summary>
</histogram>

</histograms>
""".format(src_relative_path, duplicate_owner_src_relative_path))

    expected_histograms = xml.dom.minidom.parseString("""
<histograms>

<histogram name="Caffeination" units="mg">
  <owner>joe@chromium.org</owner>
  <owner>amy@chromium.org</owner>
  <owner>rae@chromium.org</owner>
  <summary>I like coffee.</summary>
</histogram>

</histograms>
""")

    expand_owners.ExpandHistogramsOWNERS(histograms)
    self.assertEqual(histograms.toxml(), expected_histograms.toxml())
Checks that only one component tag is added if there are duplicates.
Checks that only one component tag is added if there are duplicates.
Checks that only one component tag is added if there are duplicates .
def testExpandOwnersForOWNERSFileWithDuplicateComponents(
      self, mock_dirmd_extract):
    mock_dirmd_extract.return_value = None
    absolute_path = _MakeOwnersFile('OWNERS', self.temp_dir)
    src_relative_path = _GetSrcRelativePath(absolute_path)
    with open(absolute_path, 'w') as owners_file:
      owners_file.write('\n'.join(['amy@chromium.org']))
    duplicate_owner_absolute_path = (
        _MakeOwnersFile('duplicate_owner_OWNERS', self.temp_dir))
    duplicate_owner_src_relative_path = (
        _GetSrcRelativePath(duplicate_owner_absolute_path))
    with open(duplicate_owner_absolute_path, 'w') as owners_file:
      owners_file.write('\n'.join(['rae@chromium.org']))
    histograms = xml.dom.minidom.parseString("""
<histograms>
<histogram name="Caffeination" units="mg">
  <owner>joe@chromium.org</owner>
  <owner>{}</owner>
  <owner>{}</owner>
  <summary>I like coffee.</summary>
</histogram>
</histograms>
""".format(src_relative_path, duplicate_owner_src_relative_path))
    expected_histograms = xml.dom.minidom.parseString("""
<histograms>
<histogram name="Caffeination" units="mg">
  <owner>joe@chromium.org</owner>
  <owner>amy@chromium.org</owner>
  <owner>rae@chromium.org</owner>
  <summary>I like coffee.</summary>
</histogram>
</histograms>
""")
    expand_owners.ExpandHistogramsOWNERS(histograms)
    self.assertEqual(histograms.toxml(), expected_histograms.toxml())
def testExpandOwnersForOWNERSFileWithDuplicateComponents ( self , mock_dirmd_extract ) : mock_dirmd_extract . return_value = None absolute_path = _MakeOwnersFile ( 'OWNERS' , self . temp_dir ) src_relative_path = _GetSrcRelativePath ( absolute_path ) with open ( absolute_path , 'w' ) as owners_file : owners_file . write ( '\n' . join ( [ 'amy@chromium.org' ] ) ) duplicate_owner_absolute_path = ( _MakeOwnersFile ( 'duplicate_owner_OWNERS' , self . temp_dir ) ) duplicate_owner_src_relative_path = ( _GetSrcRelativePath ( duplicate_owner_absolute_path ) ) with open ( duplicate_owner_absolute_path , 'w' ) as owners_file : owners_file . write ( '\n' . join ( [ 'rae@chromium.org' ] ) ) histograms = xml . dom . minidom . parseString ( """
<histograms>

<histogram name="Caffeination" units="mg">
  <owner>joe@chromium.org</owner>
  <owner>{}</owner>
  <owner>{}</owner>
  <summary>I like coffee.</summary>
</histogram>

</histograms>
""" . format ( src_relative_path , duplicate_owner_src_relative_path ) ) expected_histograms = xml . dom . minidom . parseString ( """
<histograms>

<histogram name="Caffeination" units="mg">
  <owner>joe@chromium.org</owner>
  <owner>amy@chromium.org</owner>
  <owner>rae@chromium.org</owner>
  <summary>I like coffee.</summary>
</histogram>

</histograms>
""" ) expand_owners . ExpandHistogramsOWNERS ( histograms ) self . assertEqual ( histograms . toxml ( ) , expected_histograms . toxml ( ) )
Checks that only one component tag is added if there are duplicates.
Checks that only one component tag is added if there are duplicates .
"""Checks that only one component tag is added if there are duplicates."""
self
mock_dirmd_extract