-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from robotpy/fix-sendable-chooser-gil
Switch SendableChooser to rpy::gilsafe_object
- Loading branch information
Showing
16 changed files
with
108 additions
and
18 deletions.
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
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
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
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
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
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,23 @@ | ||
import logging | ||
|
||
import pytest | ||
import ntcore | ||
import wpilib | ||
|
||
|
||
@pytest.fixture | ||
def cfg_logging(caplog): | ||
caplog.set_level(logging.INFO) | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def nt(cfg_logging): | ||
instance = ntcore.NetworkTableInstance.getDefault() | ||
instance.startLocal() | ||
|
||
try: | ||
yield instance | ||
finally: | ||
instance.stopLocal() | ||
instance._reset() | ||
wpilib._wpilib._clearSmartDashboardData() |
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,55 @@ | ||
import pytest | ||
|
||
from ntcore import NetworkTableInstance | ||
from wpilib import SendableChooser, SmartDashboard | ||
|
||
|
||
@pytest.fixture | ||
def chooser() -> SendableChooser: | ||
chooser = SendableChooser() | ||
for i in range(1, 4): | ||
chooser.addOption(str(i), i) | ||
return chooser | ||
|
||
|
||
@pytest.mark.parametrize("value", [0, 1, 2, 3]) | ||
def test_returns_selected( | ||
nt: NetworkTableInstance, chooser: SendableChooser, value: int | ||
): | ||
chooser.setDefaultOption("0", 0) | ||
|
||
with nt.getStringTopic( | ||
"/SmartDashboard/ReturnsSelectedChooser/selected" | ||
).publish() as pub: | ||
SmartDashboard.putData("ReturnsSelectedChooser", chooser) | ||
SmartDashboard.updateValues() | ||
print("set", value) | ||
pub.set(str(value)) | ||
SmartDashboard.updateValues() | ||
print("get", chooser.getSelected()) | ||
assert value == chooser.getSelected() | ||
|
||
|
||
def test_default_is_returned_on_no_select(chooser: SendableChooser): | ||
chooser.setDefaultOption("4", 4) | ||
assert 4 == chooser.getSelected() | ||
|
||
|
||
def test_default_constructable_is_returned_on_no_select_and_no_default( | ||
chooser: SendableChooser, | ||
): | ||
assert chooser.getSelected() is None | ||
|
||
|
||
def test_change_listener(nt: NetworkTableInstance, chooser: SendableChooser): | ||
current_val = [0] | ||
|
||
def on_change(val): | ||
current_val[0] = val | ||
|
||
chooser.onChange(on_change) | ||
SmartDashboard.putData("ChangeListenerChooser", chooser) | ||
SmartDashboard.updateValues() | ||
SmartDashboard.putString("ChangeListenerChooser/selected", "3") | ||
SmartDashboard.updateValues() | ||
assert 3 == current_val[0] |
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
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