| 1 |
#!/usr/bin/env python |
| 2 |
# coding=UTF-8 |
| 3 |
|
| 4 |
from os import walk |
| 5 |
|
| 6 |
import mozunit |
| 7 |
import pytest |
| 8 |
from conftest import fspath |
| 9 |
|
| 10 |
|
| 11 |
def test_no_dump_files(check_for_crashes): |
| 12 |
"""Test that check_for_crashes returns 0 if no dumps are present.""" |
| 13 |
assert 0 == check_for_crashes() |
| 14 |
|
| 15 |
|
| 16 |
@pytest.mark.parametrize("minidump_files", [3], indirect=True) |
| 17 |
def test_dump_count(check_for_crashes, minidump_files): |
| 18 |
"""Test that check_for_crashes returns the number of crash dumps.""" |
| 19 |
assert 3 == check_for_crashes() |
| 20 |
|
| 21 |
|
| 22 |
def test_dump_directory_unicode(request, check_for_crashes, tmpdir, capsys): |
| 23 |
"""Test that check_for_crashes can handle unicode in dump_directory.""" |
| 24 |
from conftest import minidump_files |
| 25 |
|
| 26 |
tmpdir = tmpdir.ensure("🍪", dir=1) |
| 27 |
minidump_files = minidump_files(request, tmpdir) |
| 28 |
|
| 29 |
assert 1 == check_for_crashes(dump_directory=fspath(tmpdir), quiet=False) |
| 30 |
|
| 31 |
out, _ = capsys.readouterr() |
| 32 |
assert fspath(minidump_files[0]["dmp"]) in out |
| 33 |
assert "🍪" in out |
| 34 |
|
| 35 |
|
| 36 |
def test_test_name_unicode(check_for_crashes, minidump_files, capsys): |
| 37 |
"""Test that check_for_crashes can handle unicode in dump_directory.""" |
| 38 |
assert 1 == check_for_crashes(test_name="🍪", quiet=False) |
| 39 |
|
| 40 |
out, err = capsys.readouterr() |
| 41 |
assert "| 🍪" in out |
| 42 |
|
| 43 |
|
| 44 |
@pytest.mark.parametrize("keep", [True, False, None]) |
| 45 |
def test_minidump_files_are_cleaned_up_or_preserved_in_original_location( |
| 46 |
request, check_for_crashes, tmpdir, keep |
| 47 |
): |
| 48 |
from conftest import minidump_files |
| 49 |
|
| 50 |
tmpdir = tmpdir.ensure("test", dir=1) |
| 51 |
minidump_files = minidump_files(request, tmpdir) |
| 52 |
|
| 53 |
# Make sure that minidump files are present in the temporary location. |
| 54 |
minidump_files_in_dir = next(walk(tmpdir), (None, None, []))[2] |
| 55 |
assert len(minidump_files_in_dir) == 2 |
| 56 |
|
| 57 |
check_for_crashes(dump_directory=fspath(tmpdir), quiet=False, keep=keep) |
| 58 |
|
| 59 |
# Make sure that minidump files are preserved if keep=True or |
| 60 |
# removed otherwise. |
| 61 |
minidump_files_in_dir = next(walk(tmpdir), (None, None, []))[2] |
| 62 |
assert len(minidump_files_in_dir) == (2 if keep is True else 0) |
| 63 |
|
| 64 |
|
| 65 |
if __name__ == "__main__": |
| 66 |
mozunit.main() |