Example #1
0
 def test_open_oserror(self, caplog, unwritable_tmp_path, monkeypatch):
     """Test creating a new CACHEDIR.TAG."""
     monkeypatch.setattr(standarddir, 'cache',
                         lambda: str(unwritable_tmp_path))
     with caplog.at_level(logging.ERROR, 'init'):
         standarddir._init_cachedir_tag()
     assert caplog.messages == ['Failed to create CACHEDIR.TAG']
Example #2
0
 def test_open_oserror(self, caplog, tmpdir, mocker, monkeypatch):
     """Test creating a new CACHEDIR.TAG."""
     monkeypatch.setattr(standarddir, 'cache', lambda: str(tmpdir))
     mocker.patch('builtins.open', side_effect=OSError)
     with caplog.at_level(logging.ERROR, 'init'):
         standarddir._init_cachedir_tag()
     assert caplog.messages == ['Failed to create CACHEDIR.TAG']
     assert not tmpdir.listdir()
Example #3
0
 def test_open_oserror(self, caplog, tmpdir, mocker, monkeypatch):
     """Test creating a new CACHEDIR.TAG."""
     monkeypatch.setattr(standarddir, 'cache', lambda: str(tmpdir))
     mocker.patch('builtins.open', side_effect=OSError)
     with caplog.at_level(logging.ERROR, 'init'):
         standarddir._init_cachedir_tag()
     assert caplog.messages == ['Failed to create CACHEDIR.TAG']
     assert not tmpdir.listdir()
Example #4
0
 def test_existent_cache_dir_tag(self, tmpdir, mocker, monkeypatch):
     """Test with an existent CACHEDIR.TAG."""
     monkeypatch.setattr(standarddir, 'cache', lambda: str(tmpdir))
     mocker.patch('builtins.open', side_effect=AssertionError)
     m = mocker.patch('qutebrowser.utils.standarddir.os')
     m.path.join.side_effect = os.path.join
     m.path.exists.return_value = True
     standarddir._init_cachedir_tag()
     assert not tmpdir.listdir()
     m.path.exists.assert_called_with(str(tmpdir / 'CACHEDIR.TAG'))
Example #5
0
 def test_open_oserror(self, caplog, tmpdir, mocker, monkeypatch):
     """Test creating a new CACHEDIR.TAG."""
     monkeypatch.setattr('qutebrowser.utils.standarddir.cache',
                         lambda: str(tmpdir))
     mocker.patch('builtins.open', side_effect=OSError)
     with caplog.at_level(logging.ERROR, 'init'):
         standarddir._init_cachedir_tag()
     assert len(caplog.records) == 1
     assert caplog.records[0].message == 'Failed to create CACHEDIR.TAG'
     assert not tmpdir.listdir()
 def test_open_oserror(self, caplog, tmpdir, mocker, monkeypatch):
     """Test creating a new CACHEDIR.TAG."""
     monkeypatch.setattr('qutebrowser.utils.standarddir.cache',
                         lambda: str(tmpdir))
     mocker.patch('builtins.open', side_effect=OSError)
     with caplog.at_level(logging.ERROR, 'init'):
         standarddir._init_cachedir_tag()
     assert len(caplog.records) == 1
     assert caplog.records[0].message == 'Failed to create CACHEDIR.TAG'
     assert not tmpdir.listdir()
 def test_existent_cache_dir_tag(self, tmpdir, mocker, monkeypatch):
     """Test with an existent CACHEDIR.TAG."""
     monkeypatch.setattr(standarddir, 'cache', lambda: str(tmpdir))
     mocker.patch('builtins.open', side_effect=AssertionError)
     m = mocker.patch('qutebrowser.utils.standarddir.os')
     m.path.join.side_effect = os.path.join
     m.path.exists.return_value = True
     standarddir._init_cachedir_tag()
     assert not tmpdir.listdir()
     m.path.exists.assert_called_with(str(tmpdir / 'CACHEDIR.TAG'))
Example #8
0
 def test_new_cache_dir_tag(self, tmpdir, mocker, monkeypatch):
     """Test creating a new CACHEDIR.TAG."""
     monkeypatch.setattr(standarddir, 'cache', lambda: str(tmpdir))
     standarddir._init_cachedir_tag()
     assert tmpdir.listdir() == [(tmpdir / 'CACHEDIR.TAG')]
     data = (tmpdir / 'CACHEDIR.TAG').read_text('utf-8')
     assert data == textwrap.dedent("""
         Signature: 8a477f597d28d172789f06886806bc55
         # This file is a cache directory tag created by qutebrowser.
         # For information about cache directory tags, see:
         #  http://www.brynosaurus.com/cachedir/
     """).lstrip()
 def test_new_cache_dir_tag(self, tmpdir, mocker, monkeypatch):
     """Test creating a new CACHEDIR.TAG."""
     monkeypatch.setattr(standarddir, 'cache', lambda: str(tmpdir))
     standarddir._init_cachedir_tag()
     assert tmpdir.listdir() == [(tmpdir / 'CACHEDIR.TAG')]
     data = (tmpdir / 'CACHEDIR.TAG').read_text('utf-8')
     assert data == textwrap.dedent("""
         Signature: 8a477f597d28d172789f06886806bc55
         # This file is a cache directory tag created by qutebrowser.
         # For information about cache directory tags, see:
         #  http://www.brynosaurus.com/cachedir/
     """).lstrip()
Example #10
0
 def test_no_cache_dir(self, mocker, monkeypatch):
     """Smoke test with cache() returning None."""
     monkeypatch.setattr('qutebrowser.utils.standarddir.cache',
                         lambda: None)
     mocker.patch('builtins.open', side_effect=AssertionError)
     standarddir._init_cachedir_tag()
 def test_no_cache_dir(self, mocker, monkeypatch):
     """Smoke test with cache() returning None."""
     monkeypatch.setattr('qutebrowser.utils.standarddir.cache',
                         lambda: None)
     mocker.patch('builtins.open', side_effect=AssertionError)
     standarddir._init_cachedir_tag()