Debian Codegraph @

testing/mozbase/mozcrash/tests/test_save_path.py

raw
1 #!/usr/bin/env python
2
3 import os
4
5 import mozunit
6 import pytest
7 from conftest import fspath
8
9
10 def test_save_path_not_present(check_for_crashes, minidump_files, tmpdir):
11 """Test that dump_save_path works when the directory doesn't exist."""
12 save_path = tmpdir.join("saved")
13
14 assert 1 == check_for_crashes(dump_save_path=fspath(save_path))
15
16 assert save_path.join(minidump_files[0]["dmp"].basename).check()
17 assert save_path.join(minidump_files[0]["extra"].basename).check()
18
19
20 def test_save_path(check_for_crashes, minidump_files, tmpdir):
21 """Test that dump_save_path works."""
22 save_path = tmpdir.mkdir("saved")
23
24 assert 1 == check_for_crashes(dump_save_path=fspath(save_path))
25
26 assert save_path.join(minidump_files[0]["dmp"].basename).check()
27 assert save_path.join(minidump_files[0]["extra"].basename).check()
28
29
30 def test_save_path_isfile(check_for_crashes, minidump_files, tmpdir):
31 """Test that dump_save_path works when the path is a file and not a directory."""
32 save_path = tmpdir.join("saved")
33 save_path.write("junk")
34
35 assert 1 == check_for_crashes(dump_save_path=fspath(save_path))
36
37 assert save_path.join(minidump_files[0]["dmp"].basename).check()
38 assert save_path.join(minidump_files[0]["extra"].basename).check()
39
40
41 def test_save_path_envvar(check_for_crashes, minidump_files, tmpdir):
42 """Test that the MINDUMP_SAVE_PATH environment variable works."""
43 save_path = tmpdir.mkdir("saved")
44
45 os.environ["MINIDUMP_SAVE_PATH"] = fspath(save_path)
46 try:
47 assert 1 == check_for_crashes(dump_save_path=None)
48 finally:
49 del os.environ["MINIDUMP_SAVE_PATH"]
50
51 assert save_path.join(minidump_files[0]["dmp"].basename).check()
52 assert save_path.join(minidump_files[0]["extra"].basename).check()
53
54
55 @pytest.mark.parametrize("minidump_files", [3], indirect=True)
56 def test_save_multiple(check_for_crashes, minidump_files, tmpdir):
57 """Test that all minidumps are saved."""
58 save_path = tmpdir.mkdir("saved")
59
60 assert 3 == check_for_crashes(dump_save_path=fspath(save_path))
61
62 for i in range(3):
63 assert save_path.join(minidump_files[i]["dmp"].basename).check()
64 assert save_path.join(minidump_files[i]["extra"].basename).check()
65
66
67 if __name__ == "__main__":
68 mozunit.main()