Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
BTrees
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
BTrees
Commits
48b6f87d
Commit
48b6f87d
authored
Dec 12, 2012
by
Tres Seaver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Factor out check for missing MERGE_DEFAULT to saner spot.
parent
5d43842d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
6 deletions
+24
-6
BTrees/_base.py
BTrees/_base.py
+2
-6
BTrees/tests/test__base.py
BTrees/tests/test__base.py
+22
-0
No files found.
BTrees/_base.py
View file @
48b6f87d
...
...
@@ -1278,14 +1278,10 @@ def intersection(set_type, o1, o2):
def
_prepMergeIterators
(
o1
,
o2
):
MERGE_DEFAULT
=
getattr
(
o1
,
'MERGE_DEFAULT'
,
None
)
if
MERGE_DEFAULT
is
None
:
raise
TypeError
(
"invalid set operation"
)
i1
=
_SetIteration
(
o1
,
True
,
MERGE_DEFAULT
)
i2
=
_SetIteration
(
o2
,
True
,
MERGE_DEFAULT
)
if
MERGE_DEFAULT
is
None
:
if
i1
.
useValues
:
if
(
not
i2
.
useValues
):
raise
TypeError
(
"invalid set operation"
)
else
:
raise
TypeError
(
"invalid set operation"
)
return
i1
,
i2
def
weightedUnion
(
set_type
,
o1
,
o2
,
w1
=
1
,
w2
=
1
):
...
...
BTrees/tests/test__base.py
View file @
48b6f87d
...
...
@@ -2645,6 +2645,17 @@ class Test_weightedUnion(unittest.TestCase, _SetObBase):
rhs
=
self
.
_makeSet
(
'a'
,
'b'
,
'c'
)
self
.
assertRaises
(
TypeError
,
self
.
_callFUT
,
lhs
.
__class__
,
lhs
,
rhs
)
def
test_lhs_mapping_wo_MERGE_rhs_mapping
(
self
):
class
_MappingWoMerge
(
dict
):
def
MERGE_DEFAULT
(
self
):
return
1
def
MERGE_WEIGHT
(
self
,
v
,
w
):
return
v
lhs
=
_MappingWoMerge
({
'a'
:
13
,
'b'
:
12
,
'c'
:
11
})
lhs
.
_mapping_type
=
_MappingWoMerge
rhs
=
self
.
_makeMapping
({
'a'
:
1
,
'b'
:
2
,
'c'
:
3
})
self
.
assertRaises
(
TypeError
,
self
.
_callFUT
,
lhs
.
__class__
,
lhs
,
rhs
)
def
test_lhs_set_wo_MERGE_DEFAULT_rhs_mapping
(
self
):
lhs
=
self
.
_makeSet
(
'a'
,
'd'
)
lhs
.
MERGE
=
lambda
v1
,
w1
,
v2
,
w2
:
(
v1
*
w1
)
+
(
v2
*
w2
)
...
...
@@ -2736,6 +2747,17 @@ class Test_weightedIntersection(unittest.TestCase, _SetObBase):
rhs
=
{
'b'
:
22
,
'd'
:
14
}
self
.
assertRaises
(
TypeError
,
self
.
_callFUT
,
lhs
.
__class__
,
lhs
,
rhs
)
def
test_lhs_mapping_wo_MERGE_rhs_mapping
(
self
):
class
_MappingWoMerge
(
dict
):
def
MERGE_DEFAULT
(
self
):
return
1
def
MERGE_WEIGHT
(
self
,
v
,
w
):
return
v
lhs
=
_MappingWoMerge
({
'a'
:
13
,
'b'
:
12
,
'c'
:
11
})
lhs
.
_mapping_type
=
_MappingWoMerge
rhs
=
self
.
_makeMapping
({
'a'
:
1
,
'b'
:
2
,
'c'
:
3
})
self
.
assertRaises
(
TypeError
,
self
.
_callFUT
,
lhs
.
__class__
,
lhs
,
rhs
)
def
test_lhs_set_wo_MERGE_DEFAULT_rhs_set
(
self
):
lhs
=
self
.
_makeSet
(
'a'
,
'd'
)
lhs
.
MERGE
=
lambda
v1
,
w1
,
v2
,
w2
:
(
v1
*
w1
)
+
(
v2
*
w2
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment