cover a bit more TUI in tests, and remove dead branches
Signed-off-by: Brian S. Stephan <bss@incorporeal.org>
This commit is contained in:
parent
e35d8dbf3d
commit
2a40c70b56
@ -54,9 +54,7 @@ class EditScreen(ModalScreen):
|
|||||||
self.input_field = Input(value=repr(self.field_value), validators=[Number()], id='field-input')
|
self.input_field = Input(value=repr(self.field_value), validators=[Number()], id='field-input')
|
||||||
elif self.field_descriptor.type == descriptor.FieldDescriptor.TYPE_STRING:
|
elif self.field_descriptor.type == descriptor.FieldDescriptor.TYPE_STRING:
|
||||||
self.input_field = Input(value=self.field_value, id='field-input')
|
self.input_field = Input(value=self.field_value, id='field-input')
|
||||||
else:
|
|
||||||
# we don't handle whatever these are yet
|
|
||||||
self.input_field = Label(repr(self.field_value), id='field-input')
|
|
||||||
yield Grid(
|
yield Grid(
|
||||||
Container(Label(self.field_descriptor.full_name, id='field-name'), id='field-name-container'),
|
Container(Label(self.field_descriptor.full_name, id='field-name'), id='field-name-container'),
|
||||||
Container(self.input_field, id='input-field-container'),
|
Container(self.input_field, id='input-field-container'),
|
||||||
@ -91,17 +89,16 @@ class EditScreen(ModalScreen):
|
|||||||
|
|
||||||
def _save(self):
|
def _save(self):
|
||||||
"""Save the field value to the retained config item."""
|
"""Save the field value to the retained config item."""
|
||||||
if not isinstance(self.input_field, Label):
|
if self.field_descriptor.type in (descriptor.FieldDescriptor.TYPE_INT32,
|
||||||
if self.field_descriptor.type in (descriptor.FieldDescriptor.TYPE_INT32,
|
descriptor.FieldDescriptor.TYPE_INT64,
|
||||||
descriptor.FieldDescriptor.TYPE_INT64,
|
descriptor.FieldDescriptor.TYPE_UINT32,
|
||||||
descriptor.FieldDescriptor.TYPE_UINT32,
|
descriptor.FieldDescriptor.TYPE_UINT64):
|
||||||
descriptor.FieldDescriptor.TYPE_UINT64):
|
field_value = int(self.input_field.value)
|
||||||
field_value = int(self.input_field.value)
|
else:
|
||||||
else:
|
field_value = self.input_field.value
|
||||||
field_value = self.input_field.value
|
setattr(self.parent_config, self.field_descriptor.name, field_value)
|
||||||
setattr(self.parent_config, self.field_descriptor.name, field_value)
|
logger.debug("parent config post-change: %s", self.parent_config)
|
||||||
logger.debug("parent config post-change: %s", self.parent_config)
|
self.node.set_label(pb_field_to_node_label(self.field_descriptor, field_value))
|
||||||
self.node.set_label(pb_field_to_node_label(self.field_descriptor, field_value))
|
|
||||||
|
|
||||||
|
|
||||||
class MessageScreen(ModalScreen):
|
class MessageScreen(ModalScreen):
|
||||||
|
@ -125,6 +125,41 @@ async def test_simple_edit_via_input_field():
|
|||||||
assert pilot.app.config.displayOptions.deprecatedI2cSpeed == 5
|
assert pilot.app.config.displayOptions.deprecatedI2cSpeed == 5
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
@with_pb2s
|
||||||
|
async def test_cancel_simple_edit_via_input_field():
|
||||||
|
"""Test that we can cancel out of saving an int via UI and see it reflected in the config."""
|
||||||
|
app = ConfigEditor(config_filename=os.path.join(HERE, 'test-files/test-config.bin'))
|
||||||
|
async with app.run_test() as pilot:
|
||||||
|
tree = pilot.app.query_one(Tree)
|
||||||
|
display_node = tree.root.children[5]
|
||||||
|
i2cspeed_node = display_node.children[4]
|
||||||
|
assert pilot.app.config.displayOptions.deprecatedI2cSpeed == 400000
|
||||||
|
|
||||||
|
tree.root.expand_all()
|
||||||
|
await pilot.wait_for_scheduled_animations()
|
||||||
|
tree.select_node(i2cspeed_node)
|
||||||
|
tree.action_select_cursor()
|
||||||
|
await pilot.wait_for_scheduled_animations()
|
||||||
|
await pilot.click('Input#field-input')
|
||||||
|
await pilot.wait_for_scheduled_animations()
|
||||||
|
await pilot.press('backspace', 'backspace', 'backspace', 'backspace', 'backspace', 'backspace', '5')
|
||||||
|
await pilot.wait_for_scheduled_animations()
|
||||||
|
await pilot.click('Button#cancel-button')
|
||||||
|
assert pilot.app.config.displayOptions.deprecatedI2cSpeed == 400000
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
@with_pb2s
|
||||||
|
async def test_about():
|
||||||
|
"""Test that we can bring up the about box."""
|
||||||
|
app = ConfigEditor(config_filename=os.path.join(HERE, 'test-files/test-config.bin'))
|
||||||
|
async with app.run_test() as pilot:
|
||||||
|
await pilot.press('?')
|
||||||
|
await pilot.wait_for_scheduled_animations()
|
||||||
|
await pilot.click('Button#ok-button')
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
@with_pb2s
|
@with_pb2s
|
||||||
async def test_simple_edit_via_input_field_enum():
|
async def test_simple_edit_via_input_field_enum():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user