Beispiel #1
0
def main():
  try:
    opts, args = getopt.getopt(sys.argv[1:], "k", ["keepfiles"])
  except getopt.GetoptError as e:
    print str(e)
    sys.exit(127)

  k = False
  for o, a in opts:
    if o in ["-k", "--keepfiles"]:
      k = True

  pythonpath = os.environ.get("PATH_TO_PYBIND_TEST_PYTHON") if \
                os.environ.get('PATH_TO_PYBIND_TEST_PYTHON') is not None \
                  else sys.executable
  pyangpath = os.environ.get('PYANGPATH') if \
                os.environ.get('PYANGPATH') is not None else False
  pyangbindpath = os.environ.get('PYANGBINDPATH') if \
                os.environ.get('PYANGBINDPATH') is not None else False
  assert pyangpath is not False, "could not find path to pyang"
  assert pyangbindpath is not False, "could not resolve pyangbind directory"

  this_dir = os.path.dirname(os.path.realpath(__file__))

  cmd = "%s " % pythonpath
  cmd += "%s --plugindir %s/pyangbind/plugin" % (pyangpath, pyangbindpath)
  cmd += " -f pybind -o %s/bindings.py" % this_dir
  cmd += " -p %s" % this_dir
  cmd += " %s/%s.yang" % (this_dir, TESTNAME)
  os.system(cmd)

  from bindings import bits as b

  t = b()

  for i in ["b1"]:
    assert hasattr(t.container, i), "element did not exist in container (%s)" % i

  for value in [False, True]:
    passed = True
    try:
      t.container.b1.flag1 = value
    except:
      passed = False
    assert passed and t.container.b1.flag1 == value, "could incorrectly set bit value"

    try:
      t.container.b1.flag2 = value
    except:
      passed = False
    assert passed and t.container.b1.flag2 == value, "could incorrectly set bit value"

  if not k:
    os.system("/bin/rm %s/bindings.py" % this_dir)
    os.system("/bin/rm %s/bindings.pyc" % this_dir)
Beispiel #2
0
def main():
  try:
    opts, args = getopt.getopt(sys.argv[1:], "k", ["keepfiles"])
  except getopt.GetoptError as e:
    print str(e)
    sys.exit(127)

  k = False
  for o, a in opts:
    if o in ["-k", "--keepfiles"]:
      k = True

  pythonpath = os.environ.get("PATH_TO_PYBIND_TEST_PYTHON") if \
                os.environ.get('PATH_TO_PYBIND_TEST_PYTHON') is not None \
                  else sys.executable
  pyangpath = os.environ.get('PYANGPATH') if \
                os.environ.get('PYANGPATH') is not None else False
  pyangbindpath = os.environ.get('PYANGBINDPATH') if \
                os.environ.get('PYANGBINDPATH') is not None else False
  assert pyangpath is not False, "could not find path to pyang"
  assert pyangbindpath is not False, "could not resolve pyangbind directory"

  this_dir = os.path.dirname(os.path.realpath(__file__))

  cmd = "%s " % pythonpath
  cmd += "%s --plugindir %s/pyangbind/plugin" % (pyangpath, pyangbindpath)
  cmd += " -f pybind -o %s/bindings.py" % this_dir
  cmd += " -p %s" % this_dir
  cmd += " %s/%s.yang" % (this_dir, TESTNAME)
  os.system(cmd)

  from bindings import binary as b
  from bitarray import bitarray
  t = b()

  for i in ["b1", "b2", "b3"]:
    assert hasattr(t.container, i), \
        "element did not exist in container (%s)" % i

  for value in [
      ("01110", True, [False, True, True, True, False],),
          ({"42": 42}, True, [True])]:
    passed = True
    try:
      t.container.b1 = value[0]
    except:
      passed = False
    assert passed == value[1], "could incorrectly set b1 to %s" % value[0]

  assert t.container.b2._default == bitarray("0100"), \
    "Default for leaf b2 was not set correctly (%s != %s)" \
       % (t.container.b2._default, bitarray("0100"))

  assert t.container.b2 == bitarray(), \
    "Value of bitarray was not null when checking b2 (%s != %s)" \
        % (t.container.b2, bitarray())

  assert t.container.b2._changed() == False, \
    "Unset bitarray specified changed when was default (%s != False)" \
        % (t.container.b2._changed())

  t.container.b2 = bitarray("010")
  assert t.container.b2 == bitarray('010'), \
    "Bitarray not successfuly set (%s != %s)" % \
        (t.container.b2, bitarray('010'))

  assert t.container.b2._changed() == True, \
    "Bitarray value not flagged as changed (%s != %s)" % \
        (t.container.b2._changed(), True)

  for v in [("0", False), ("01", True), ("010", False)]:
    try:
      t.container.b3 = v[0]
      passed = True
    except ValueError:
      passed = False
    assert passed == v[1], \
        "limited length binary incorrectly set to %s (%s != %s)" \
          % (v[0], v[1], passed)

  for v in [("0", False), ("01", True), ("1111", True), ("10000001", False)]:
    try:
      t.container.b4 = v[0]
      passed = True
    except ValueError:
      passed = False
    assert passed == v[1], "limited length binary with range incorrectly " + \
      "set to %s (%s != %s)" % (v[0], v[1], passed)

  for v in [("0", False), ("01", True), ("010", True), ("01000", False),
      ("100000", True), ("10101010101010101010101010101", True),
          ("10101010101010101010101010101010101010101010101010101010" +
              "1010101010101010", False)]:
    try:
      t.container.b5 = v[0]
      passed = True
    except:
      passed = False
    assert passed == v[1], "limited length binary with complex length " + \
        "argument incorrectly set to %s (%s != %s)" % (v[0], v[1], passed)

  if not k:
    os.system("/bin/rm %s/bindings.py" % this_dir)
    os.system("/bin/rm %s/bindings.pyc" % this_dir)
