DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (286cbc3b542b)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
from __future__ import absolute_import

import uuid

import pytest
from py._path.common import fspath

import mozcrash


@pytest.fixture(scope='session')
def stackwalk(tmpdir_factory):
    stackwalk = tmpdir_factory.mktemp('stackwalk_binary').join('stackwalk')
    stackwalk.write('fake binary')
    stackwalk.chmod(0o744)
    return stackwalk


@pytest.fixture
def check_for_crashes(tmpdir, stackwalk, monkeypatch):
    monkeypatch.delenv('MINIDUMP_SAVE_PATH', raising=False)

    def wrapper(dump_directory=fspath(tmpdir),
                symbols_path='symbols_path',
                stackwalk_binary=fspath(stackwalk),
                dump_save_path=None,
                test_name=None,
                quiet=True):
        return mozcrash.check_for_crashes(dump_directory,
                                          symbols_path,
                                          stackwalk_binary,
                                          dump_save_path,
                                          test_name,
                                          quiet)

    return wrapper


@pytest.fixture
def check_for_java_exception():

    def wrapper(logcat=None,
                test_name=None,
                quiet=True):
        return mozcrash.check_for_java_exception(logcat,
                                                 test_name,
                                                 quiet)

    return wrapper


@pytest.fixture
def minidump_files(request, tmpdir):
    files = []

    for i in range(getattr(request, 'param', 1)):
        name = uuid.uuid4()

        dmp = tmpdir.join('{}.dmp'.format(name))
        dmp.write('foo')

        extra = tmpdir.join('{}.extra'.format(name))
        extra.write('bar')

        files.append({'dmp': dmp, 'extra': extra})

    return files


@pytest.fixture(autouse=True)
def mock_popen(monkeypatch):
    """Generate a class that can mock subprocess.Popen.

    :param stdouts: Iterable that should return an iterable for the
                    stdout of each process in turn.
    """
    class MockPopen(object):
        def __init__(self, args, *args_rest, **kwargs):
            # all_popens.append(self)
            self.args = args
            self.returncode = 0

        def communicate(self):
            return (u'Stackwalk command: {}'.format(" ".join(self.args)), "")

        def wait(self):
            return self.returncode

    monkeypatch.setattr(mozcrash.mozcrash.subprocess, 'Popen', MockPopen)