Skip to content

Commit

Permalink
test: changed categorization test to include backslash-metacharacter …
Browse files Browse the repository at this point in the history
…(\w)
  • Loading branch information
ErikBjare committed Aug 5, 2020
1 parent c38b814 commit e83f3f8
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions tests/test_query2.py
Expand Up @@ -516,32 +516,32 @@ def test_query2_query_categorize(datastore):
starttime = iso8601.parse_date("1970")
endtime = starttime + timedelta(hours=1)

example_query = """
example_query = r"""
events = query_bucket("{bid}");
events = sort_by_timestamp(events);
events = categorize(events, [[["test"], {{"regex": "test"}}], [["test", "subtest"], {{"regex": "test2"}}]]);
events = categorize(events, [[["test"], {{"regex": "test"}}], [["test", "subtest"], {{"regex": "test\w"}}]]);
events_by_cat = merge_events_by_keys(events, ["$category"]);
RETURN = {{"events": events, "events_by_cat": events_by_cat}};
""".format(
bid=bid, bid_escaped=bid.replace("'", "\\'")
bid=bid
)
try:
bucket = datastore.create_bucket(
bucket_id=bid, type="test", client="test", hostname="test", name="asd"
)
events = [
Event(
data={"label": "test1"},
data={"label": "test"},
timestamp=starttime,
duration=timedelta(seconds=1),
),
Event(
data={"label": "test2"},
data={"label": "testwithmoredetail"},
timestamp=starttime + timedelta(seconds=1),
duration=timedelta(seconds=1),
),
Event(
data={"label": "test2"},
data={"label": "testwithmoredetail"},
timestamp=starttime + timedelta(seconds=2),
duration=timedelta(seconds=1),
),
Expand All @@ -550,9 +550,11 @@ def test_query2_query_categorize(datastore):
result = query(qname, example_query, starttime, endtime, datastore)
print(result)
assert len(result["events"]) == 3
assert result["events"][0].data["label"] == "test1"
assert result["events"][0].data["label"] == "test"
assert result["events"][0].data["$category"] == ["test"]
assert result["events"][1].data["$category"] == ["test", "subtest"]

assert len(result["events_by_cat"]) == 2
assert result["events_by_cat"][0].data["$category"] == ["test"]
assert result["events_by_cat"][1].data["$category"] == ["test", "subtest"]
assert result["events_by_cat"][1].duration == timedelta(seconds=2)
Expand Down

0 comments on commit e83f3f8

Please sign in to comment.