Beispiel #3
0
def main():
    try:
        opts, args = getopt.getopt(sys.argv[1:], "k", ["keepfiles"])
    except getopt.GetoptError as e:
        print(str(e))
        sys.exit(127)

    k = False
    for o, a in opts:
        if o in ["-k", "--keepfiles"]:
            k = True

    pythonpath = os.environ.get("PATH_TO_PYBIND_TEST_PYTHON") if \
                  os.environ.get('PATH_TO_PYBIND_TEST_PYTHON') is not None \
                    else sys.executable
    pyangpath = os.environ.get('PYANGPATH') if \
                  os.environ.get('PYANGPATH') is not None else False
    pyangbindpath = os.environ.get('PYANGBINDPATH') if \
                  os.environ.get('PYANGBINDPATH') is not None else False
    assert pyangpath is not False, "could not find path to pyang"
    assert pyangbindpath is not False, "could not resolve pyangbind directory"

    this_dir = os.path.dirname(os.path.realpath(__file__))

    cmd = "%s " % pythonpath
    cmd += "%s --plugindir %s/pyangbind/plugin" % (pyangpath, pyangbindpath)
    cmd += " -f pybind -o %s/bindings.py" % this_dir
    cmd += " -p %s" % this_dir
    cmd += " %s/%s.yang" % (this_dir, TESTNAME)
    os.system(cmd)

    from bindings import boolean_empty as b

    t = b()

    for i in ["b1", "b2", "e1"]:
        assert hasattr(t.container, i), "element did not exist in container (%s)" \
            % i

    for value in [(0, False), ("0", False), (False, False), ("false", False),
                  ("False", False), (1, True), ("1", True), (True, True),
                  ("true", True), ("True", True)]:
        passed = True
        try:
            t.container.b1 = value[0]
        except:
            passed = False

        assert passed is True, "value of b1 was not correctly set to %s" % value
        assert t.container.b1 == value[1], "value of b1 was not correctly set " + \
            "when compared (%s - set to %s)" % (t.container.b1, value)

    for value in [(0, False), ("0", False), (False, False), ("false", False),
                  ("False", False), (1, True), ("1", True), (True, True),
                  ("true", True), ("True", True)]:
        passed = True
        try:
            t.container.e1 = value[0]
        except:
            passed = False

        assert passed is True, "value of e1 was not correctly set to %s" % value
        assert t.container.e1 == value[1], "value of e1 was not correctly set " + \
            "when compared (%s - set to %s)" % (t.container.e1, value)

    assert t.container.b2._default is False, "value default was not " + \
        "correctly set (%s)" % t.container.b2._default

    assert t.container.b2._changed() == False, "value was marked as changed " + \
        "incorrectly (%s)" % t.container.b2._changed()

    t.container.b2 = True
    assert t.container.b2._changed() == True, "value was not marked as " + \
        "when it was (%s)" % t.container.b2._changed()

    t.container.b2 = False
    assert t.get() == {'container': {'e1': True, 'b1': True, 'b2': False}}, \
      "wrong get() result returned %s" % t.get()

    if not k:
        os.system("/bin/rm %s/bindings.py" % this_dir)
        os.system("/bin/rm %s/bindings.pyc" % this_dir)
