# `doctests.test_Changelog` module documentation

Part of `doctests`

Test `gbp.deb.changelog.ChangeLog`

Function | setup | Setup test module
Function | test_parse_debian_only | Parse a the changelog of debian only package
Function | test_parse_no_eopch | Parse a the changelog of a package without eopch
Function | test_parse_eopch | Parse a the changelog of a package without epoch
Function | test_parse_name | Methods tested: - `gbp.deb.changelog.ChangeLog.__init__`
Function | test_parse_last_mod | Test author, email and date of last modification
Function | test_parse_sections | Test if we can parse sections out of the changelog
Function | test_get_changes | Test if we can get changes
Function | test_add_section | Test if we can add a section to an existing changelog
Function | test_add_entry | Test if we can add an entry to an existing changelog

def setup():

Setup test module

def test_parse_debian_only():

Parse a the changelog of debian only package

Methods tested:

- `gbp.deb.changelog.ChangeLog.__init__`

Properties tested:

- `gbp.deb.changelog.ChangeLog.version`
- `gbp.deb.changelog.ChangeLog.debian_version`
- `gbp.deb.changelog.ChangeLog.upstream_version`
- `gbp.deb.changelog.ChangeLog.epoch`
- `gbp.deb.changelog.ChangeLog.noepoch`

    >>> import gbp.deb.changelog
    >>> cl = gbp.deb.changelog.ChangeLog(cl_debian)
    >>> cl.version
    '0.5.32'
    >>> cl.version == cl['Version']
    True
    >>> cl.debian_version
    '0.5.32'
    >>> cl.debian_version == cl['Debian-Version']
    True
    >>> cl.noepoch
    '0.5.32'
    >>> cl.noepoch == cl['NoEpoch-Version']
    True
    >>> cl.epoch
    >>> cl.upstream_version

def test_parse_no_eopch():

Parse a the changelog of a package without eopch

Methods tested:

- `gbp.deb.changelog.ChangeLog.__init__`
- `gbp.deb.changelog.ChangeLog.has_epoch`

Properties tested:

- `gbp.deb.changelog.ChangeLog.version`
- `gbp.deb.changelog.ChangeLog.debian_version`
- `gbp.deb.changelog.ChangeLog.upstream_version`
- `gbp.deb.changelog.ChangeLog.epoch`
- `gbp.deb.changelog.ChangeLog.noepoch`

    >>> import gbp.deb.changelog
    >>> cl = gbp.deb.changelog.ChangeLog(cl_upstream)
    >>> cl.version
    '1.0-1'
    >>> cl.version == cl['Version']
    True
    >>> cl.debian_version
    '1'
    >>> cl.debian_version == cl['Debian-Version']
    True
    >>> cl.noepoch
    '1.0-1'
    >>> cl.noepoch == cl['NoEpoch-Version']
    True
    >>> cl.epoch
    >>> cl.upstream_version
    '1.0'
    >>> cl.has_epoch()
    False
    >>> cl.distribution
    'unstable'

def test_parse_eopch():

Parse a the changelog of a package without epoch

Methods tested:

- `gbp.deb.changelog.ChangeLog.__init__`
- `gbp.deb.changelog.ChangeLog.has_epoch`

Properties tested:

- `gbp.deb.changelog.ChangeLog.version`
- `gbp.deb.changelog.ChangeLog.debian_version`
- `gbp.deb.changelog.ChangeLog.upstream_version`
- `gbp.deb.changelog.ChangeLog.epoch`
- `gbp.deb.changelog.ChangeLog.noepoch`

    >>> import gbp.deb.changelog
    >>> cl = gbp.deb.changelog.ChangeLog(cl_epoch)
    >>> cl.version
    '1:1.2.0-3'
    >>> cl.version == cl['Version']
    True
    >>> cl.debian_version
    '3'
    >>> cl.debian_version == cl['Debian-Version']
    True
    >>> cl.noepoch
    '1.2.0-3'
    >>> cl.noepoch == cl['NoEpoch-Version']
    True
    >>> cl.epoch
    '1'
    >>> cl.upstream_version
    '1.2.0'
    >>> cl.has_epoch()
    True

def test_parse_name():

Methods tested:

- `gbp.deb.changelog.ChangeLog.__init__`

Properties tested:

- `gbp.deb.changelog.ChangeLog.name`

    >>> import gbp.deb.changelog
    >>> cl = gbp.deb.changelog.ChangeLog(cl_debian)
    >>> cl.name
    'git-buildpackage'

def test_parse_last_mod():

Test author, email and date of last modification

Methods tested:

- `gbp.deb.changelog.ChangeLog.__init__`

Properties tested:

- `gbp.deb.changelog.ChangeLog.name`
- `gbp.deb.changelog.ChangeLog.email`
- `gbp.deb.changelog.ChangeLog.date`

    >>> import gbp.deb.changelog
    >>> cl = gbp.deb.changelog.ChangeLog(cl_debian)
    >>> cl.author.startswith('Guido')
    True
    >>> cl.email
    'agx@sigxcpu.org'
    >>> cl.date
    'Mon, 17 Oct 2011 10:15:22 +0200'

def test_parse_sections():

Test if we can parse sections out of the changelog

Methods tested:

- `gbp.deb.changelog.ChangeLog.__init__`
- `gbp.deb.changelog.ChangeLogSection.__init__`
- `gbp.deb.changelog.ChangeLogSection.parse`

