Exemplo n.º 1
0
def test_LoadPersistentAssign(storage_empty, outgoing, 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 1 == len(outgoing)
    assert not outgoing[0].only
    assert not outgoing[0].conn
    msg = outgoing[0].msg
    assert kEntryAssign == msg.type
    assert "foo" == msg.str
    if is_server:
        assert 0 == msg.id    # assigned as server

    else:
        assert 0xffff == msg.id    # not assigned as client

    assert 1 == msg.seq_num_uid
    assert Value.makeBoolean(True) == msg.value
    assert NT_PERSISTENT == msg.flags
Exemplo n.º 2
0
def storage_persistent(storage_empty, outgoing):
    storage = storage_empty
    
    storage.setEntryTypeValue("boolean/True", Value.makeBoolean(True))
    storage.setEntryTypeValue("boolean/False", Value.makeBoolean(False))
    storage.setEntryTypeValue("double/neg", Value.makeDouble(-1.5))
    storage.setEntryTypeValue("double/zero", Value.makeDouble(0.0))
    storage.setEntryTypeValue("double/big", Value.makeDouble(1.3e8))
    storage.setEntryTypeValue("string/empty", Value.makeString(""))
    storage.setEntryTypeValue("string/normal", Value.makeString("hello"))
    storage.setEntryTypeValue("string/special", Value.makeString("\0\3\5\n"))
    storage.setEntryTypeValue("raw/empty", Value.makeRaw(b""))
    storage.setEntryTypeValue("raw/normal", Value.makeRaw(b"hello"))
    storage.setEntryTypeValue("raw/special", Value.makeRaw(b"\0\3\5\n"))
    storage.setEntryTypeValue("booleanarr/empty", Value.makeBooleanArray([]))
    storage.setEntryTypeValue("booleanarr/one", Value.makeBooleanArray([True]))
    storage.setEntryTypeValue("booleanarr/two", Value.makeBooleanArray([True, False]))
    storage.setEntryTypeValue("doublearr/empty", Value.makeDoubleArray([]))
    storage.setEntryTypeValue("doublearr/one", Value.makeDoubleArray([0.5]))
    storage.setEntryTypeValue("doublearr/two", Value.makeDoubleArray([0.5, -0.25]))
    storage.setEntryTypeValue("stringarr/empty", Value.makeStringArray([]))
    storage.setEntryTypeValue("stringarr/one", Value.makeStringArray(["hello"]))
    storage.setEntryTypeValue("stringarr/two", Value.makeStringArray(["hello", "world\n"]))
    storage.setEntryTypeValue("\0\3\5\n",Value.makeBoolean(True))
    del outgoing[:]
    
    return storage
Exemplo n.º 3
0
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
Exemplo n.º 4
0
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
Exemplo n.º 5
0
def storage_populated(storage_empty, outgoing):
    storage = storage_empty
    
    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))
    del outgoing[:]

    return storage
