当前位置: 首页>>代码示例>>Python>>正文


Python value.Value类代码示例

本文整理汇总了Python中ntcore.value.Value的典型用法代码示例。如果您正苦于以下问题:Python Value类的具体用法?Python Value怎么用?Python Value使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Value类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_EntryNewRemote

def test_EntryNewRemote(nt_live, server_cb):
    nt_server, nt_client = nt_live
    nt_server_api = nt_server._api
    nt_client_api = nt_client._api

    nt_server_api.addEntryListenerById(
        nt_server_api.getEntryId("/foo"), server_cb, NT_NOTIFY_NEW
    )

    # Trigger an event
    nt_client_api.setEntryValueById(
        nt_client_api.getEntryId("/foo/bar"), Value.makeDouble(2.0)
    )
    nt_client_api.setEntryValueById(
        nt_client_api.getEntryId("/foo"), Value.makeDouble(1.0)
    )

    nt_client_api.flush()

    assert nt_server_api.waitForEntryListenerQueue(1.0)

    # Check the event
    events = server_cb.wait(1)

    # assert events[0].listener == handle
    assert events[0].local_id == nt_server_api.getEntryId("/foo")
    assert events[0].name == "/foo"
    assert events[0].value == Value.makeDouble(1.0)
    assert events[0].flags == NT_NOTIFY_NEW
开发者ID:robotpy,项目名称:pynetworktables,代码行数:29,代码来源:test_entry_listener.py

示例2: getGlobalAutoUpdateValue

    def getGlobalAutoUpdateValue(cls, key, defaultValue, writeDefault):
        """Global version of getAutoUpdateValue. This function will not initialize
        NetworkTables.
        
        :param key: the full NT path of the value (must start with /)
        :type key: str
        :param defaultValue: The default value to return if the key doesn't exist
        :type defaultValue: any
        :param writeDefault: If True, force the value to the specified default
        :type writeDefault: bool
        
        .. versionadded:: 2015.3.0
        
        .. seealso:: :func:`.ntproperty` is a read-write alternative to this
        """
        assert key.startswith("/")

        # Use raw NT api to avoid having to initialize networktables
        value = None
        valuefn = None  # optimization for ntproperty

        if not writeDefault:
            value = cls._api.getEntryValue(key)

        if value is None:
            valuefn = Value.getFactory(defaultValue)
            cls._api.setEntryValue(key, valuefn(defaultValue))
            value = defaultValue
        else:
            valuefn = Value.getFactory(value)

        return cls._api.createAutoValue(key, AutoUpdateValue(key, value, valuefn))
开发者ID:robotpy,项目名称:pynetworktables,代码行数:32,代码来源:networktables.py

示例3: test_Raw

def test_Raw():
    v = Value.makeRaw(b"hello")
    assert NT_RAW == v.type
    assert b"hello" == v.value

    v = Value.makeRaw(b"goodbye")
    assert NT_RAW == v.type
    assert b"goodbye" == v.value
开发者ID:robotpy,项目名称:pynetworktables,代码行数:8,代码来源:test_value.py

示例4: test_String

def test_String():
    v = Value.makeString("hello")
    assert NT_STRING == v.type
    assert "hello" == v.value

    v = Value.makeString("goodbye")
    assert NT_STRING == v.type
    assert "goodbye" == v.value
开发者ID:robotpy,项目名称:pynetworktables,代码行数:8,代码来源:test_value.py

示例5: test_Double

def test_Double():
    v = Value.makeDouble(0.5)
    assert NT_DOUBLE == v.type
    assert 0.5 == v.value

    v = Value.makeDouble(0.25)
    assert NT_DOUBLE == v.type
    assert 0.25 == v.value
开发者ID:robotpy,项目名称:pynetworktables,代码行数:8,代码来源:test_value.py

示例6: test_Boolean

def test_Boolean():
    v = Value.makeBoolean(False)
    assert NT_BOOLEAN == v.type
    assert not v.value

    v = Value.makeBoolean(True)
    assert NT_BOOLEAN == v.type
    assert v.value
开发者ID:robotpy,项目名称:pynetworktables,代码行数:8,代码来源:test_value.py

示例7: test_DoubleArrayComparison

