-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix support for dialogs without response (#78)
* Add test_parser.py * Fix parser * Add type: ignore comments. Fixing types ends up being a much larger effort than suitable for this PR.
- Loading branch information
1 parent
6fb7d9d
commit d06bc89
Showing
2 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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,57 @@ | ||
# -*- coding: utf-8 -*- | ||
from typing import Dict, Tuple | ||
|
||
import pytest | ||
|
||
from pyvisa_sim import parser | ||
from pyvisa_sim.component import NoResponse, OptionalStr | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"dialogue_dict, want", | ||
[ | ||
({"q": "foo", "r": "bar"}, ("foo", "bar")), | ||
({"q": "foo ", "r": " bar"}, ("foo", "bar")), | ||
({"q": " foo", "r": "bar "}, ("foo", "bar")), | ||
({"q": " foo ", "r": " bar "}, ("foo", "bar")), | ||
# Make sure to support queries that don't have responses | ||
({"q": "foo"}, ("foo", NoResponse)), | ||
# Ignore other keys | ||
({"q": "foo", "bar": "bar"}, ("foo", NoResponse)), | ||
], | ||
) | ||
def test_get_pair(dialogue_dict: Dict[str, str], want: Tuple[str, OptionalStr]) -> None: | ||
got = parser._get_pair(dialogue_dict) | ||
assert got == want | ||
|
||
|
||
def test_get_pair_requires_query_key() -> None: | ||
with pytest.raises(KeyError): | ||
parser._get_pair({"r": "bar"}) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"dialogue_dict, want", | ||
[ | ||
({"q": "foo", "r": "bar", "e": "baz"}, ("foo", "bar", "baz")), | ||
({"q": "foo ", "r": " bar", "e": " baz "}, ("foo", "bar", "baz")), | ||
({"q": " foo", "r": "bar ", "e": "baz "}, ("foo", "bar", "baz")), | ||
({"q": " foo ", "r": " bar ", "e": " baz"}, ("foo", "bar", "baz")), | ||
# Make sure to support queries that don't have responses | ||
({"q": "foo"}, ("foo", NoResponse, NoResponse)), | ||
({"q": "foo", "r": "bar"}, ("foo", "bar", NoResponse)), | ||
({"q": "foo", "e": "bar"}, ("foo", NoResponse, "bar")), | ||
# Ignore other keys | ||
({"q": "foo", "bar": "bar"}, ("foo", NoResponse, NoResponse)), | ||
], | ||
) | ||
def test_get_triplet( | ||
dialogue_dict: Dict[str, str], want: Tuple[str, OptionalStr, OptionalStr] | ||
) -> None: | ||
got = parser._get_triplet(dialogue_dict) | ||
assert got == want | ||
|
||
|
||
def test_get_triplet_requires_query_key() -> None: | ||
with pytest.raises(KeyError): | ||
parser._get_triplet({"r": "bar"}) |