Exemplo n.º 6
0
def test_loadPersistent(storage_empty, outgoing):
    storage = storage_empty
    
    inp = "[NetworkTables Storage 3.0]\n"
    inp += "boolean \"\\x00\\x03\\x05\\n\"=true\n"
    inp += "boolean \"boolean/false\"=false\n"
    inp += "boolean \"boolean/true\"=true\n"
    inp += "array boolean \"booleanarr/empty\"=\n"
    inp += "array boolean \"booleanarr/one\"=true\n"
    inp += "array boolean \"booleanarr/two\"=true,false\n"
    inp += "double \"double/big\"=1.3e+08\n"
    inp += "double \"double/neg\"=-1.5\n"
    inp += "double \"double/zero\"=0\n"
    inp += "array double \"doublearr/empty\"=\n"
    inp += "array double \"doublearr/one\"=0.5\n"
    inp += "array double \"doublearr/two\"=0.5,-0.25\n"
    inp += "raw \"raw/empty\"=\n"
    inp += "raw \"raw/normal\"=aGVsbG8=\n"
    inp += "raw \"raw/special\"=AAMFCg==\n"
    inp += "string \"string/empty\"=\"\"\n"
    inp += "string \"string/normal\"=\"hello\"\n"
    inp += "string \"string/special\"=\"\\x00\\x03\\x05\\n\"\n"
    inp += "array string \"stringarr/empty\"=\n"
    inp += "array string \"stringarr/one\"=\"hello\"\n"
    inp += "array string \"stringarr/two\"=\"hello\",\"world\\n\"\n"

    fp = StringIO(inp)
    assert storage.loadPersistent(fp=fp) is None
    
    assert 21 == len(storage.m_entries)
    assert 21 == len(outgoing)

    assert Value.makeBoolean(True) == storage.getEntryValue("boolean/true")
    assert Value.makeBoolean(False) == storage.getEntryValue("boolean/false")
    assert Value.makeDouble(-1.5) == storage.getEntryValue("double/neg")
    assert Value.makeDouble(0.0) == storage.getEntryValue("double/zero")
    assert Value.makeDouble(1.3e8) == storage.getEntryValue("double/big")
    assert Value.makeString("") == storage.getEntryValue("string/empty")
    assert Value.makeString("hello") == storage.getEntryValue("string/normal")
    assert Value.makeString("\0\3\5\n") == storage.getEntryValue("string/special")
    assert Value.makeRaw(b"") == storage.getEntryValue("raw/empty")
    assert Value.makeRaw(b"hello") == storage.getEntryValue("raw/normal")
    assert Value.makeRaw(b"\0\3\5\n") == storage.getEntryValue("raw/special")
    assert Value.makeBooleanArray([]) == storage.getEntryValue("booleanarr/empty")
    assert Value.makeBooleanArray([True]) == storage.getEntryValue("booleanarr/one")
    assert Value.makeBooleanArray([True, False]) == storage.getEntryValue("booleanarr/two")
    assert Value.makeDoubleArray([]) == storage.getEntryValue("doublearr/empty")
    assert Value.makeDoubleArray([0.5]) == storage.getEntryValue("doublearr/one")
    assert Value.makeDoubleArray([0.5, -0.25]) == storage.getEntryValue("doublearr/two")
    assert Value.makeStringArray([]) == storage.getEntryValue("stringarr/empty")
    assert Value.makeStringArray(["hello"]) == storage.getEntryValue("stringarr/one")
    assert Value.makeStringArray(["hello", "world\n"]) == storage.getEntryValue("stringarr/two")
    assert Value.makeBoolean(True) == storage.getEntryValue("\0\3\5\n")
Exemplo n.º 7
0
def test_SetEntryTypeValueAssignNew(
    storage_empty, dispatcher, entry_notifier, is_server
):
    storage = storage_empty

    # brand new entry
    value = Value.makeBoolean(True)
    storage.setEntryTypeValue("foo", value)
    assert value == storage.m_entries.get("foo").value

    dispatcher._queueOutgoing.assert_has_calls(
        [
            call(
                Message.entryAssign("foo", 0 if is_server else 0xFFFF, 1, value, 0),
                None,
                None,
            )
        ]
    )
    entry_notifier.notifyEntry.assert_has_calls(
        [call(0, "foo", value, NT_NOTIFY_NEW | NT_NOTIFY_LOCAL)]
    )

    if is_server:
        assert 1 == len(storage.m_idmap)
        assert value == storage.m_idmap[0].value
    else:
        assert len(storage.m_idmap) == 0
Exemplo n.º 8
0
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
Exemplo n.º 9
0
def storage_populate_one(storage_empty, outgoing):
    storage = storage_empty
    
    storage.setEntryTypeValue("foo", Value.makeBoolean(True))
    del outgoing[:]
    
    return storage
Exemplo n.º 10
0
 def forceSetBoolean(self, value):
     """Sets the entry's value.
     
     :param value: the value to set
     """
     value = Value.makeBoolean(value)
     return self.__api.setEntryTypeValueById(self._local_id, value)
Exemplo n.º 11
0
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
Exemplo n.º 12
0
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)]
    )
