Skip to content

Commit

Permalink
Fix handling empty vm_type in Store.last_buildroot
Browse files Browse the repository at this point in the history
  • Loading branch information
dmach committed Sep 25, 2023
1 parent 4b5534b commit 93cfb76
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion osc/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def write_list(self, fn, value, subdir=None):
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):
Expand Down Expand Up @@ -291,6 +291,8 @@ def last_buildroot(self):
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
Expand Down
8 changes: 8 additions & 0 deletions tests/test_git_scm_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ def test_last_buildroot(self):
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")
Expand Down
6 changes: 6 additions & 0 deletions tests/test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ def test_last_buildroot(self):
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",
Expand Down

0 comments on commit 93cfb76

Please sign in to comment.