Example #1
0
    def __init__(self, file_path):
        parser = ChangelogParser(RpmPkgPolicy)

        if os.path.splitext(file_path)[1] == '.spec':
            gbp.log.debug("Using spec file '%s' as changelog" % file_path)
            self._file = SpecFile(file_path)
            self.changelog = parser.raw_parse_string(self._file.get_changelog())
        else:
            self._file = os.path.abspath(file_path)
            if not os.path.exists(file_path):
                gbp.log.info("Changelog '%s' not found, creating new "
                             "changelog file" % file_path)
                self.changelog = Changelog(RpmPkgPolicy)
            else:
                gbp.log.debug("Using changelog file '%s'" % file_path)
                self.changelog = parser.raw_parse_file(self._file)

        # Parse topmost section and try to determine the start commit
        if self.changelog.sections:
            self.changelog.sections[0] = parser.parse_section(
                self.changelog.sections[0])
Example #2
0
    def __init__(self, file_path):
        parser = ChangelogParser(RpmPkgPolicy)

        if os.path.splitext(file_path)[1] == '.spec':
            gbp.log.debug("Using spec file '%s' as changelog" % file_path)
            self._file = SpecFile(file_path)
            self.changelog = parser.raw_parse_string(
                self._file.get_changelog())
        else:
            self._file = os.path.abspath(file_path)
            if not os.path.exists(file_path):
                gbp.log.info("Changelog '%s' not found, creating new "
                             "changelog file" % file_path)
                self.changelog = Changelog(RpmPkgPolicy)
            else:
                gbp.log.debug("Using changelog file '%s'" % file_path)
                self.changelog = parser.raw_parse_file(self._file)

        # Parse topmost section and try to determine the start commit
        if self.changelog.sections:
            self.changelog.sections[0] = parser.parse_section(
                self.changelog.sections[0])
Example #3
0
class TestChangelogParser(object):
    """Test the default changelog parser"""

    cl_default_style = """\
* Wed Jan 29 2014 Markus Lehtonen <*****@*****.**> 0.3-1
- Version bump
- Drop foo.patch

* Tue Jan 28 2014 Markus Lehtonen <*****@*****.**> 0.2
- Update to 0.2

* Mon Jan 27 2014 Markus Lehtonen <*****@*****.**> 0.1
- Initial version
"""
    cl_with_authors = """\
* Wed Jan 29 2014 Markus Lehtonen <*****@*****.**> 0.3-1
[Markus Lehtonen]
- Version bump
[John Doe]
- Bug fix
"""
    # Invalid timestamp / name
    cl_broken_header_1 = """\
* Wed Jan 29 2014Markus Lehtonen <*****@*****.**> 0.3-1
- Version bump
"""
    # Whitespace before the asterisk in the header
    cl_broken_header_2 = """\
 * Wed Jan 29 2014 Markus Lehtonen <*****@*****.**> 0.3-1
- Version bump
"""
    # Invalid timestamp
    cl_broken_header_3 = """\
* Wed Jan 32 2014 Markus Lehtonen <*****@*****.**> 0.3-1
- Version bump
"""
    # Missing email
    cl_broken_header_4 = """\
* Wed Jan 29 2014 Markus Lehtonen 0.3-1
- Version bump
"""
    # Garbage before section header
    cl_broken_header_5 = """\
---garbage---
* Wed Jan 29 2014 Markus Lehtonen <*****@*****.**> 0.3-1
- Version bump
"""

    parser = ChangelogParser(RpmPkgPolicy)

    def test_parse_changelog(self):
        """Basic tests for successful parsing"""
        # Raw parsing of changelog
        changelog = self.parser.raw_parse_string(self.cl_default_style)
        eq_(len(changelog.sections), 3)

        # Check that re-creating the changelog doesn't mangle it
        eq_(str(changelog), self.cl_default_style)

        # Parse and check section
        section = self.parser.parse_section(changelog.sections[0])

        eq_(section.header['time'], datetime(2014, 1, 29))
        eq_(section.header['name'], "Markus Lehtonen")
        eq_(section.header['email'], "*****@*****.**")
        eq_(section.header['revision'], "0.3-1")

        # Check that re-creating section doesn't mangle it
        eq_(str(section), changelog.sections[0])

    def test_parse_authors(self):
        """Test parsing of authors from changelog entries"""
        section = self.parser.parse_section(self.cl_with_authors)
        eq_(section.entries[0].author, "Markus Lehtonen")
        eq_(section.entries[1].author, "John Doe")

    def test_parse_changelog_file(self):
        """Basic tests for parsing a file"""
        # Create file and parse it
        tmpfile = NamedTemporaryFile()
        tmpfile.write(self.cl_default_style)
        tmpfile.file.flush()
        changelog = self.parser.raw_parse_file(tmpfile.name)
        # Check parsing results
        eq_(len(changelog.sections), 3)
        eq_(str(changelog), self.cl_default_style)
        # Cleanup
        tmpfile.close()

    def test_parse_section_fail(self):
        """Basic tests for failures of changelog section parsing"""
        assert_raises(ChangelogError, self.parser.parse_section,
                      self.cl_broken_header_1)
        assert_raises(ChangelogError, self.parser.parse_section,
                      self.cl_broken_header_2)
        assert_raises(ChangelogError, self.parser.parse_section,
                      self.cl_broken_header_3)
        assert_raises(ChangelogError, self.parser.parse_section,
                      self.cl_broken_header_4)
        """
        with assert_raises(ChangelogError):
            self.parser.parse_section(self.cl_broken_header_1)

        with assert_raises(ChangelogError):
            self.parser.parse_section(self.cl_broken_header_2)

        with assert_raises(ChangelogError):
            self.parser.parse_section(self.cl_broken_header_3)

        with assert_raises(ChangelogError):
            self.parser.parse_section(self.cl_broken_header_4)
	"""

    def test_parse_changelog_fail(self):
        """Basic tests for changelog parsing failures"""
        assert_raises(ChangelogError, self.parser.raw_parse_string,
                      self.cl_broken_header_5)
        """