Exemplo n.º 13
0
def test_SetEntryTypeValueAssignNew(storage_empty, outgoing, is_server):
    storage = storage_empty
    
    # brand entry
    value = Value.makeBoolean(True)
    storage.setEntryTypeValue("foo", value)
    assert value == storage.m_entries.get("foo").value
    if is_server:
        assert 1 == len(storage.m_idmap)
        assert value == storage.m_idmap[0].value

    else:
        assert len(storage.m_idmap) == 0


    assert 1 == len(outgoing)
    assert not outgoing[0].only
    assert not outgoing[0].conn
    msg = outgoing[0].msg
    assert kEntryAssign == msg.type
    assert "foo" == msg.str
    if is_server:
        assert 0 == msg.id    # assigned as server

    else:
        assert 0xffff == msg.id    # not assigned as client

    assert 1 == msg.seq_num_uid
    assert value == msg.value
    assert 0 == msg.flags
Exemplo n.º 14
0
def test_SetEntryTypeValueAssignNew(
    storage_empty, dispatcher, entry_notifier, is_server
):
    storage = storage_empty

    # brand new entry
    value = Value.makeBoolean(True)
    storage.setEntryTypeValue("foo", value)
    assert value == storage.m_entries.get("foo").value

    dispatcher._queueOutgoing.assert_has_calls(
        [
            call(
                Message.entryAssign("foo", 0 if is_server else 0xFFFF, 1, value, 0),
                None,
                None,
            )
        ]
    )
    entry_notifier.notifyEntry.assert_has_calls(
        [call(0, "foo", value, NT_NOTIFY_NEW | NT_NOTIFY_LOCAL)]
    )

    if is_server:
        assert 1 == len(storage.m_idmap)
        assert value == storage.m_idmap[0].value
    else:
        assert len(storage.m_idmap) == 0
Exemplo n.º 15
0
 def forceSetBoolean(self, value):
     """Sets the entry's value.
     
     :param value: the value to set
     """
     value = Value.makeBoolean(value)
     return self.__api.setEntryTypeValueById(self._local_id, value)
Exemplo n.º 16
0
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

    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)]
    )
Exemplo n.º 17
0
def test_GetEntryValueExist(storage_empty, outgoing):
    storage = storage_empty
    
    value = Value.makeBoolean(True)
    storage.setEntryTypeValue("foo", value)
    del outgoing[:]
    assert value == storage.getEntryValue("foo")
Exemplo n.º 18
0
 def setDefaultBoolean(self, defaultValue):
     """Sets the entry's value if it does not exist.
     
     :param defaultValue: the default value to set
     :returns: False if the entry exists with a different type
     """
     value = Value.makeBoolean(defaultValue)
     return self.__api.setDefaultEntryValueById(self._local_id, value)
Exemplo n.º 19
0
 def setBoolean(self, value):
     """Sets the entry's value.
     
     :param value: the value to set
     :returns: False if the entry exists with a different type
     """
     value = Value.makeBoolean(value)
     return self.__api.setEntryValueById(self._local_id, value)
Exemplo n.º 20
0
def test_SetEntryValueEmptyName(storage_empty, outgoing):
    storage = storage_empty
    
    value = Value.makeBoolean(True)
    assert storage.setEntryValue("", value)
    assert len(storage.m_entries) == 0
    assert len(storage.m_idmap) == 0
    assert len(outgoing) == 0
Exemplo n.º 21
0
 def setBoolean(self, value):
     """Sets the entry's value.
     
     :param value: the value to set
     :returns: False if the entry exists with a different type
     """
     value = Value.makeBoolean(value)
     return self.__api.setEntryValueById(self._local_id, value)
Exemplo n.º 22
0
 def setDefaultBoolean(self, defaultValue):
     """Sets the entry's value if it does not exist.
     
     :param defaultValue: the default value to set
     :returns: False if the entry exists with a different type
     """
     value = Value.makeBoolean(defaultValue)
     return self.__api.setDefaultEntryValueById(self._local_id, value)
Exemplo n.º 23
0
def test_GetEntryValueExist(storage_empty, dispatcher, entry_notifier):
    storage = storage_empty

    value = Value.makeBoolean(True)
    storage.setEntryTypeValue("foo", value)
    assert dispatcher._queueOutgoing.call_count == 1
    assert entry_notifier.notifyEntry.call_count == 1

    assert value == storage.getEntryValue("foo")
