コード例 #1
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
コード例 #2
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")
コード例 #3
0
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
コード例 #4
0
ファイル: test_value.py プロジェクト: robotpy/pynetworktables
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
コード例 #5
0
ファイル: entry.py プロジェクト: robotpy/pynetworktables
 def forceSetStringArray(self, value):
     """Sets the entry's value.
     
     :param value: the value to set
     """
     value = Value.makeStringArray(value)
     return self.__api.setEntryTypeValueById(self._local_id, value)
コード例 #6
0
ファイル: entry.py プロジェクト: maniyar1/ManiVision
 def forceSetStringArray(self, value):
     """Sets the entry's value.
     
     :param value: the value to set
     """
     value = Value.makeStringArray(value)
     return self.__api.setEntryTypeValueById(self._local_id, value)
コード例 #7
0
ファイル: entry.py プロジェクト: robotpy/pynetworktables
 def setDefaultStringArray(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.makeStringArray(defaultValue)
     return self.__api.setDefaultEntryValueById(self._local_id, value)
コード例 #8
0
ファイル: entry.py プロジェクト: robotpy/pynetworktables
 def setStringArray(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.makeStringArray(value)
     return self.__api.setEntryValueById(self._local_id, value)
コード例 #9
0
ファイル: entry.py プロジェクト: maniyar1/ManiVision
 def setStringArray(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.makeStringArray(value)
     return self.__api.setEntryValueById(self._local_id, value)
コード例 #10
0
ファイル: entry.py プロジェクト: maniyar1/ManiVision
 def setDefaultStringArray(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.makeStringArray(defaultValue)
     return self.__api.setDefaultEntryValueById(self._local_id, value)
コード例 #11
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
コード例 #12
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
コード例 #13
0
 def putStringArray(self, key, value):
     """Put a string array in the table
     
     :param key: the key to be assigned to
     :type key: str
     :param value: the value that will be assigned
     :type value: iterable(str)
     
     :returns: False if the table key already exists with a different type
     :rtype: bool
     
     .. versionadded:: 2017.0.0
     """
     path = self._path + key
     return self._api.setEntryValue(path, Value.makeStringArray(value))
コード例 #14
0
 def putStringArray(self, key, value):
     """Put a string array in the table
     
     :param key: the key to be assigned to
     :type key: str
     :param value: the value that will be assigned
     :type value: list(str)
     
     :returns: False if the table key already exists with a different type
     :rtype: bool
     
     .. versionadded:: 2017.0.0
     """
     path = self._path + key
     return self._api.setEntryValue(path, Value.makeStringArray(value))
コード例 #15
0
 def setDefaultStringArray(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: iterable(str)
     
     :returns: False if the table key exists with a different type
     :rtype: bool
     
     .. versionadded:: 2017.0.0
     """
     path = self._path + key
     return self._api.setDefaultEntryValue(path, Value.makeStringArray(defaultValue))
コード例 #16
0
 def setDefaultStringArray(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: list(str)
     
     :returns: False if the table key exists with a different type
     :rtype: bool
     
     .. versionadded:: 2017.0.0
     """
     path = self._path + key
     return self._api.setDefaultEntryValue(path, Value.makeStringArray(defaultValue))
コード例 #17
0
def test_wire_stringArray1(v_round_trip):
    v_round_trip(Value.makeStringArray([]))
コード例 #18
0
ファイル: test_value.py プロジェクト: robotpy/pynetworktables
def test_StringArray():
    v = Value.makeStringArray(["hello", "goodbye", "string"])
    assert NT_STRING_ARRAY == v.type
    assert ("hello", "goodbye", "string") == v.value
コード例 #19
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")
コード例 #20
0
def test_StringArray():
    v = Value.makeStringArray(["hello", "goodbye", "string"])
    assert NT_STRING_ARRAY == v.type
    assert ("hello", "goodbye", "string") == v.value
コード例 #21
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 += 'string "string/quoted"="\\"a\\""\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)] * 23)

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

    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.makeString('"a"') == storage.getEntryValue("string/quoted")
    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")
コード例 #22
0
def test_wire_stringArray1(v_round_trip):
    v_round_trip(Value.makeStringArray([]))
コード例 #23
0
def test_wire_stringArray2(v_round_trip):
    v_round_trip(Value.makeStringArray(["hi", "there"]))
コード例 #24
0
def test_wire_stringArray3(v_round_trip):
    v_round_trip(Value.makeStringArray(["hi"] * 255))
コード例 #25
0
def test_wire_stringArray2(v_round_trip):
    v_round_trip(Value.makeStringArray(["hi", "there"]))