MCPcopy Create free account
hub / github.com/python-cmd2/cmd2 / test_commandset_settables

Function test_commandset_settables

tests/test_commandset.py:1022–1196  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1020
1021
1022def test_commandset_settables() -> None:
1023 # Define an arbitrary class with some attribute
1024 class Arbitrary:
1025 def __init__(self) -> None:
1026 self.some_value = 5
1027
1028 # Declare a CommandSet with a settable of some arbitrary property
1029 class WithSettablesA(CommandSetBase):
1030 def __init__(self) -> None:
1031 super().__init__()
1032
1033 self._arbitrary = Arbitrary()
1034 self._settable_prefix = "addon"
1035 self.my_int = 11
1036
1037 self.add_settable(
1038 Settable(
1039 "arbitrary_value",
1040 int,
1041 "Some settable value",
1042 settable_object=self._arbitrary,
1043 settable_attrib_name="some_value",
1044 )
1045 )
1046
1047 # Declare a CommandSet with an empty settable prefix
1048 class WithSettablesNoPrefix(CommandSetBase):
1049 def __init__(self) -> None:
1050 super().__init__()
1051
1052 self._arbitrary = Arbitrary()
1053 self._settable_prefix = ""
1054 self.my_int = 11
1055
1056 self.add_settable(
1057 Settable(
1058 "another_value",
1059 float,
1060 "Some settable value",
1061 settable_object=self._arbitrary,
1062 settable_attrib_name="some_value",
1063 )
1064 )
1065
1066 # Declare a commandset with duplicate settable name
1067 class WithSettablesB(CommandSetBase):
1068 def __init__(self) -> None:
1069 super().__init__()
1070
1071 self._arbitrary = Arbitrary()
1072 self._settable_prefix = "some"
1073 self.my_int = 11
1074
1075 self.add_settable(
1076 Settable(
1077 "arbitrary_value",
1078 int,
1079 "Some settable value",

Callers

nothing calls this directly

Calls 11

add_settableMethod · 0.95
register_command_setMethod · 0.95
SettableClass · 0.90
WithSettablesAClass · 0.85
ArbitraryClass · 0.85
run_cmdFunction · 0.85
normalizeFunction · 0.85
WithSettablesBClass · 0.85
remove_settableMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…