Exemplo n.º 24
0
def test_DeleteCheckHandle(storage_populate_one, dispatcher, entry_notifier, is_server):
    storage = storage_populate_one

    handle = storage.getEntryId("foo")
    storage.deleteEntry("foo")
    storage.setEntryTypeValue("foo", Value.makeBoolean(True))

    handle2 = storage.getEntryId("foo")
    assert handle == handle2
Exemplo n.º 25
0
def test_DeleteCheckHandle(storage_populate_one, dispatcher, entry_notifier, is_server):
    storage = storage_populate_one

    handle = storage.getEntryId("foo")
    storage.deleteEntry("foo")
    storage.setEntryTypeValue("foo", Value.makeBoolean(True))

    handle2 = storage.getEntryId("foo")
    assert handle == handle2
Exemplo n.º 26
0
def test_SetEntryTypeValueEqualValue(storage_populate_one, outgoing):
    storage = storage_populate_one
    
    # update with same type and same value: change value contents but no update
    # message is issued (minimizing bandwidth usage)
    value = Value.makeBoolean(True)
    storage.setEntryTypeValue("foo", value)
    assert value == storage.m_entries.get("foo").value
    assert len(outgoing) == 0
Exemplo n.º 27
0
def test_GetEntryValueExist(storage_empty, dispatcher, entry_notifier):
    storage = storage_empty

    value = Value.makeBoolean(True)
    storage.setEntryTypeValue("foo", value)
    assert dispatcher._queueOutgoing.call_count == 1
    assert entry_notifier.notifyEntry.call_count == 1

    assert value == storage.getEntryValue("foo")
Exemplo n.º 28
0
def test_SetDefaultEntryExistsSameType(storage_populate_one, outgoing):
    storage = storage_populate_one
    
    # existing entry
    value = Value.makeBoolean(False)
    ret_val = storage.setDefaultEntryValue("foo", value)
    assert ret_val
    assert value != storage.m_entries.get("foo").value

    assert len(outgoing) == 0
Exemplo n.º 29
0
def test_SetEntryValueEmptyName(storage_empty, dispatcher, entry_notifier):
    storage = storage_empty

    value = Value.makeBoolean(True)
    assert storage.setEntryValue("", value)
    assert len(storage.m_entries) == 0
    assert len(storage.m_idmap) == 0

    assert dispatcher._queueOutgoing.call_count == 0
    assert entry_notifier.notifyEntry.call_count == 0
Exemplo n.º 30
0
def test_SetEntryValueEmptyName(storage_empty, dispatcher, entry_notifier):
    storage = storage_empty

    value = Value.makeBoolean(True)
    assert storage.setEntryValue("", value)
    assert len(storage.m_entries) == 0
    assert len(storage.m_idmap) == 0

    assert dispatcher._queueOutgoing.call_count == 0
    assert entry_notifier.notifyEntry.call_count == 0
Exemplo n.º 31
0
def test_SetEntryTypeValueEqualValue(storage_populate_one, dispatcher, entry_notifier):
    storage = storage_populate_one

    # update with same type and same value: change value contents but no update
    # message is issued (minimizing bandwidth usage)
    value = Value.makeBoolean(True)
    storage.setEntryTypeValue("foo", value)
    assert value == storage.m_entries.get("foo").value

    assert dispatcher._queueOutgoing.call_count == 0
    assert entry_notifier.notifyEntry.call_count == 0
Exemplo n.º 32
0
def test_empty_SetDefaultEntryEmptyName(storage_empty, outgoing):
    storage = storage_empty
    
    value = Value.makeBoolean(True)
    ret_val = storage.setDefaultEntryValue("", value)
    assert not ret_val
    assert "foo" not in storage.m_entries
    
    assert len(storage.m_entries) == 0
    assert len(storage.m_idmap) == 0
    assert len(outgoing) == 0
Exemplo n.º 33
0
def test_SetEntryTypeValueEqualValue(storage_populate_one, dispatcher, entry_notifier):
    storage = storage_populate_one

    # update with same type and same value: change value contents but no update
    # message is issued (minimizing bandwidth usage)
    value = Value.makeBoolean(True)
    storage.setEntryTypeValue("foo", value)
    assert value == storage.m_entries.get("foo").value

    assert dispatcher._queueOutgoing.call_count == 0
    assert entry_notifier.notifyEntry.call_count == 0
