Skip to content

Commit

Permalink
fix(merge): handle iterables in sets union correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
jdreo committed Nov 12, 2024
1 parent 591f508 commit abb64f3
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/ontoweaver/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class Append(DictryMerger):

def __init__(self, sep = None):
self.sep = sep
self.merged = {}

def reset(self):
self.merged = {}
Expand All @@ -144,7 +145,7 @@ def set(self, merged) -> None:
if type(v) == set:
e.union(v)
else:
self.merged[k] = set(v).union(e)
self.merged[k] = set((v,)).union(e)

def merge(self, key, lhs: dict[str,str], rhs: dict[str,str]):
self.set(lhs)
Expand Down
42 changes: 42 additions & 0 deletions tests/test_merge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import logging

import ontoweaver

def test_append():

sep = ";"
merge = ontoweaver.merge.dictry.Append(sep)

k = ontoweaver.base.Node()

merge(k, {"p1":"x"},{"p2":"y"} )
assert( merge.get() == {"p1":"x", "p2":"y"} )

merge.reset()
merge(k, {"p1":"x"},{} )
assert( merge.get() == {"p1":"x"} )

merge.reset()
merge(k, {"p1":"x", "p2":"y"},{} )
assert( merge.get() == {"p1":"x", "p2":"y"} )

merge.reset()
merge(k, {"p1":"x"},{"p1":"y"} )
assert( "y" in merge.get()["p1"].split(sep) )
assert( "x" in merge.get()["p1"].split(sep) )

merge.reset()
merge(k, {"p1":"abcd"},{"p1":"efgh"} )
m = merge.get()
assert( "abcd" in m["p1"].split(sep) )
assert( "efgh" in m["p1"].split(sep) )

merge.reset()
merge(k, {"p1":"[abcd]"},{"p1":"[efgh]"} )
m = merge.get()
assert( "[abcd]" in m["p1"].split(sep) )
assert( "[efgh]" in m["p1"].split(sep) )


if __name__ == "__main__":
test_append()

0 comments on commit abb64f3

Please sign in to comment.