old_contents: import re
  import settings
  
  class Specfile(object):
      def __init__(self, specfile):
          if not isinstance(specfile, str):
              self.specfile = ''.join(specfile)
          else:
              self.specfile = specfile
  
          self.sections = self.split_sections()
      
      def split_sections(self):
          headers_re = [re.compile('^' + x, re.M) for x in settings.SPECFILE_SECTIONS]
          section_starts = []
          for header in headers_re:
              for match in header.finditer(self.specfile):
                  section_starts.append(match.start())
  
          section_starts.sort()
          sections = [('%header', self.specfile[:section_starts[0]])]
          for i in range(len(section_starts)):
              if len(section_starts) > i + 1:
                  curr_section = self.specfile[section_starts[i]:section_starts[i+1]]
              else:
                  curr_section = self.specfile[section_starts[i]:]
              for header in headers_re:
                  if header.match(curr_section):
                      sections.append((header.pattern[1:], curr_section))
  
          return sections
  
      def __str__(self):
          return '\n\n'.join(zip(*self.sections)[1])
  
new_contents: import re
  import settings
  
  class Specfile(object):
      def __init__(self, specfile):
          if not isinstance(specfile, str):
              self.specfile = ''.join(specfile)
          else:
              self.specfile = specfile
  
          self.sections = self.split_sections()
      
      def split_sections(self):
          headers_re = [re.compile('^' + x, re.M) for x in settings.SPECFILE_SECTIONS]
          section_starts = []
          for header in headers_re:
              for match in header.finditer(self.specfile):
                  section_starts.append(match.start())
  
          section_starts.sort()
          # this is mainly for tests - if the header is the only section
          header_end = section_starts[0] if section_starts else len(self.specfile)
          sections = [('%header', self.specfile[:header_end])]
          for i in range(len(section_starts)):
              if len(section_starts) > i + 1:
                  curr_section = self.specfile[section_starts[i]:section_starts[i+1]]
              else:
                  curr_section = self.specfile[section_starts[i]:]
              for header in headers_re:
                  if header.match(curr_section):
                      sections.append((header.pattern[1:], curr_section))
  
          return sections
  
      def __str__(self):
          return '\n\n'.join(zip(*self.sections)[1])
  
subject: Fix Specfile for tests, that have only header section of specfile