1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-02-04 10:36:17 +01:00

Merge pull request #1412 from dmach/fix-store-last_buildroot-vm_type-None

Fix handling empty vm_type in Store.last_buildroot
This commit is contained in:
Daniel Mach 2023-09-25 10:59:28 +02:00 committed by GitHub
commit 641b365f38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 2 deletions

View File

@ -179,7 +179,7 @@ class OscOptions(BaseModel):
if not value.strip():
if field.is_optional:
setattr(self, field_name, value)
setattr(self, field_name, None)
return
if field.origin_type is Password:

View File

@ -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

View File

@ -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")

View File

@ -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",