Exemplo n.º 34
0
def storage_populate_one(storage_empty, dispatcher, entry_notifier):
    storage = storage_empty

    entry_notifier.m_local_notifiers = False

    storage.setEntryTypeValue("foo", Value.makeBoolean(True))

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

    return storage
Exemplo n.º 35
0
def test_SetDefaultEntryExistsSameType(storage_populate_one, dispatcher,
                                       entry_notifier):
    storage = storage_populate_one

    # existing entry
    value = Value.makeBoolean(False)
    ret_val = storage.setDefaultEntryValue("foo", value)
    assert ret_val
    assert value != storage.m_entries.get("foo").value

    assert dispatcher._queueOutgoing.call_count == 0
    assert entry_notifier.notifyEntry.call_count == 0
Exemplo n.º 36
0
def storage_populate_one(storage_empty, dispatcher, entry_notifier):
    storage = storage_empty

    entry_notifier.m_local_notifiers = False

    storage.setEntryTypeValue("foo", Value.makeBoolean(True))

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

    return storage
Exemplo n.º 37
0
def test_empty_SetDefaultEntryEmptyName(storage_empty, dispatcher, entry_notifier):
    storage = storage_empty

    value = Value.makeBoolean(True)
    ret_val = storage.setDefaultEntryValue("", value)
    assert not ret_val
    assert "foo" not in storage.m_entries

    assert len(storage.m_entries) == 0
    assert len(storage.m_idmap) == 0

    assert dispatcher._queueOutgoing.call_count == 0
    assert entry_notifier.notifyEntry.call_count == 0
Exemplo n.º 38
0
def test_SetDefaultEntryExistsSameType(
    storage_populate_one, dispatcher, entry_notifier
):
    storage = storage_populate_one

    # existing entry
    value = Value.makeBoolean(False)
    ret_val = storage.setDefaultEntryValue("foo", value)
    assert ret_val
    assert value != storage.m_entries.get("foo").value

    assert dispatcher._queueOutgoing.call_count == 0
    assert entry_notifier.notifyEntry.call_count == 0
 def putBoolean(self, key, value):
     """Put a boolean in the table
     
     :param key: the key to be assigned to
     :type key: str
     :param value: the value that will be assigned
     :type value: bool
     
     :returns: False if the table key already exists with a different type
     :rtype: bool
     """
     path = self._path + key
     return self._api.setEntryValue(path, Value.makeBoolean(value))
Exemplo n.º 40
0
 def putBoolean(self, key, value):
     """Put a boolean in the table
     
     :param key: the key to be assigned to
     :type key: str
     :param value: the value that will be assigned
     :type value: bool
     
     :returns: False if the table key already exists with a different type
     :rtype: bool
     """
     path = self._path + key
     return self._api.setEntryValue(path, Value.makeBoolean(value))
Exemplo n.º 41
0
def test_empty_SetDefaultEntryEmptyName(storage_empty, dispatcher, entry_notifier):
    storage = storage_empty

    value = Value.makeBoolean(True)
    ret_val = storage.setDefaultEntryValue("", value)
    assert not ret_val
    assert "foo" not in storage.m_entries

    assert len(storage.m_entries) == 0
    assert len(storage.m_idmap) == 0

    assert dispatcher._queueOutgoing.call_count == 0
    assert entry_notifier.notifyEntry.call_count == 0