Properties tested:

- `gbp.deb.changelog.ChangeLog.sections`

    >>> import gbp.deb.changelog
    >>> cl = gbp.deb.changelog.ChangeLog(cl_debian)
    >>> cl.sections[0].package
    'git-buildpackage'
    >>> cl.sections[0].version
    '0.5.32'
    >>> cl.sections[1].package
    'git-buildpackage'
    >>> cl.sections[1].version
    '0.5.31'

def test_get_changes():

Test if we can get changes

Methods tested:

- `gbp.deb.changelog.ChangeLog.__init__`
- `gbp.deb.changelog.ChangeLog.get_changes`

    >>> import gbp.deb.changelog
    >>> cl = gbp.deb.changelog.ChangeLog(cl_debian)
    >>> len(cl.get_changes().split('\n'))
    19
    >>> len(cl.get_changes('0.5.31').split('\n'))
    7
    >>> cl['Changes'].split('\n')[0]
    ' git-buildpackage (0.5.32) unstable; urgency=low'
    >>> len(cl['Changes'])
    187

def test_add_section():

Test if we can add a section to an existing changelog

Methods tested:

- `gbp.deb.changelog.ChangeLog.__init__`
- `gbp.deb.changelog.ChangeLog._parse`
- `gbp.deb.changelog.ChangeLog.add_section`
- `gbp.deb.changelog.ChangeLog.spawn_dch`

    >>> import os
    >>> import tempfile
    >>> import shutil
    >>> import gbp.deb.changelog
    >>> from ..testutils import OsReleaseFile
    >>> os_release = OsReleaseFile('/etc/lsb-release')
    >>> olddir = os.path.abspath(os.path.curdir)
    >>> testdir = tempfile.mkdtemp(prefix='gbp-test-changelog-')
    >>> testdebdir = os.path.join(testdir, 'debian')
    >>> testclname = os.path.join(testdebdir, "changelog")
    >>> os.mkdir(testdebdir)
    >>> clh = open(os.path.join(testdebdir, "changelog"), "w", encoding='utf-8')
    >>> ret = clh.write(cl_debian)
    >>> clh.close()
    >>> os.chdir(testdir)
    >>> os.path.abspath(os.path.curdir) == testdir
    True
    >>> cl = gbp.deb.changelog.ChangeLog(filename=testclname)
    >>> cl.add_section(msg=["Test add section"], distribution=None, author="Debian Maintainer", email="maint@debian.org")
    >>> cl = gbp.deb.changelog.ChangeLog(filename=testclname)
    >>> version = '0.5.32ubuntu1' if os_release['DISTRIB_ID'] == 'Ubuntu' else '0.5.33'
    >>> cl.version == version
    True
    >>> cl.debian_version == version
    True
    >>> distributions = ['UNRELEASED', os_release['DISTRIB_CODENAME'] or 'unstable']
    >>> cl['Distribution'] in distributions
    True
    >>> 'Test add section' in cl['Changes']
    True
    >>> os.chdir(olddir)
    >>> os.path.abspath(os.path.curdir) == olddir
    True
    >>> shutil.rmtree(testdir, ignore_errors=True)

def test_add_entry():

Test if we can add an entry to an existing changelog

Methods tested:

- `gbp.deb.changelog.ChangeLog.__init__`
- `gbp.deb.changelog.ChangeLog._parse`
- `gbp.deb.changelog.ChangeLog.add_entry`
- `gbp.deb.changelog.ChangeLog.spawn_dch`

    >>> import os
    >>> import tempfile
    >>> import shutil
    >>> import gbp.deb.changelog
    >>> from ..testutils import OsReleaseFile
    >>> os_release = OsReleaseFile('/etc/lsb-release')
    >>> olddir = os.path.abspath(os.path.curdir)
    >>> testdir = tempfile.mkdtemp(prefix='gbp-test-changelog-')
    >>> testdebdir = os.path.join(testdir, 'debian')
    >>> testclname = os.path.join(testdebdir, "changelog")
    >>> os.mkdir(testdebdir)
    >>> clh = open(os.path.join(testdebdir, "changelog"), "w", encoding='utf-8')
    >>> ret = clh.write(cl_debian)
    >>> clh.close()
    >>> os.chdir(testdir)
    >>> os.path.abspath(os.path.curdir) == testdir
    True
    >>> cl = gbp.deb.changelog.ChangeLog(filename=testclname)
    >>> cl.add_section(msg=["Test add section"], distribution=None, author="Debian Maintainer", email="maint@debian.org")
    >>> cl.add_entry(msg=["Test add entry"], author="Debian Maintainer", email="maint@debian.org")
    >>> cl = gbp.deb.changelog.ChangeLog(filename=testclname)
    >>> version = '0.5.32ubuntu1' if os_release['DISTRIB_ID'] == 'Ubuntu' else '0.5.33'
    >>> cl.version == version
    True
    >>> cl.debian_version == version
    True
    >>> distributions = ['UNRELEASED', os_release['DISTRIB_CODENAME'] or 'unstable']
    >>> cl['Distribution'] in distributions
    True
    >>> 'Test add entry' in cl['Changes']
    True
    >>> cl['Changes'].split('*',1)[1]
    ' Test add section\n   * Test add entry'
    >>> os.chdir(olddir)
    >>> os.path.abspath(os.path.curdir) == olddir
    True
    >>> shutil.rmtree(testdir, ignore_errors=True)