diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f5d1a959..67ca1894 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/lib/rift/RPM.py b/lib/rift/RPM.py index 7cfa3eae..afec03a5 100644 --- a/lib/rift/RPM.py +++ b/lib/rift/RPM.py @@ -40,6 +40,7 @@ import shutil from subprocess import Popen, PIPE, STDOUT, run, CalledProcessError import time +import locale import rpm @@ -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): diff --git a/tests/Controller.py b/tests/Controller.py index ac952b68..585a7cb3 100644 --- a/tests/Controller.py +++ b/tests/Controller.py @@ -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 @@ -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 - 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 - 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): + main(['changelog', 'pkg', '-c', 'basic change', '-t', 'Fail']) + + class ControllerArgumentsTest(RiftTestCase): """ Arguments parsing tests for Controller module"""