Exemplo n.º 42
0
def storage_persistent(storage_empty, dispatcher, entry_notifier):
    storage = storage_empty

    entry_notifier.m_local_notifiers = False

    storage.setEntryTypeValue("boolean/true", Value.makeBoolean(True))
    storage.setEntryTypeValue("boolean/false", Value.makeBoolean(False))
    storage.setEntryTypeValue("double/neg", Value.makeDouble(-1.5))
    storage.setEntryTypeValue("double/zero", Value.makeDouble(0.0))
    storage.setEntryTypeValue("double/big", Value.makeDouble(1.3e8))
    storage.setEntryTypeValue("string/empty", Value.makeString(""))
    storage.setEntryTypeValue("string/normal", Value.makeString("hello"))
    storage.setEntryTypeValue("string/special", Value.makeString("\0\3\5\n"))
    storage.setEntryTypeValue("raw/empty", Value.makeRaw(b""))
    storage.setEntryTypeValue("raw/normal", Value.makeRaw(b"hello"))
    storage.setEntryTypeValue("raw/special", Value.makeRaw(b"\0\3\5\n"))
    storage.setEntryTypeValue("booleanarr/empty", Value.makeBooleanArray([]))
    storage.setEntryTypeValue("booleanarr/one", Value.makeBooleanArray([True]))
    storage.setEntryTypeValue("booleanarr/two",
                              Value.makeBooleanArray([True, False]))
    storage.setEntryTypeValue("doublearr/empty", Value.makeDoubleArray([]))
    storage.setEntryTypeValue("doublearr/one", Value.makeDoubleArray([0.5]))
    storage.setEntryTypeValue("doublearr/two",
                              Value.makeDoubleArray([0.5, -0.25]))
    storage.setEntryTypeValue("stringarr/empty", Value.makeStringArray([]))
    storage.setEntryTypeValue("stringarr/one",
                              Value.makeStringArray(["hello"]))
    storage.setEntryTypeValue("stringarr/two",
                              Value.makeStringArray(["hello", "world\n"]))
    storage.setEntryTypeValue("\0\3\5\n", Value.makeBoolean(True))
    storage.setEntryTypeValue("CaseSensitive/KeyName", Value.makeBoolean(True))
    storage.setEntryTypeValue("=", Value.makeBoolean(True))

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

    return storage
Exemplo n.º 43
0
def storage_persistent(storage_empty, dispatcher, entry_notifier):
    storage = storage_empty

    entry_notifier.m_local_notifiers = False

    storage.setEntryTypeValue("boolean/true", Value.makeBoolean(True))
    storage.setEntryTypeValue("boolean/false", Value.makeBoolean(False))
    storage.setEntryTypeValue("double/neg", Value.makeDouble(-1.5))
    storage.setEntryTypeValue("double/zero", Value.makeDouble(0.0))
    storage.setEntryTypeValue("double/big", Value.makeDouble(1.3e8))
    storage.setEntryTypeValue("string/empty", Value.makeString(""))
    storage.setEntryTypeValue("string/normal", Value.makeString("hello"))
    storage.setEntryTypeValue("string/special", Value.makeString("\0\3\5\n"))
    storage.setEntryTypeValue("string/quoted", Value.makeString('"a"'))
    storage.setEntryTypeValue("raw/empty", Value.makeRaw(b""))
    storage.setEntryTypeValue("raw/normal", Value.makeRaw(b"hello"))
    storage.setEntryTypeValue("raw/special", Value.makeRaw(b"\0\3\5\n"))
    storage.setEntryTypeValue("booleanarr/empty", Value.makeBooleanArray([]))
    storage.setEntryTypeValue("booleanarr/one", Value.makeBooleanArray([True]))
    storage.setEntryTypeValue("booleanarr/two", Value.makeBooleanArray([True, False]))
    storage.setEntryTypeValue("doublearr/empty", Value.makeDoubleArray([]))
    storage.setEntryTypeValue("doublearr/one", Value.makeDoubleArray([0.5]))
    storage.setEntryTypeValue("doublearr/two", Value.makeDoubleArray([0.5, -0.25]))
    storage.setEntryTypeValue("stringarr/empty", Value.makeStringArray([]))
    storage.setEntryTypeValue("stringarr/one", Value.makeStringArray(["hello"]))
    storage.setEntryTypeValue(
        "stringarr/two", Value.makeStringArray(["hello", "world\n"])
    )
    storage.setEntryTypeValue("\0\3\5\n", Value.makeBoolean(True))
    storage.setEntryTypeValue("CaseSensitive/KeyName", Value.makeBoolean(True))
    storage.setEntryTypeValue("=", Value.makeBoolean(True))

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

    return storage