def test_DoubleArrayComparison():
    v1 = Value.makeDoubleArray([0.5, 0.25, 0.5])
    v2 = Value.makeDoubleArray((0.5, 0.25, 0.5))
    assert v1 == v2

    # different contents
    v2 = Value.makeDoubleArray([0.5, 0.5, 0.5])
    assert v1 != v2

    # different size
    v2 = Value.makeDoubleArray([0.5, 0.25])
    assert v1 != v2
开发者ID:robotpy,项目名称:pynetworktables,代码行数:12,代码来源:test_value.py

示例8: test_BooleanArrayComparison

def test_BooleanArrayComparison():
    v1 = Value.makeBooleanArray([1, 0, 1])
    v2 = Value.makeBooleanArray((1, 0, 1))
    assert v1 == v2

    # different contents
    v2 = Value.makeBooleanArray([1, 1, 1])
    assert v1 != v2

    # different size
    v2 = Value.makeBooleanArray([True, False])
    assert v1 != v2
开发者ID:robotpy,项目名称:pynetworktables,代码行数:12,代码来源:test_value.py

示例9: test_ProcessIncomingEntryAssignWithFlags

def test_ProcessIncomingEntryAssignWithFlags(
    storage_populate_one, dispatcher, entry_notifier, is_server, conn
):
    storage = storage_populate_one
    value = Value.makeDouble(1.0)

    storage.processIncoming(Message.entryAssign("foo", 0, 1, value, 0x2), conn)

    # EXPECT_CALL(*conn, proto_rev()).WillRepeatedly(Return(0x0300u))
    if is_server:
        # server broadcasts new value/flags to all *other* connections
        dispatcher._queueOutgoing.assert_has_calls(
            [call(Message.entryAssign("foo", 0, 1, value, 0x2), None, conn)]
        )

        entry_notifier.notifyEntry.assert_has_calls(
            [call(0, "foo", value, NT_NOTIFY_UPDATE | NT_NOTIFY_FLAGS)]
        )

    else:
        # client forces flags back when an assign message is received for an
        # existing entry with different flags
        dispatcher._queueOutgoing.assert_has_calls(
            [call(Message.flagsUpdate(0, 0), None, None)]
        )

        entry_notifier.notifyEntry.assert_has_calls(
            [call(0, "foo", value, NT_NOTIFY_UPDATE)]
        )
开发者ID:robotpy,项目名称:pynetworktables,代码行数:29,代码来源:test_storage.py

示例10: generateNotifications

def generateNotifications(notifier):
    # All flags combos that can be generated by Storage
    flags = [
        # "normal" notifications
        NT_NOTIFY_NEW,
        NT_NOTIFY_DELETE,
        NT_NOTIFY_UPDATE,
        NT_NOTIFY_FLAGS,
        NT_NOTIFY_UPDATE | NT_NOTIFY_FLAGS,
        # immediate notifications are always "new"
        NT_NOTIFY_IMMEDIATE | NT_NOTIFY_NEW,
        # local notifications can be of any flag combo
        NT_NOTIFY_LOCAL | NT_NOTIFY_NEW,
        NT_NOTIFY_LOCAL | NT_NOTIFY_DELETE,
        NT_NOTIFY_LOCAL | NT_NOTIFY_UPDATE,
        NT_NOTIFY_LOCAL | NT_NOTIFY_FLAGS,
        NT_NOTIFY_LOCAL | NT_NOTIFY_UPDATE | NT_NOTIFY_FLAGS,
    ]

    # Generate across keys
    keys = ["/foo/bar", "/baz", "/boo"]

    val = Value.makeDouble(1)

    # Provide unique key indexes for each key
    keyindex = 5
    for key in keys:
        for flag in flags:
            notifier.notifyEntry(keyindex, key, val, flag)

        keyindex += 1
开发者ID:robotpy,项目名称:pynetworktables,代码行数:31,代码来源:test_entry_notifier.py

示例11: test_LoadPersistentAssign

