Skip to content

Commit ee4c1f0

Browse files
authored
Merge pull request #19 from rezib/pr/fix-changelog-locale
Temporarily user C locale for date in spec changelog
2 parents c4f3b5d + 12b1fbc commit ee4c1f0

File tree

3 files changed

+74
-1
lines changed

3 files changed

+74
-1
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ jobs:
3636
steps:
3737
- uses: actions/checkout@v4
3838

39+
# Generate missing locales in the container. Programs are executed with
40+
# en_US.UTF-8 locale, this locale must be defined in the container in
41+
# order to be restored by Rift without errors when manipulating dates.
42+
- name: Install locales
43+
run: |
44+
dnf install -y glibc-locale-source glibc-langpack-en
45+
localedef -i en_US -f UTF-8 en_US.UTF-8
46+
3947
# Mount binfmt_misc virtual FS to register support of additional binary
4048
# formats for multi-arch builds.
4149
- name: Mount binfmt_misc virtual filesystem

lib/rift/RPM.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
from subprocess import Popen, PIPE, STDOUT, run, CalledProcessError
4242
import time
4343
import datetime
44+
import locale
4445

4546
import rpm
4647

@@ -374,7 +375,14 @@ def add_changelog_entry(self, userstring, comment, bump=False):
374375
if bump:
375376
self.bump_release()
376377

378+
# Temporarily set basic C locale to generate date representation in
379+
# changelog.
380+
current_locale = locale.getlocale(locale.LC_TIME)
381+
locale.setlocale(locale.LC_TIME, 'C')
377382
date = time.strftime("%a %b %d %Y", time.gmtime())
383+
# Immediately restore previous locale.
384+
locale.setlocale(locale.LC_TIME, current_locale)
385+
378386
newchangelogentry = f"* {date} {userstring} - {self.evr}\n{comment}\n"
379387
chlg_match = None
380388
for i, _ in enumerate(self.lines):

tests/Controller.py

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
make_parser,
2222
)
2323
from rift.Package import Package
24-
from rift.RPM import RPM
24+
from rift.RPM import RPM, Spec
2525
from rift.run import RunResult
2626
from rift import RiftError
2727

@@ -697,6 +697,63 @@ def test_action_sync_missing_output_parent(self):
697697
main(['sync'])
698698

699699

700+
class ControllerProjectActionChangelogTest(RiftProjectTestCase):
701+
"""
702+
Tests class for Controller action changelog
703+
"""
704+
705+
def test_action_changelog_without_pkg(self):
706+
"""changelog without package fails """
707+
with self.assertRaisesRegex(SystemExit, "2"):
708+
main(['changelog'])
709+
710+
def test_action_changelog_without_comment(self):
711+
"""changelog without comment fails """
712+
with self.assertRaisesRegex(SystemExit, "2"):
713+
main(['changelog', 'pkg'])
714+
715+
def test_action_changelog_without_maintainer(self):
716+
"""changelog without maintainer """
717+
with self.assertRaisesRegex(RiftError, "You must specify a maintainer"):
718+
main(['changelog', 'pkg', '-c', 'basic change'])
719+
720+
def test_action_changelog_pkg_not_found(self):
721+
"""changelog package not found"""
722+
with self.assertRaisesRegex(
723+
RiftError,
724+
"Package 'pkg' directory does not exist"):
725+
main(['changelog', 'pkg', '-c', 'basic change', '-t', 'Myself'])
726+
727+
def test_action_changelog(self):
728+
"""simple changelog"""
729+
self.make_pkg()
730+
self.assertEqual(
731+
main(['changelog', 'pkg', '-c', 'basic change', '-t', 'Myself']), 0)
732+
spec = Spec(filepath=self.pkgspecs['pkg'])
733+
spec.load()
734+
self.assertEqual(spec.changelog_name, 'Myself <buddy@somewhere.org> - 1.0-1')
735+
self.assertEqual(spec.version, '1.0')
736+
self.assertEqual(spec.release, '1')
737+
738+
def test_action_changelog_bump(self):
739+
"""simple changelog with bump"""
740+
self.make_pkg()
741+
self.assertEqual(
742+
main(['changelog', 'pkg', '-c', 'basic change', '-t', 'Myself', '--bump']),
743+
0)
744+
spec = Spec(filepath=self.pkgspecs['pkg'])
745+
spec.load()
746+
self.assertEqual(spec.changelog_name, 'Myself <buddy@somewhere.org> - 1.0-2')
747+
self.assertEqual(spec.version, '1.0')
748+
self.assertEqual(spec.release, '2')
749+
750+
def test_action_changelog_unknown_maintainer(self):
751+
"""changelog with unknown maintainer"""
752+
self.make_pkg()
753+
with self.assertRaises(TypeError):
754+
main(['changelog', 'pkg', '-c', 'basic change', '-t', 'Fail'])
755+
756+
700757
class ControllerArgumentsTest(RiftTestCase):
701758
""" Arguments parsing tests for Controller module"""
702759

0 commit comments

Comments
 (0)