def test_changelog_release_plugin_cache( # pylint: disable=redefined-outer-name collection_changelog): # noqa: F811 collection_changelog.set_galaxy({ 'version': '1.0.0', }) collection_changelog.config.title = 'My Amazing Collection' collection_changelog.set_config(collection_changelog.config) collection_changelog.add_fragment_line( '1.0.0.yml', 'release_summary', 'This is the first proper release.') collection_changelog.add_plugin( 'module', 'test_module.py', create_plugin( DOCUMENTATION={ 'name': 'test_module', 'short_description': 'A test module', 'version_added': '1.0.0', 'description': ['This is a test module.'], 'author': ['Someone'], 'options': {}, }, EXAMPLES='', RETURN={}, )) collection_changelog.add_plugin( 'module', '__init__.py', create_plugin( DOCUMENTATION={ 'name': 'bad_module', 'short_description': 'Bad module', 'description': ['This should be ignored, not found as a module!.'], 'author': ['badguy'], 'options': {}, }, EXAMPLES='# Some examples\n', RETURN={}, ), subdirs=['cloud']) collection_changelog.add_plugin('module', 'old_module.py', create_plugin( DOCUMENTATION={ 'name': 'old_module', 'short_description': 'An old module', 'description': ['This is an old module.'], 'author': ['Elder'], 'options': {}, }, EXAMPLES='# Some examples\n', RETURN={}, ), subdirs=['cloud', 'sky']) collection_changelog.add_plugin('module', 'bad_module2', create_plugin( DOCUMENTATION={ 'name': 'bad_module2', 'short_description': 'An bad module', 'description': ['Shold not be found either.'], 'author': ['Elder'], 'options': {}, }, EXAMPLES='# Some examples\n', RETURN={}, ), subdirs=['cloud', 'sky']) collection_changelog.add_plugin( 'callback', 'test_callback.py', create_plugin( DOCUMENTATION={ 'name': 'test_callback', 'short_description': 'A not so old callback', 'version_added': '0.5.0', 'description': ['This is a relatively new callback added before.'], 'author': ['Someone else'], 'options': {}, }, EXAMPLES='# Some examples\n', RETURN={}, )) collection_changelog.add_plugin( 'callback', 'test_callback2.py', create_plugin( DOCUMENTATION={ 'name': 'test_callback2', 'short_description': 'This one should not be found.', 'version_added': '2.9', 'description': ['This is a relatively new callback added before.'], 'author': ['Someone else'], 'options': {}, }, EXAMPLES='# Some examples\n', RETURN={}, ), subdirs=['dont', 'find', 'me']) assert collection_changelog.run_tool('release', ['-v', '--date', '2020-01-02']) == 0 diff = collection_changelog.diff() assert diff.added_dirs == [] assert diff.added_files == [ 'changelogs/.plugin-cache.yaml', 'changelogs/CHANGELOG.rst', 'changelogs/changelog.yaml', ] assert diff.removed_dirs == [] assert diff.removed_files == ['changelogs/fragments/1.0.0.yml'] assert diff.changed_files == [] plugin_cache = diff.parse_yaml('changelogs/.plugin-cache.yaml') assert plugin_cache['version'] == '1.0.0' # Plugin cache: modules assert sorted( plugin_cache['plugins']['module']) == ['old_module', 'test_module'] assert plugin_cache['plugins']['module']['old_module'][ 'name'] == 'old_module' assert plugin_cache['plugins']['module']['old_module'][ 'namespace'] == 'cloud.sky' assert plugin_cache['plugins']['module']['old_module'][ 'description'] == 'An old module' assert plugin_cache['plugins']['module']['old_module'][ 'version_added'] is None assert plugin_cache['plugins']['module']['test_module'][ 'name'] == 'test_module' assert plugin_cache['plugins']['module']['test_module']['namespace'] == '' assert plugin_cache['plugins']['module']['test_module'][ 'description'] == 'A test module' assert plugin_cache['plugins']['module']['test_module'][ 'version_added'] == '1.0.0' # Plugin cache: callbacks assert sorted(plugin_cache['plugins']['callback']) == ['test_callback'] assert plugin_cache['plugins']['callback']['test_callback'][ 'name'] == 'test_callback' assert plugin_cache['plugins']['callback']['test_callback']['description'] == \ 'A not so old callback' assert plugin_cache['plugins']['callback']['test_callback'][ 'version_added'] == '0.5.0' assert 'namespace' not in plugin_cache['plugins']['callback'][ 'test_callback'] # Changelog changelog = diff.parse_yaml('changelogs/changelog.yaml') assert changelog['ancestor'] is None assert sorted(changelog['releases']) == ['1.0.0'] assert changelog['releases']['1.0.0']['release_date'] == '2020-01-02' assert changelog['releases']['1.0.0']['changes'] == { 'release_summary': 'This is the first proper release.' } assert changelog['releases']['1.0.0']['fragments'] == ['1.0.0.yml'] assert len(changelog['releases']['1.0.0']['modules']) == 1 assert changelog['releases']['1.0.0']['modules'][0][ 'name'] == 'test_module' assert changelog['releases']['1.0.0']['modules'][0]['namespace'] == '' assert changelog['releases']['1.0.0']['modules'][0][ 'description'] == 'A test module' assert 'version_added' not in changelog['releases']['1.0.0']['modules'][0] assert diff.file_contents['changelogs/CHANGELOG.rst'].decode('utf-8') == ( r'''=================================== My Amazing Collection Release Notes =================================== .. contents:: Topics v1.0.0 ====== Release Summary --------------- This is the first proper release. New Modules ----------- - test_module - A test module ''')
def test_changelog_release_plugin_cache(collection_changelog): collection_changelog.set_galaxy({ 'version': '1.0.0', }) collection_changelog.set_config(collection_changelog.config) collection_changelog.add_fragment_line( '1.0.0.yml', 'release_summary', 'This is the first proper release.') collection_changelog.add_plugin( 'module', 'test_module.py', create_plugin( DOCUMENTATION={ 'name': 'test_module', 'short_description': 'A test module', 'version_added': '1.0.0', 'description': ['This is a test module.'], 'author': ['Someone'], 'options': {}, }, EXAMPLES='', RETURN={}, )) collection_changelog.add_plugin('module', 'old_module.py', create_plugin( DOCUMENTATION={ 'name': 'old_module', 'short_description': 'An old module', 'description': ['This is an old module.'], 'author': ['Elder'], 'options': {}, }, EXAMPLES='# Some examples\n', RETURN={}, ), subdirs=['cloud', 'sky']) assert collection_changelog.run_tool('release', ['-v', '--date', '2020-01-02']) == 0 diff = collection_changelog.diff() assert diff.added_dirs == [] assert diff.added_files == [ 'changelogs/.plugin-cache.yaml', 'changelogs/CHANGELOG.rst', 'changelogs/changelog.yaml' ] assert diff.removed_dirs == [] assert diff.removed_files == ['changelogs/fragments/1.0.0.yml'] assert diff.changed_files == [] plugin_cache = diff.parse_yaml('changelogs/.plugin-cache.yaml') assert plugin_cache['version'] == '1.0.0' # Plugin cache: modules assert sorted( plugin_cache['plugins']['module']) == ['old_module', 'test_module'] assert plugin_cache['plugins']['module']['old_module'][ 'name'] == 'old_module' assert plugin_cache['plugins']['module']['old_module'][ 'namespace'] == 'cloud.sky' assert plugin_cache['plugins']['module']['old_module'][ 'description'] == 'An old module' assert plugin_cache['plugins']['module']['old_module'][ 'version_added'] is None assert plugin_cache['plugins']['module']['test_module'][ 'name'] == 'test_module' assert plugin_cache['plugins']['module']['test_module']['namespace'] == '' assert plugin_cache['plugins']['module']['test_module'][ 'description'] == 'A test module' assert plugin_cache['plugins']['module']['test_module'][ 'version_added'] == '1.0.0' # Changelog changelog = diff.parse_yaml('changelogs/changelog.yaml') assert changelog['ancestor'] is None assert sorted(changelog['releases']) == ['1.0.0'] assert changelog['releases']['1.0.0']['release_date'] == '2020-01-02' assert changelog['releases']['1.0.0']['changes'] == { 'release_summary': 'This is the first proper release.' } assert changelog['releases']['1.0.0']['fragments'] == ['1.0.0.yml'] assert len(changelog['releases']['1.0.0']['modules']) == 1 assert changelog['releases']['1.0.0']['modules'][0][ 'name'] == 'test_module' assert changelog['releases']['1.0.0']['modules'][0]['namespace'] == '' assert changelog['releases']['1.0.0']['modules'][0][ 'description'] == 'A test module' assert 'version_added' not in changelog['releases']['1.0.0']['modules'][0]