def test_LoadPersistentAssign(storage_empty, dispatcher, entry_notifier, is_server):
    storage = storage_empty

    fp = StringIO('[NetworkTables Storage 3.0]\nboolean "foo"=true\n')
    assert storage.loadPersistent(fp=fp) is None

    entry = storage.m_entries.get("foo")
    assert Value.makeBoolean(True) == entry.value
    assert NT_PERSISTENT == entry.flags
    assert entry.isPersistent

    dispatcher._queueOutgoing.assert_has_calls(
        [
            call(
                Message.entryAssign(
                    "foo", 0 if is_server else 0xFFFF, 1, entry.value, NT_PERSISTENT
                ),
                None,
                None,
            )
        ]
    )

    entry_notifier.notifyEntry.assert_has_calls(
        [call(0, "foo", entry.value, NT_NOTIFY_NEW | NT_NOTIFY_LOCAL)]
    )
开发者ID:robotpy,项目名称:pynetworktables,代码行数:26,代码来源:test_storage.py

示例12: test_DeleteEntryExist

def test_DeleteEntryExist(storage_populated, dispatcher, entry_notifier, is_server):
    storage = storage_populated

    storage.deleteEntry("foo2")

    entry = storage.m_entries.get("foo2")
    assert entry is not None
    assert entry.value is None
    assert entry.id == 0xFFFF
    assert entry.local_write == False

    # client shouldn't send an update as id not assigned yet
    if is_server:
        # id assigned as this is the server
        dispatcher._queueOutgoing.assert_has_calls(
            [call(Message.entryDelete(1), None, None)]
        )
    else:
        # shouldn't send an update id not assigned yet
        assert dispatcher._queueOutgoing.call_count == 0

    entry_notifier.notifyEntry.assert_has_calls(
        [call(1, "foo2", Value.makeDouble(0.0), NT_NOTIFY_DELETE | NT_NOTIFY_LOCAL)]
    )

    if is_server:
        assert len(storage.m_idmap) >= 2
        assert not storage.m_idmap[1]
开发者ID:robotpy,项目名称:pynetworktables,代码行数:28,代码来源:test_storage.py

示例13: test_SetEntryValueDifferentValue

def test_SetEntryValueDifferentValue(
    storage_populated, is_server, dispatcher, entry_notifier
):
    storage = storage_populated

    # update with same type and different value results in value update message
    value = Value.makeDouble(1.0)
    assert storage.setEntryValue("foo2", value)
    entry = storage.m_entries.get("foo2")
    assert value == entry.value

    # client shouldn't send an update as id not assigned yet
    if is_server:
        # id assigned if server; seq_num incremented
        dispatcher._queueOutgoing.assert_has_calls(
            [call(Message.entryUpdate(1, 2, value), None, None)]
        )
    else:
        assert dispatcher._queueOutgoing.call_count == 0

    entry_notifier.notifyEntry.assert_has_calls(
        [call(1, "foo2", value, NT_NOTIFY_UPDATE | NT_NOTIFY_LOCAL)]
    )

    if not is_server:
        assert 2 == storage.m_entries.get("foo2").seq_num  # still should be incremented
开发者ID:robotpy,项目名称:pynetworktables,代码行数:26,代码来源:test_storage.py

示例14: test_StringArrayComparison

def test_StringArrayComparison():
    v1 = Value.makeStringArray(["hello", "goodbye", "string"])
    v2 = Value.makeStringArray(("hello", "goodbye", "string"))
    assert v1 == v2

    # different contents
    v2 = Value.makeStringArray(["hello", "goodby2", "string"])
    assert v1 != v2

    # different sized contents
    v2 = Value.makeStringArray(["hello", "goodbye2", "string"])
    assert v1 != v2

    # different size
    v2 = Value.makeStringArray(["hello", "goodbye"])
    assert v1 != v2
开发者ID:robotpy,项目名称:pynetworktables,代码行数:16,代码来源:test_value.py

示例15: storage_populated

def storage_populated(storage_empty, dispatcher, entry_notifier):
    storage = storage_empty

    entry_notifier.m_local_notifiers = False

    entry_notifier.m_local_notifiers = False
    storage.setEntryTypeValue("foo", Value.makeBoolean(True))
    storage.setEntryTypeValue("foo2", Value.makeDouble(0.0))
    storage.setEntryTypeValue("bar", Value.makeDouble(1.0))
    storage.setEntryTypeValue("bar2", Value.makeBoolean(False))

    dispatcher.reset_mock()
    entry_notifier.reset_mock()
    entry_notifier.m_local_notifiers = True

    return storage
开发者ID:robotpy,项目名称:pynetworktables,代码行数:16,代码来源:test_storage.py


注:本文中的ntcore.value.Value类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。