'This method creates the post and pre commands if coverage is to be
generated'

def _generate_coverage_commands(self):

    if (self.parallel != 0):
        raise ValueError('--coverage    can    not    be    used    with    --parallel')
    try:
        import coverage
    except ImportError:
        raise ImportError('--coverage    requires    that    the    coverage    package    is    installed.')
    coveragerc = os.path.join(self.testing_path, self.package_name, 'tests', 'coveragerc')
    with open(coveragerc, 'r') as fd:
        coveragerc_content = fd.read()
    if (not six.PY2):
        ignore_python_version = '2'
    else:
        ignore_python_version = '3'
    coveragerc_content = coveragerc_content.replace('{ignore_python_version}', ignore_python_version).replace('{packagename}', self.package_name)
    tmp_coveragerc = os.path.join(self.tmp_dir, 'coveragerc')
    with open(tmp_coveragerc, 'wb') as tmp:
        tmp.write(coveragerc_content.encode('utf-8'))
    cmd_pre = 'import    coverage;    cov    =    coverage.coverage(data_file="{0}",    config_file="{1}");    cov.start();'.format(os.path.abspath('.coverage'), tmp_coveragerc)
    cmd_post = 'cov.stop();    from    astropy.tests.helper    import    _save_coverage;    _save_coverage(cov,    result,    "{0}",    "{1}");'.format(os.path.abspath('.'), self.testing_path)
    return (cmd_pre, cmd_post)
