Example #1
0
def pysmraw_test_multi_open_close_file(filename, mode):
    """Tests multiple open and close."""
    description = ("Testing multi open close of: {0:s} with access: {1:s}"
                   "\t").format(get_filename_string(filename),
                                get_mode_string(mode))
    print(description, end="")

    error_string = None
    result = True

    try:
        smraw_handle = pysmraw.handle()

        filenames = None
        if filename:
            filenames = pysmraw.glob(filename)

        smraw_handle.open(filenames, mode)
        smraw_handle.close()
        smraw_handle.open(filenames, mode)
        smraw_handle.close()

    except Exception as exception:
        error_string = str(exception)
        result = False

    if not result:
        print("(FAIL)")
    else:
        print("(PASS)")

    if error_string:
        print(error_string)
    return result
Example #2
0
def pysmraw_test_single_open_close_file_object(filename, mode):
    """Tests a single file-like object open and close."""
    description = (
        "Testing single open close of file-like object of: {0:s} with access: "
        "{1:s}\t").format(get_filename_string(filename), get_mode_string(mode))
    print(description, end="")

    error_string = None
    result = True

    try:
        file_objects = []
        if filename:
            filenames = pysmraw.glob(filename)
            for filename in filenames:
                file_object = open(filename, "rb")
                file_objects.append(file_object)

        smraw_handle = pysmraw.handle()

        smraw_handle.open_file_objects(file_objects, mode)
        smraw_handle.close()

    except Exception as exception:
        error_string = str(exception)
        result = False

    if not result:
        print("(FAIL)")
    else:
        print("(PASS)")

    if error_string:
        print(error_string)
    return result
def pysmraw_test_multi_open_close_file_object(filename, mode):
  print(("Testing multi open close of file-like object of: {0:s} "
         "with access: {1:s}\t").format(filename, get_mode_string(mode)))

  result = True
  try:
    filenames = pysmraw.glob(filename)
    file_objects = []
    for filename in filenames:
      file_object = open(filename, "rb")
      file_objects.append(file_object)

    smraw_handle = pysmraw.handle()

    smraw_handle.open_file_object(file_objects, mode)
    smraw_handle.close()
    smraw_handle.open_file_object(file_objects, mode)
    smraw_handle.close()

  except Exception as exception:
    print(str(exception))
    result = False

  if not result:
    print("(FAIL)")
  else:
    print("(PASS)")
  return result
Example #4
0
def pysmraw_test_seek_file(filename):
    filenames = pysmraw.glob(filename)
    smraw_handle = pysmraw.handle()

    smraw_handle.open(filenames, "r")
    result = pysmraw_test_seek(smraw_handle)
    smraw_handle.close()

    return result
Example #5
0
def pysmraw_test_read_file(filename):
    """Tests the read function with a file."""
    smraw_handle = pysmraw.handle()

    filenames = pysmraw.glob(filename)
    smraw_handle.open(filenames, "r")
    result = pysmraw_test_read(smraw_handle)
    smraw_handle.close()

    return result
Example #6
0
def pysmraw_test_single_open_close_file(filename, mode):
    """Tests a single open and close."""
    description = ("Testing single open close of: {0:s} with access: {1:s}"
                   "\t").format(get_filename_string(filename),
                                get_mode_string(mode))
    print(description, end="")

    error_string = None
    result = True

    try:
        smraw_handle = pysmraw.handle()

        filenames = None
        if filename:
            filenames = pysmraw.glob(filename)

        smraw_handle.open(filenames, mode)
        smraw_handle.close()

    except TypeError as exception:
        expected_message = ("{0:s}: argument: files must be a sequence object."
                            ).format("pysmraw_handle_open")

        if not filename and str(exception) == expected_message:
            pass

        else:
            error_string = str(exception)
            result = False

    except ValueError as exception:
        expected_message = (
            "{0:s}: unsupported mode: w.").format("pysmraw_handle_open")

        if mode != "w" or str(exception) != expected_message:
            error_string = str(exception)
            result = False

    except Exception as exception:
        error_string = str(exception)
        result = False

    if not result:
        print("(FAIL)")
    else:
        print("(PASS)")

    if error_string:
        print(error_string)
    return result
Example #7
0
def pysmraw_test_seek_file_object(filename):
    filenames = pysmraw.glob(filename)
    file_objects = []
    for filename in filenames:
        file_object = open(filename, "rb")
        file_objects.append(file_object)

    smraw_handle = pysmraw.handle()

    smraw_handle.open_file_object(file_objects, "r")
    result = pysmraw_test_seek(smraw_handle)
    smraw_handle.close()

    return result
Example #8
0
def pysmraw_test_read_file_object(filename):
    """Tests the read function with a file-like object."""
    smraw_handle = pysmraw.handle()

    filenames = pysmraw.glob(filename)
    file_objects = []
    for filename in filenames:
        file_object = open(filename, "rb")
        file_objects.append(file_object)

    smraw_handle.open_file_objects(file_objects, "r")
    result = pysmraw_test_read(smraw_handle)
    smraw_handle.close()

    return result
def pysmraw_test_single_open_close_file(filename, mode):
  if not filename:
    filename_string = "None"
  else:
    filename_string = filename

  print("Testing single open close of: {0:s} with access: {1:s}\t".format(
      filename_string, get_mode_string(mode)))

  result = True
  try:
    filenames = pysmraw.glob(filename)
    smraw_handle = pysmraw.handle()

    smraw_handle.open(filenames, mode)
    smraw_handle.close()

  except TypeError as exception:
    expected_message = (
        "{0:s}: unsupported string object type.").format(
            "pysmraw_handle_open")

    if not filename and str(exception) == expected_message:
      pass

    else:
      print(str(exception))
      result = False

  except ValueError as exception:
    expected_message = (
        "{0:s}: unsupported mode: w.").format(
            "pysmraw_handle_open")

    if mode != "w" or str(exception) != expected_message:
      print(str(exception))
      result = False

  except Exception as exception:
    print(str(exception))
    result = False

  if not result:
    print("(FAIL)")
  else:
    print("(PASS)")
  return result
def pysmraw_test_multi_open_close_file(filename, mode):
  print("Testing multi open close of: {0:s} with access: {1:s}\t".format(
      filename, get_mode_string(mode)))

  result = True
  try:
    filenames = pysmraw.glob(filename)
    smraw_handle = pysmraw.handle()

    smraw_handle.open(filenames, mode)
    smraw_handle.close()
    smraw_handle.open(filenames, mode)
    smraw_handle.close()

  except Exception as exception:
    print(str(exception))
    result = False

  if not result:
    print("(FAIL)")
  else:
    print("(PASS)")
  return result