Exemple #1
0
    def test_release(self):
        valid_files = [
            'CHANGELOG.md',
            'CHANGELOG_unrelease_only.md'
        ]

        for filename in valid_files:
            changelog_file = os.path.join(os.path.dirname(
                os.path.realpath(__file__)), "data", filename)
            changelog = kacl.load(changelog_file)

            msg = 'This is my first added change'
            changelog.add('Added', msg)

            self.assertTrue(changelog.has_changes())

            changelog.release(version='2.0.0', link='https://my-new-version/2.0.0.html')

            changelog_dump = kacl.dump(changelog)
            self.assertIsNotNone(changelog_dump)

            changelog_changed = kacl.parse(changelog_dump)
            self.assertIsNotNone(changelog_changed)

            version = changelog_changed.get('2.0.0')
            self.assertIsNotNone(version)

            self.assertIn(msg, version.changes('Added').items())
Exemple #2
0
def load_changelog(ctx):
    config = ctx.obj['config']
    file = ctx.obj['file']

    changelog_file = os.path.join(os.getcwd(), file)
    if not os.path.exists(changelog_file):
        click.echo(
            click.style("Error: ", fg='red') + f"{changelog_file} not found")
        sys.exit(1)

    if config is None:
        default_config_path = os.path.join(os.getcwd(), '.kacl.yml')
        config = default_config_path if os.path.exists(
            default_config_path) else None

    kacl_config = kacl.KACLConfig(config)
    if file:
        kacl_config.set_changelog_file_path(file)

    # read the changelog
    kacl_changelog = kacl.load(kacl_config.changelog_file_path())
    kacl_changelog.set_config(kacl_config)

    # share the objects
    return (kacl_changelog, changelog_file)
Exemple #3
0
    def test_unreleased_missing_sections(self):
        changelog_file = os.path.join(os.path.dirname(
            os.path.realpath(__file__)), "data/CHANGELOG_missing_sections.md")

        changelog = kacl.load(changelog_file)
        validation = changelog.validate()
        self.assertFalse(changelog.is_valid())
Exemple #4
0
    def test_add_change(self):
        changelog_file = os.path.join(os.path.dirname(
            os.path.realpath(__file__)), "data/CHANGELOG.md")

        changelog = kacl.load(changelog_file)

        msg = 'This is my first added change'
        changelog.add('Added', msg)

        changelog_dump = kacl.dump(changelog)
        self.assertIsNotNone(changelog_dump)

        changelog_changed = kacl.parse(changelog_dump)
        self.assertIsNotNone(changelog_changed)

        unreleased = changelog_changed.get('Unreleased')
        self.assertIsNotNone(unreleased)

        unreleased_change_sections = unreleased.sections()
        self.assertIsNotNone(unreleased_change_sections)
        self.assertIn('Added', unreleased_change_sections)

        unreleased_changes_added = unreleased.changes('Added')
        self.assertIsNotNone(unreleased_changes_added)

        self.assertIn(msg, unreleased_changes_added.items())
Exemple #5
0
    def test_release_without_changes(self):
        changelog_file = os.path.join(os.path.dirname(
            os.path.realpath(__file__)), "data/CHANGELOG_no_unreleased.md")
        changelog = kacl.load(changelog_file)

        self.assertFalse(changelog.has_changes())
        self.assertRaises(Exception, changelog.release, "1.1.1", 'https://github.com/mschmieder/python-kacl/compare/v1.0.0...HEAD' )
Exemple #6
0
    def test_link_generation(self):
        valid_files = [
            #'CHANGELOG.md',
            'CHANGELOG_unrelease_only.md'
        ]

        for filename in valid_files:
            changelog_file = os.path.join(os.path.dirname(
                os.path.realpath(__file__)), "data", filename)
            changelog = kacl.load(changelog_file)

            changelog = kacl.load(changelog_file)
            changelog.generate_links()

            versions = changelog.versions()
            for v in versions:
                self.assertIsNotNone(v.link())
Exemple #7
0
    def test_valid(self):
        changelog_file = os.path.join(os.path.dirname(
            os.path.realpath(__file__)), "data/CHANGELOG.md")
        changelog = kacl.load(changelog_file)
        self.assertTrue(changelog.is_valid())

        validation = changelog.validate()
        self.assertGreaterEqual(len(validation.errors()), 0)
Exemple #8
0
    def test_release_with_non_semver(self):
        changelog_file = os.path.join(os.path.dirname(
            os.path.realpath(__file__)), "data/CHANGELOG.md")
        changelog = kacl.load(changelog_file)

        msg = 'This is my first added change'
        changelog.add('Added', msg)

        self.assertTrue(changelog.has_changes())
        self.assertRaises(Exception, changelog.release, "a0.9.0", 'https://github.com/mschmieder/python-kacl/compare/v1.0.0...HEAD' )
Exemple #9
0
    def test_link_generation(self):
        changlog_file = os.path.join(
            os.path.dirname(os.path.realpath(__file__)), "data/CHANGELOG.md")

        changelog = kacl.load(changlog_file)
        changelog.generate_links()

        versions = changelog.versions()
        for v in versions:
            self.assertIsNotNone(v.link())
Exemple #10
0
    def test_invalid(self):
        invalid_files = [
            'CHANGELOG_invalid.md', 'CHANGELOG_missing_sections.md',
            'CHANGELOG_no_unreleased.md'
        ]

        for filename in invalid_files:
            changlog_file = os.path.join(
                os.path.dirname(os.path.realpath(__file__)), "data", filename)
            changelog = kacl.load(changlog_file)
            self.assertFalse(changelog.is_valid())
Exemple #11
0
    def test_release_with_increment(self):
        tests = {"major": "2.0.0", "minor": "1.1.0", "patch": "1.0.1"}
        changlog_file = os.path.join(
            os.path.dirname(os.path.realpath(__file__)), "data/CHANGELOG.md")

        for increment, expected_version in tests.items():
            changelog = kacl.load(changlog_file)

            msg = 'This is my first added change'
            changelog.add('Added', msg)

            self.assertTrue(changelog.has_changes())
            changelog.release(increment=increment)
            self.assertEqual(expected_version, changelog.current_version())
Exemple #12
0
    def test_load_valid(self):
        changelog_file = os.path.join(os.path.dirname(
            os.path.realpath(__file__)), "data/CHANGELOG.md")
        changelog = kacl.load(changelog_file)

        self.assertEqual(changelog.title(), 'Changelog')
        self.assertGreater(len(changelog.versions()), 0)

        version = changelog.get('1.0.0')
        self.assertIsNotNone(version)

        added_changes = version.changes('Added')
        self.assertIsNotNone(added_changes)

        added_items = added_changes.items()
        self.assertIsNotNone(added_items)
Exemple #13
0
    def test_dump(self):
        changelog_file = os.path.join(os.path.dirname(
            os.path.realpath(__file__)), "data/CHANGELOG.md")
        changelog = kacl.load(changelog_file)
        changelog_dump = kacl.dump(changelog)
        self.assertIsNotNone(changelog_dump)

        with open(changelog_file, 'r') as reference_file:
            changelog_reference = reference_file.read()
        reference_file.close()

        changelog_dump_lines = changelog_dump.split('\n')
        changelog_reference_lines = changelog_reference.split('\n')

        self.assertEqual(len(changelog_dump_lines),
                         len(changelog_reference_lines))
        self.assertEqual(changelog_dump, changelog_reference)