-
Notifications
You must be signed in to change notification settings - Fork 218
[WIP] Use itertools.cycle to iterate over random queries from the query file
#768
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
fressi-elastic
wants to merge
7
commits into
elastic:master
from
fressi-elastic:cycle-wikipedia-queries
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ec90503
Use `itertools.cycle` to iterate over random queries from the query f…
fressi-elastic 6d94f28
Use default random seed when none is provided to enforce track reprod…
fressi-elastic 7bc4198
Assume default seed is used in all test cases.
fressi-elastic 2035b40
Fix test cases: remove seed parameter when preparing the `want` seque…
fressi-elastic 0468f04
Merge remote-tracking branch 'upstream/master' into cycle-wikipedia-q…
fressi-elastic f7e083b
Fix test case to match the removal of caching.
fressi-elastic 5a0e92a
Update wikipedia/track.py
fressi-elastic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| import dataclasses | ||
|
|
||
| from wikipedia import track | ||
|
|
||
|
|
||
| def test_query_samples(): | ||
| queries = track.query_samples(100) | ||
| assert len(queries) == 100 | ||
|
|
||
|
|
||
| def test_RandomQueriesParamSource_query(): | ||
| """It tests DummyRandomQueriesParamSource.query() will return the same random sequence twice by calling N*2 times query method.""" | ||
| want = track.query_samples(3) * 2 | ||
|
|
||
| source = DummyRandomQueriesParamSource(track=None, params={"batch_size": 3}) | ||
| got = [source.query() for _ in want] | ||
| assert got == want | ||
|
|
||
|
|
||
| def test_SearchApplicationSearchParamSource_params(): | ||
| """It tests SearchApplicationSearchParamSource.params().""" | ||
|
|
||
| want = [ | ||
| { | ||
| "body": {"params": {"query_string": query}}, | ||
| "method": "POST", | ||
| "path": "/_application/search_application/dummy-search-application/_search", | ||
| } | ||
| for query in track.query_samples(2) | ||
| ] * 2 # It will iterate this twice. | ||
|
|
||
| source = track.SearchApplicationSearchParamSource(DummyTrack(), params={"batch_size": 2}) | ||
| got = [source.params() for _ in want] | ||
| assert got == want | ||
|
|
||
|
|
||
| def test_QueryRulesSearchParamSource_params(): | ||
| want = [ | ||
| { | ||
| "body": { | ||
| "query": { | ||
| "rule": { | ||
| "match_criteria": {"rule_key": AnyOf(["match", "no-match"])}, | ||
| "organic": {"query_string": {"default_field": ["<search-field>"], "query": query}}, | ||
| "ruleset_ids": [None], | ||
| } | ||
| }, | ||
| "size": 10, | ||
| }, | ||
| "method": "POST", | ||
| "path": "/_search", | ||
| } | ||
| for query in track.query_samples(2) | ||
| ] * 2 # It will iterate this twice. | ||
|
|
||
| source = track.QueryRulesSearchParamSource( | ||
| track=DummyTrack(), params={"batch_size": 2, "search-fields": ["<search-field>"], "size": 10} | ||
| ) | ||
| got = [source.params() for _ in want] | ||
| assert want == got | ||
|
|
||
|
|
||
| def test_PinnedSearchParamSource_params(): | ||
| ids = track.ids_samples() | ||
| want = [ | ||
| { | ||
| "body": { | ||
| "query": { | ||
| "pinned": {"ids": [AnyOf(ids)], "organic": {"query_string": {"default_field": ["<search-field>"], "query": query}}} | ||
| }, | ||
| "size": 10, | ||
| }, | ||
| "method": "POST", | ||
| "path": "/_search", | ||
| } | ||
| for query in track.query_samples(2) | ||
| ] * 2 # It will iterate this twice. | ||
|
|
||
| source = track.PinnedSearchParamSource(track=DummyTrack(), params={"batch_size": 2, "search-fields": ["<search-field>"], "size": 10}) | ||
| got = [source.params() for _ in want] | ||
| assert got == want | ||
|
|
||
|
|
||
| def test_RetrieverParamSource_params(): | ||
| want = [ | ||
| { | ||
| "body": { | ||
| "retriever": {"standard": {"query": {"query_string": {"default_field": ["<search-field>"], "query": query}}}}, | ||
| "size": 10, | ||
| }, | ||
| "method": "POST", | ||
| "path": "/dummy/_search", | ||
| } | ||
| for query in track.query_samples(2) | ||
| ] * 2 # It will iterate this twice. | ||
|
|
||
| source = track.RetrieverParamSource(track=DummyTrack(), params={"batch_size": 2, "search-fields": ["<search-field>"], "size": 10}) | ||
| got = [source.params() for _ in want] | ||
| assert got == want | ||
|
|
||
|
|
||
| def test_QueryParamSource_params(): | ||
| want = [ | ||
| { | ||
| "body": {"query": {"query_string": {"default_field": ["<search-fields>"], "query": query}}, "size": 2}, | ||
| "cache": False, | ||
| "index": "dummy", | ||
| } | ||
| for query in track.query_samples(2) | ||
| ] * 2 # It will iterate this twice. | ||
|
|
||
| source = track.QueryParamSource( | ||
| track=DummyTrack(), | ||
| params={"batch_size": 2, "query-type": "query-string", "search-fields": ["<search-fields>"], "size": 2}, | ||
| ) | ||
| got = [source.params() for _ in want] | ||
| assert got == want | ||
|
|
||
|
|
||
| @dataclasses.dataclass() | ||
| class DummyIndex: | ||
| name: str = "dummy" | ||
|
|
||
|
|
||
| @dataclasses.dataclass() | ||
| class DummyTrack: | ||
| indices: tuple[DummyIndex, ...] = (DummyIndex(),) | ||
|
|
||
| def index_names(self) -> list[str]: | ||
| return [i.name for i in self.indices] | ||
|
|
||
|
|
||
| class DummyRandomQueriesParamSource(track.RandomQueriesParamSource): | ||
| # Dummy implementation of abstract method. | ||
| def params(self): | ||
| return {"query": self.query()} | ||
|
|
||
|
|
||
| class AnyOf(list): | ||
| def __eq__(self, other) -> bool: | ||
| return other in self | ||
|
|
||
| def __repr__(self) -> str: | ||
| return f"AnyOf([{self[0]}, ...])" | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.