Exemplo n.º 44
0
 def setDefaultBoolean(self, key, defaultValue):
     """If the key doesn't currently exist, then the specified value will
     be assigned to the key.
     
     :param key: the key to be assigned to
     :type key: str
     :param defaultValue: the default value to set if key doesn't exist.
     :type defaultValue: bool
     
     :returns: False if the table key exists with a different type
     
     .. versionadded:: 2017.0.0
     """
     path = self._path + key
     return self._api.setDefaultEntryValue(path, Value.makeBoolean(defaultValue))
Exemplo n.º 45
0
 def setDefaultBoolean(self, key, defaultValue):
     """If the key doesn't currently exist, then the specified value will
     be assigned to the key.
     
     :param key: the key to be assigned to
     :type key: str
     :param defaultValue: the default value to set if key doesn't exist.
     :type defaultValue: bool
     
     :returns: False if the table key exists with a different type
     
     .. versionadded:: 2017.0.0
     """
     path = self._path + key
     return self._api.setDefaultEntryValue(path, Value.makeBoolean(defaultValue))
Exemplo n.º 46
0
def test_populated_SetDefaultEntryEmptyName(storage_populated, outgoing, is_server):
    storage = storage_populated
    
    value = Value.makeBoolean(True)
    ret_val = storage.setDefaultEntryValue("", value)
    assert not ret_val
    # assert that no entries get added
    assert 4 == len(storage.m_entries)
    if is_server:
        assert 4 == len(storage.m_idmap)

    else:
        assert 0 == len(storage.m_idmap)

    assert len(outgoing) == 0
Exemplo n.º 47
0
def test_SetEntryValueAssignNew(storage_empty, dispatcher, entry_notifier,
                                is_server):
    storage = storage_empty

    # brand entry
    value = Value.makeBoolean(True)
    assert storage.setEntryValue("foo", value)
    assert value == storage.m_entries.get("foo").value

    dispatcher._queueOutgoing.assert_has_calls([
        call(
            Message.entryAssign("foo", 0 if is_server else 0xffff, 1, value,
                                0), None, None),
    ])
    entry_notifier.notifyEntry.assert_has_calls([
        call(0, "foo", value, NT_NOTIFY_NEW | NT_NOTIFY_LOCAL),
    ])
Exemplo n.º 48
0
def test_populated_SetDefaultEntryEmptyName(storage_populated, dispatcher,
                                            entry_notifier, is_server):
    storage = storage_populated

    value = Value.makeBoolean(True)
    ret_val = storage.setDefaultEntryValue("", value)
    assert not ret_val
    # assert that no entries get added
    assert 4 == len(storage.m_entries)
    if is_server:
        assert 4 == len(storage.m_idmap)

    else:
        assert 0 == len(storage.m_idmap)

    assert dispatcher._queueOutgoing.call_count == 0
    assert entry_notifier.notifyEntry.call_count == 0
Exemplo n.º 49
0
def test_populated_SetDefaultEntryEmptyName(
    storage_populated, dispatcher, entry_notifier, is_server
):
    storage = storage_populated

    value = Value.makeBoolean(True)
    ret_val = storage.setDefaultEntryValue("", value)
    assert not ret_val
    # assert that no entries get added
    assert 4 == len(storage.m_entries)
    if is_server:
        assert 4 == len(storage.m_idmap)

    else:
        assert 0 == len(storage.m_idmap)

    assert dispatcher._queueOutgoing.call_count == 0
    assert entry_notifier.notifyEntry.call_count == 0
Exemplo n.º 50
0
def test_BooleanComparison():
    v1 = Value.makeBoolean(True)
    v2 = Value.makeBoolean(True)
    assert v1 == v2
    v2 = Value.makeBoolean(False)
    assert v1 != v2
Exemplo n.º 51
0
def test_MixedComparison():

    v2 = Value.makeBoolean(True)
    v3 = Value.makeDouble(0.5)
    assert v2 != v3  # boolean vs double
