From 93cfb76a463a77aae79c6c33e0797437f16bc094 Mon Sep 17 00:00:00 2001 From: Daniel Mach Date: Mon, 25 Sep 2023 10:16:00 +0200 Subject: [PATCH] Fix handling empty vm_type in Store.last_buildroot --- osc/store.py | 4 +++- tests/test_git_scm_store.py | 8 ++++++++ tests/test_store.py | 6 ++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/osc/store.py b/osc/store.py index d96d4c66..3aad42c5 100644 --- a/osc/store.py +++ b/osc/store.py @@ -119,7 +119,7 @@ class Store: if not isinstance(value, (list, tuple)): msg = f"The argument `value` should be list, not {type(value).__name__}" raise TypeError(msg) - value = "".join((f"{line}\n" for line in value)) + value = "".join((f"{line or ''}\n" for line in value)) self.write_file(fn, value, subdir=subdir) def read_string(self, fn, subdir=None): @@ -291,6 +291,8 @@ class Store: if items is not None and len(items) != 3: msg = f"Package '{self.path}' contains _last_buildroot metadata that doesn't contain 3 lines: [repo, arch, vm_type]" raise oscerr.NoWorkingCopy(msg) + if items[2] in ("", "None"): + items[2] = None return items @last_buildroot.setter diff --git a/tests/test_git_scm_store.py b/tests/test_git_scm_store.py index e884f4b2..dcde2b4c 100644 --- a/tests/test_git_scm_store.py +++ b/tests/test_git_scm_store.py @@ -36,6 +36,14 @@ class TestGitStore(unittest.TestCase): store = GitStore(self.tmpdir) self.assertEqual(store.last_buildroot, ("repo", "arch", "vm_type")) + def test_last_buildroot_empty_vm_type(self): + store = GitStore(self.tmpdir) + self.assertEqual(store.last_buildroot, None) + store.last_buildroot = ("repo", "arch", None) + + store = GitStore(self.tmpdir) + self.assertEqual(store.last_buildroot, ("repo", "arch", None)) + def test_scmurl(self): store = GitStore(self.tmpdir) self.assertEqual(store.scmurl, "https://example.com/packages/my-package.git") diff --git a/tests/test_store.py b/tests/test_store.py index f77cf613..c5eb9db9 100644 --- a/tests/test_store.py +++ b/tests/test_store.py @@ -203,6 +203,12 @@ class TestStore(unittest.TestCase): store2 = Store(self.tmpdir) self.assertEqual(store2.last_buildroot, ["repo", "arch", "vm_type"]) + self.store.last_buildroot = "repo", "arch", None + self.fileEquals("_last_buildroot", "repo\narch\n\n") + + store2 = Store(self.tmpdir) + self.assertEqual(store2.last_buildroot, ["repo", "arch", None]) + def test_meta_node(self): self.store.write_string( "_meta",