Ejemplo n.º 1
0
    def test_old(self, mock_backend):
        """backends.write: Ignores files ending in '.old'.

        If this raises a BackendError it means it didn't find a backend to use,
        thus it skipped the file ending in '.old'.
        """
        backends.write(self.results, 'results.test_backend.old')
Ejemplo n.º 2
0
    def test_notimplemented(self, mocker):
        """backends.write(): An error is raised if a writer isn't properly
        implemented.
        """
        mocker.patch.dict(
            backends.BACKENDS,
            {'test_backend': backends.register.Registry(
                extensions=['.test_backend'],
                backend=None,
                load=None,
                meta=None,
                write=None,
            )})

        backends.write(self.results, 'foo.test_backend')
Ejemplo n.º 3
0
    def test_trailing_dot(self, mocker):
        """framework.backends.write: handles the result name ending in '.'.

        Basically if this reaches a BackendNotImplementedError, then the '.'
        was handled correctly, otherwise if it's '.' then we should reach the
        BackendError, which is incorrect.
        """
        mocker.patch.dict(
            backends.BACKENDS,
            {'test_backend': backends.register.Registry(
                extensions=['.test_backend'],
                backend=None,
                load=None,
                meta=None,
                write=None,
            )})

        backends.write(self.results, 'foo.test_backend..gz')
Ejemplo n.º 4
0
def aggregate(input_):
    """Combine files in a tests/ directory into a single results file."""
    unparsed = parsers.parse_config(input_)[1]

    # Adding the parent is necissary to get the help options
    parser = argparse.ArgumentParser(parents=[parsers.CONFIG])
    parser.add_argument('results_folder',
                        type=path.realpath,
                        metavar="<results path>",
                        help="Path to a results directory "
                             "(which contains a tests directory)")
    parser.add_argument('-o', '--output',
                        default="results.json",
                        help="name of output file. Default: results.json")
    args = parser.parse_args(unparsed)

    assert os.path.isdir(args.results_folder)

    # args.results_folder must be a path with a 'tests' directory in it, not
    # the tests directory itself.
    outfile = os.path.join(args.results_folder, args.output)
    try:
        results = backends.load(args.results_folder)
    except backends.BackendError:
        raise exceptions.PiglitFatalError(
            'Cannot find a tests directory to aggregate in {}.\n'
            'Are you you sure that you pointed to '
            'a results directory (not results/tests)?'.format(args.results_folder))

    try:
        use_compression = backends.write(results, outfile)
    except IOError as e:
        if e.errno == errno.EPERM:
            raise exceptions.PiglitFatalError(
                "Unable to write aggregated file, permission denied.")
        raise

    mode = backends.compression.get_mode() if use_compression else 'none'
    comp_ext = '.{}'.format(mode) if mode != 'none' else ''
    print("Aggregated file written to: {}{}".format(outfile, comp_ext))
Ejemplo n.º 5
0
    def test_basic(self, expected, mocker):
        """backends.write: works as expected.

        This is an interesting function to test, because it is just a wrapper
        that returns True or False. So most of the testing should be
        happening in the tests for each backend.

        However, we can test this by injecting a fake backend, and ensuring
        that we get back what we expect. What we do is inject list(), which
        means that we should get back [file_path], instead of just file_path,
        like the legitimate backends return.
        """
        mocker.patch.dict(
            backends.BACKENDS,
            {'test_backend': backends.register.Registry(
                extensions=['.test_backend'],
                backend=None,
                load=None,
                meta=None,
                write=lambda x, _: expected,
            )})

        test = backends.write(self.results, 'foo.test_backend')
        assert expected == test
Ejemplo n.º 6
0
 def test_unknown(self, tmpdir):  # pylint: disable=unused-argument
     backends.write(self.results, 'foo.test_extension')