tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_save_path.py (2244B)


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