Exemplo n.º 52
0
def test_loadPersistent(storage_empty, dispatcher, entry_notifier):
    storage = storage_empty

    inp = "[NetworkTables Storage 3.0]\n"
    inp += "boolean \"\\x00\\x03\\x05\\n\"=true\n"
    inp += "boolean \"CaseSensitive/KeyName\"=true\n"
    inp += "boolean \"boolean/false\"=false\n"
    inp += "boolean \"boolean/true\"=true\n"
    inp += "array boolean \"booleanarr/empty\"=\n"
    inp += "array boolean \"booleanarr/one\"=true\n"
    inp += "array boolean \"booleanarr/two\"=true,false\n"
    inp += "double \"double/big\"=1.3e+08\n"
    inp += "double \"double/neg\"=-1.5\n"
    inp += "double \"double/zero\"=0\n"
    inp += "array double \"doublearr/empty\"=\n"
    inp += "array double \"doublearr/one\"=0.5\n"
    inp += "array double \"doublearr/two\"=0.5,-0.25\n"
    inp += "raw \"raw/empty\"=\n"
    inp += "raw \"raw/normal\"=aGVsbG8=\n"
    inp += "raw \"raw/special\"=AAMFCg==\n"
    inp += "string \"string/empty\"=\"\"\n"
    inp += "string \"string/normal\"=\"hello\"\n"
    inp += "string \"string/special\"=\"\\x00\\x03\\x05\\n\"\n"
    inp += "array string \"stringarr/empty\"=\n"
    inp += "array string \"stringarr/one\"=\"hello\"\n"
    inp += "array string \"stringarr/two\"=\"hello\",\"world\\n\"\n"

    fp = StringIO(inp)
    assert storage.loadPersistent(fp=fp) is None

    dispatcher._queueOutgoing.assert_has_calls([
        call(ANY, None, None),
    ] * 22)

    entry_notifier.notifyEntry.assert_has_calls(
        [call(ANY, ANY, ANY, NT_NOTIFY_NEW | NT_NOTIFY_LOCAL)] * 22)

    assert Value.makeBoolean(True) == storage.getEntryValue("boolean/true")
    assert Value.makeBoolean(False) == storage.getEntryValue("boolean/false")
    assert Value.makeDouble(-1.5) == storage.getEntryValue("double/neg")
    assert Value.makeDouble(0.0) == storage.getEntryValue("double/zero")
    assert Value.makeDouble(1.3e8) == storage.getEntryValue("double/big")
    assert Value.makeString("") == storage.getEntryValue("string/empty")
    assert Value.makeString("hello") == storage.getEntryValue("string/normal")
    assert Value.makeString("\0\3\5\n") == storage.getEntryValue(
        "string/special")
    assert Value.makeRaw(b"") == storage.getEntryValue("raw/empty")
    assert Value.makeRaw(b"hello") == storage.getEntryValue("raw/normal")
    assert Value.makeRaw(b"\0\3\5\n") == storage.getEntryValue("raw/special")
    assert Value.makeBooleanArray(
        []) == storage.getEntryValue("booleanarr/empty")
    assert Value.makeBooleanArray(
        [True]) == storage.getEntryValue("booleanarr/one")
    assert Value.makeBooleanArray(
        [True, False]) == storage.getEntryValue("booleanarr/two")
    assert Value.makeDoubleArray(
        []) == storage.getEntryValue("doublearr/empty")
    assert Value.makeDoubleArray([0.5
                                  ]) == storage.getEntryValue("doublearr/one")
    assert Value.makeDoubleArray([0.5, -0.25
                                  ]) == storage.getEntryValue("doublearr/two")
    assert Value.makeStringArray(
        []) == storage.getEntryValue("stringarr/empty")
    assert Value.makeStringArray(["hello"
                                  ]) == storage.getEntryValue("stringarr/one")
    assert Value.makeStringArray(["hello", "world\n"
                                  ]) == storage.getEntryValue("stringarr/two")
    assert Value.makeBoolean(True) == storage.getEntryValue("\0\3\5\n")
    assert Value.makeBoolean(True) == storage.getEntryValue(
        "CaseSensitive/KeyName")
Exemplo n.º 53
0
def test_wire_entryUpdate1(msg_round_trip, proto_rev):
    exclude = [] if proto_rev >= 0x0300 else [4]
    value = Value.makeBoolean(True)
    msg_round_trip(Message.entryUpdate(0x1234, 0x4321, value), exclude=exclude)
Exemplo n.º 54
0
def test_wire_boolean(v_round_trip):
    v_round_trip(Value.makeBoolean(True))