Beispiel #4
0
def main():
    try:
        opts, args = getopt.getopt(sys.argv[1:], "k", ["keepfiles"])
    except getopt.GetoptError as e:
        print str(e)
        sys.exit(127)

    k = False
    for o, a in opts:
        if o in ["-k", "--keepfiles"]:
            k = True

    pythonpath = os.environ.get("PATH_TO_PYBIND_TEST_PYTHON") if \
                  os.environ.get('PATH_TO_PYBIND_TEST_PYTHON') is not None \
                    else sys.executable
    pyangpath = os.environ.get('PYANGPATH') if \
                  os.environ.get('PYANGPATH') is not None else False
    pyangbindpath = os.environ.get('PYANGBINDPATH') if \
                  os.environ.get('PYANGBINDPATH') is not None else False
    assert pyangpath is not False, "could not find path to pyang"
    assert pyangbindpath is not False, "could not resolve pyangbind directory"

    this_dir = os.path.dirname(os.path.realpath(__file__))

    cmd = "%s " % pythonpath
    cmd += "%s --plugindir %s/pyangbind/plugin" % (pyangpath, pyangbindpath)
    cmd += " -f pybind -o %s/bindings.py" % this_dir
    cmd += " -p %s" % this_dir
    cmd += " %s/%s.yang" % (this_dir, TESTNAME)
    os.system(cmd)

    from bindings import binary as b
    from bitarray import bitarray
    t = b()

    for i in ["b1", "b2", "b3"]:
        assert hasattr(t.container, i), \
            "element did not exist in container (%s)" % i

    for value in [(
            "01110",
            True,
        [False, True, True, True, False],
    ), ({
            "42": 42
    }, True, [True])]:
        passed = True
        try:
            t.container.b1 = value[0]
        except:
            passed = False
        assert passed == value[1], "could incorrectly set b1 to %s" % value[0]

    assert t.container.b2._default == bitarray("0100"), \
      "Default for leaf b2 was not set correctly (%s != %s)" \
         % (t.container.b2._default, bitarray("0100"))

    assert t.container.b2 == bitarray(), \
      "Value of bitarray was not null when checking b2 (%s != %s)" \
          % (t.container.b2, bitarray())

    assert t.container.b2._changed() == False, \
      "Unset bitarray specified changed when was default (%s != False)" \
          % (t.container.b2._changed())

    t.container.b2 = bitarray("010")
    assert t.container.b2 == bitarray('010'), \
      "Bitarray not successfuly set (%s != %s)" % \
          (t.container.b2, bitarray('010'))

    assert t.container.b2._changed() == True, \
      "Bitarray value not flagged as changed (%s != %s)" % \
          (t.container.b2._changed(), True)

    for v in [("0", False), ("01", True), ("010", False)]:
        try:
            t.container.b3 = v[0]
            passed = True
        except ValueError:
            passed = False
        assert passed == v[1], \
            "limited length binary incorrectly set to %s (%s != %s)" \
              % (v[0], v[1], passed)

    for v in [("0", False), ("01", True), ("1111", True), ("10000001", False)]:
        try:
            t.container.b4 = v[0]
            passed = True
        except ValueError:
            passed = False
        assert passed == v[1], "limited length binary with range incorrectly " + \
          "set to %s (%s != %s)" % (v[0], v[1], passed)

    for v in [("0", False), ("01", True), ("010", True), ("01000", False),
              ("100000", True), ("10101010101010101010101010101", True),
              ("10101010101010101010101010101010101010101010101010101010" +
               "1010101010101010", False)]:
        try:
            t.container.b5 = v[0]
            passed = True
        except:
            passed = False
        assert passed == v[1], "limited length binary with complex length " + \
            "argument incorrectly set to %s (%s != %s)" % (v[0], v[1], passed)

    if not k:
        os.system("/bin/rm %s/bindings.py" % this_dir)
        os.system("/bin/rm %s/bindings.pyc" % this_dir)
