示例#1
0
def test_utils_history_log_no_input():
    """Test utils history log function raises if no input."""
    with pytest.raises(IpaUtilsException) as error:
        ipa_utils.update_history_log('tests/data/.history')

    assert str(error.value) == \
        'A test log or clear flag must be provided.'
示例#2
0
def test_utils_history_log():
    """Test utils history log function."""
    history_file = NamedTemporaryFile(delete=False)
    history_file.close()

    copyfile('tests/data/.history', history_file.name)

    ipa_utils.update_history_log(history_file.name,
                                 test_log='tests/data/history.log')

    with open(history_file.name, 'r+') as f:
        lines = f.readlines()

    assert lines[-1].strip() == 'tests/data/history.log'

    with ipa_utils.ignored(OSError):
        os.remove(history_file.name)
示例#3
0
def archive_history_item(item, destination, no_color):
    """
    Archive the log and results file for the given history item.

    Copy the files and update the results file in destination directory.
    """
    log_src, description = split_history_item(item.strip())

    # Get relative path for log:
    # {provider}/{image}/{instance}/{timestamp}.log
    log_dest = os.path.sep.join(log_src.rsplit(os.path.sep, 4)[1:])

    # Get results src and destination based on log paths.
    results_src = log_src.rsplit('.', 1)[0] + '.results'
    results_dest = log_dest.rsplit('.', 1)[0] + '.results'

    destination_path = os.path.join(destination, log_dest)
    log_dir = os.path.dirname(destination_path)

    try:
        if not os.path.isdir(log_dir):
            os.makedirs(log_dir)

        # Copy results and log files to archive directory.
        shutil.copyfile(log_src, destination_path)
        shutil.copyfile(results_src, os.path.join(destination, results_dest))
    except Exception as error:
        echo_style(
            'Unable to archive history item: %s' % error,
            no_color,
            fg='red'
        )
        sys.exit(1)
    else:
        # Only update the archive results log if no error occur.
        update_history_log(
            os.path.join(destination, '.history'),
            description=description,
            test_log=log_dest
        )
示例#4
0
 def _update_history(self):
     """Save the current test information to history json."""
     ipa_utils.update_history_log(self.history_log,
                                  description=self.description,
                                  test_log=self.log_file)
示例#5
0
def clear(context):
    """
    Clear the results from the history file.
    """
    ipa_utils.update_history_log(context.obj['history_log'], clear=True)