Skip to content

Commit 80704f1

Browse files
author
Johannes Otepka
committed
$glob tests improved using labels
1 parent 7622f41 commit 80704f1

File tree

2 files changed

+52
-14
lines changed

2 files changed

+52
-14
lines changed

ipyparallel/controller/dictdb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
'$all': lambda a, b: all([a in bb for bb in b]),
6161
'$mod': lambda a, b: a % b[0] == b[1],
6262
'$exists': lambda a, b: (b and a is not None) or (a is None and not b),
63-
'$glob': lambda a, b: fnmatch.fnmatch(a, b),
63+
'$glob': lambda a, b: fnmatch.fnmatch(a, b) if a is not None else False,
6464
}
6565

6666

ipyparallel/tests/test_db.py

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -135,19 +135,57 @@ def test_find_records_in(self):
135135

136136
def test_find_records_glob(self):
137137
"""test finding records with '$glob' operators"""
138-
hist = self.db.get_history()
139-
140-
pattern = "*" + hist[0][5:-2] + "_?"
141-
ref = [msg_id for msg_id in hist if fnmatch.fnmatch(msg_id, pattern)]
142-
recs = self.db.find_records({'msg_id': {'$glob': pattern}}, ["msg_id"])
143-
found = [r['msg_id'] for r in recs]
144-
assert set(ref) == set(found)
145-
146-
pattern = "*_1?"
147-
ref = [msg_id for msg_id in hist if fnmatch.fnmatch(msg_id, pattern)]
148-
recs = self.db.find_records({'msg_id': {'$glob': pattern}}, ["msg_id"])
149-
found = [r['msg_id'] for r in recs]
150-
assert set(ref) == set(found)
138+
msg_ids = self.load_records(10)
139+
labels = [
140+
"group_a",
141+
"group_a",
142+
"group_a/subgroup_a",
143+
"group_a/subgroup_b",
144+
"group_b",
145+
"group_b/subgroup_a",
146+
"group_b/subgroup_b",
147+
"group_b/subgroup_c",
148+
"label*task",
149+
"label?task",
150+
]
151+
assert len(msg_ids) == len(labels)
152+
for msg_id, label in zip(msg_ids, labels):
153+
self.db.update_record(msg_id, dict(label=label))
154+
155+
patterns = [
156+
"group_a*",
157+
"group_a/subgroup_?",
158+
"group_b",
159+
"group_b/subgroup_[ab]",
160+
"*/subgroup_a",
161+
"*[*]*",
162+
"*[?]*",
163+
]
164+
for pattern in patterns:
165+
ref = [
166+
msg_id
167+
for msg_id, label in zip(msg_ids, labels)
168+
if fnmatch.fnmatch(label, pattern)
169+
]
170+
recs = self.db.find_records(
171+
{'label': {'$glob': pattern}}, ["msg_id", 'label']
172+
)
173+
found = [r['msg_id'] for r in recs]
174+
assert set(ref) == set(found)
175+
176+
# hist = self.db.get_history()
177+
#
178+
# pattern = "*" + hist[0][5:-2] + "_?"
179+
# ref = [msg_id for msg_id in hist if fnmatch.fnmatch(msg_id, pattern)]
180+
# recs = self.db.find_records({'msg_id': {'$glob': pattern}}, ["msg_id"])
181+
# found = [r['msg_id'] for r in recs]
182+
# assert set(ref) == set(found)
183+
#
184+
# pattern = "*_1?"
185+
# ref = [msg_id for msg_id in hist if fnmatch.fnmatch(msg_id, pattern)]
186+
# recs = self.db.find_records({'msg_id': {'$glob': pattern}}, ["msg_id"])
187+
# found = [r['msg_id'] for r in recs]
188+
# assert set(ref) == set(found)
151189

152190
def test_get_history(self):
153191
msg_ids = self.db.get_history()

0 commit comments

Comments
 (0)