Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ jobs:
steps:
- uses: actions/checkout@v4

# Generate missing locales in the container. Programs are executed with
# en_US.UTF-8 locale, this locale must be defined in the container in
# order to be restored by Rift without errors when manipulating dates.
- name: Install locales
run: |
dnf install -y glibc-locale-source glibc-langpack-en
localedef -i en_US -f UTF-8 en_US.UTF-8

# Mount binfmt_misc virtual FS to register support of additional binary
# formats for multi-arch builds.
- name: Mount binfmt_misc virtual filesystem
Expand Down
8 changes: 8 additions & 0 deletions lib/rift/RPM.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import shutil
from subprocess import Popen, PIPE, STDOUT, run, CalledProcessError
import time
import locale

import rpm

Expand Down Expand Up @@ -364,7 +365,14 @@ def add_changelog_entry(self, userstring, comment, bump=False):
if bump:
self.bump_release()

# Temporarily set basic C locale to generate date representation in
# changelog.
current_locale = locale.getlocale(locale.LC_TIME)
locale.setlocale(locale.LC_TIME, 'C')
date = time.strftime("%a %b %d %Y", time.gmtime())
# Immediately restore previous locale.
locale.setlocale(locale.LC_TIME, current_locale)

newchangelogentry = f"* {date} {userstring} - {self.evr}\n{comment}\n"
chlg_match = None
for i, _ in enumerate(self.lines):
Expand Down
59 changes: 58 additions & 1 deletion tests/Controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
make_parser,
)
from rift.Package import Package
from rift.RPM import RPM
from rift.RPM import RPM, Spec
from rift.run import RunResult
from rift import RiftError

Expand Down Expand Up @@ -983,6 +983,63 @@ def test_action_sync_missing_output_parent(self):
main(['sync'])


class ControllerProjectActionChangelogTest(RiftProjectTestCase):
"""
Tests class for Controller action changelog
"""

def test_action_changelog_without_pkg(self):
"""changelog without package fails """
with self.assertRaisesRegex(SystemExit, "2"):
main(['changelog'])

def test_action_changelog_without_comment(self):
"""changelog without comment fails """
with self.assertRaisesRegex(SystemExit, "2"):
main(['changelog', 'pkg'])

def test_action_changelog_without_maintainer(self):
"""changelog without maintainer """
with self.assertRaisesRegex(RiftError, "You must specify a maintainer"):
main(['changelog', 'pkg', '-c', 'basic change'])

def test_action_changelog_pkg_not_found(self):
"""changelog package not found"""
with self.assertRaisesRegex(
RiftError,
"Package 'pkg' directory does not exist"):
main(['changelog', 'pkg', '-c', 'basic change', '-t', 'Myself'])

def test_action_changelog(self):
"""simple changelog"""
self.make_pkg()
self.assertEqual(
main(['changelog', 'pkg', '-c', 'basic change', '-t', 'Myself']), 0)
spec = Spec(filepath=self.pkgspecs['pkg'])
spec.load()
self.assertEqual(spec.changelog_name, 'Myself <[email protected]> - 1.0-1')
self.assertEqual(spec.version, '1.0')
self.assertEqual(spec.release, '1')

def test_action_changelog_bump(self):
"""simple changelog with bump"""
self.make_pkg()
self.assertEqual(
main(['changelog', 'pkg', '-c', 'basic change', '-t', 'Myself', '--bump']),
0)
spec = Spec(filepath=self.pkgspecs['pkg'])
spec.load()
self.assertEqual(spec.changelog_name, 'Myself <[email protected]> - 1.0-2')
self.assertEqual(spec.version, '1.0')
self.assertEqual(spec.release, '2')

def test_action_changelog_unknown_maintainer(self):
"""changelog with unknown maintainer"""
self.make_pkg()
with self.assertRaises(TypeError):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: shouldn't it be a RiftError and have a proper message aswell ? Seems like a common issue, so having its own error message would be nice

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, for sure. However, it's arguably out of scope of this PR. Do you want me to open another PR for this or just add a commit in this one?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another PR is fine by me

main(['changelog', 'pkg', '-c', 'basic change', '-t', 'Fail'])


class ControllerArgumentsTest(RiftTestCase):
""" Arguments parsing tests for Controller module"""

Expand Down