Beispiel #5
0
def main():
  try:
    opts, args = getopt.getopt(sys.argv[1:], "k", ["keepfiles"])
  except getopt.GetoptError as e:
    print str(e)
    sys.exit(127)

  k = False
  for o, a in opts:
    if o in ["-k", "--keepfiles"]:
      k = True

  pythonpath = os.environ.get("PATH_TO_PYBIND_TEST_PYTHON") if \
                os.environ.get('PATH_TO_PYBIND_TEST_PYTHON') is not None \
                  else sys.executable
  pyangpath = os.environ.get('PYANGPATH') if \
                os.environ.get('PYANGPATH') is not None else False
  pyangbindpath = os.environ.get('PYANGBINDPATH') if \
                os.environ.get('PYANGBINDPATH') is not None else False
  assert pyangpath is not False, "could not find path to pyang"
  assert pyangbindpath is not False, "could not resolve pyangbind directory"

  this_dir = os.path.dirname(os.path.realpath(__file__))

  cmd = "%s " % pythonpath
  cmd += "%s --plugindir %s/pyangbind/plugin" % (pyangpath, pyangbindpath)
  cmd += " -f pybind -o %s/bindings.py" % this_dir
  cmd += " -p %s" % this_dir
  cmd += " %s/%s.yang" % (this_dir, TESTNAME)
  os.system(cmd)

  from bindings import boolean_empty as b

  t = b()

  for i in ["b1", "b2", "e1"]:
    assert hasattr(t.container, i), "element did not exist in container (%s)" \
        % i

  for value in [(0, False), ("0", False), (False, False), ("false", False),
                ("False", False), (1, True), ("1", True), (True, True),
                ("true", True), ("True", True)]:
    passed = True
    try:
      t.container.b1 = value[0]
    except:
      passed = False

    assert passed is True, "value of b1 was not correctly set to %s" % value
    assert t.container.b1 == value[1], "value of b1 was not correctly set " + \
        "when compared (%s - set to %s)" % (t.container.b1, value)

  for value in [(0, False), ("0", False), (False, False), ("false", False),
                ("False", False), (1, True), ("1", True), (True, True),
                ("true", True), ("True", True)]:
    passed = True
    try:
      t.container.e1 = value[0]
    except:
      passed = False

    assert passed is True, "value of e1 was not correctly set to %s" % value
    assert t.container.e1 == value[1], "value of e1 was not correctly set " + \
        "when compared (%s - set to %s)" % (t.container.e1, value)

  assert t.container.b2._default is False, "value default was not " + \
      "correctly set (%s)" % t.container.b2._default

  assert t.container.b2._changed() == False, "value was marked as changed " + \
      "incorrectly (%s)" % t.container.b2._changed()

  t.container.b2 = True
  assert t.container.b2._changed() == True, "value was not marked as " + \
      "when it was (%s)" % t.container.b2._changed()

  t.container.b2 = False
  assert t.get() == {'container': {'e1': True, 'b1': True, 'b2': False}}, \
    "wrong get() result returned %s" % t.get()

  if not k:
    os.system("/bin/rm %s/bindings.py" % this_dir)
    os.system("/bin/rm %s/bindings.pyc" % this_dir)