Fixed tests.
This commit is contained in:
parent
a6010e3ead
commit
e5779d0775
@ -17,38 +17,33 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
"""Tests for qutebrowser.browser.dirbrowser."""
|
||||
"""Tests for qutebrowser.browser.network.filescheme."""
|
||||
|
||||
import os
|
||||
|
||||
import pytest
|
||||
|
||||
from qutebrowser.browser.network.filescheme import get_file_list
|
||||
|
||||
|
||||
class TestFileList:
|
||||
@pytest.mark.parametrize('create_file, create_dir, filterfunc, expected', [
|
||||
(True, False, os.path.isfile, True),
|
||||
(True, False, os.path.isdir, False),
|
||||
|
||||
"""Test file list."""
|
||||
(False, True, os.path.isfile, False),
|
||||
(False, True, os.path.isdir, True),
|
||||
|
||||
def test_get_file_list(self):
|
||||
"""Test get_file_list."""
|
||||
basedir = os.path.abspath('./qutebrowser/utils')
|
||||
all_files = os.listdir(basedir)
|
||||
result = get_file_list(basedir, all_files, os.path.isfile)
|
||||
assert {'name': 'testfile', 'absname': os.path.join(basedir,
|
||||
'testfile')} in result
|
||||
(False, False, os.path.isfile, False),
|
||||
(False, False, os.path.isdir, False),
|
||||
])
|
||||
def test_get_file_list(tmpdir, create_file, create_dir, filterfunc, expected):
|
||||
"""Test get_file_list."""
|
||||
path = tmpdir / 'foo'
|
||||
if create_file or create_dir:
|
||||
path.ensure(dir=create_dir)
|
||||
|
||||
basedir = os.path.abspath('./qutebrowser/utils')
|
||||
all_files = os.listdir(basedir)
|
||||
result = get_file_list(basedir, all_files, os.path.isdir)
|
||||
print(result)
|
||||
assert {'name': 'testfile', 'absname': os.path.join(basedir,
|
||||
'testfile')} not in result
|
||||
all_files = os.listdir(str(tmpdir))
|
||||
|
||||
basedir = os.path.abspath('./qutebrowser')
|
||||
all_files = os.listdir(basedir)
|
||||
result = get_file_list(basedir, all_files, os.path.isfile)
|
||||
assert ({'name': 'utils', 'absname': os.path.join(basedir, 'utils')}
|
||||
not in result)
|
||||
|
||||
result = get_file_list(basedir, all_files, os.path.isdir)
|
||||
assert ({'name': 'utils', 'absname': os.path.join(basedir, 'utils')}
|
||||
in result)
|
||||
result = get_file_list(str(tmpdir), all_files, filterfunc)
|
||||
item = {'name': 'foo', 'absname': str(path)}
|
||||
assert (item in result) == expected
|
||||
|
@ -92,19 +92,21 @@ class TestEliding:
|
||||
assert utils.elide(text, length) == expected
|
||||
|
||||
|
||||
@pytest.fixture(params=[True, False])
|
||||
def freezer(request, monkeypatch):
|
||||
if request.param and not getattr(sys, 'frozen', False):
|
||||
monkeypatch.setattr(sys, 'frozen', True, raising=False)
|
||||
monkeypatch.setattr('sys.executable', qutebrowser.__file__)
|
||||
elif not request.param and getattr(sys, 'frozen', False):
|
||||
# Want to test unfrozen tests, but we are frozen
|
||||
pytest.skip("Can't run with sys.frozen = True!")
|
||||
|
||||
|
||||
@pytest.mark.usefixtures('freezer')
|
||||
class TestReadFile:
|
||||
|
||||
"""Test read_file."""
|
||||
|
||||
@pytest.fixture(autouse=True, params=[True, False])
|
||||
def freezer(self, request, monkeypatch):
|
||||
if request.param and not getattr(sys, 'frozen', False):
|
||||
monkeypatch.setattr(sys, 'frozen', True, raising=False)
|
||||
monkeypatch.setattr('sys.executable', qutebrowser.__file__)
|
||||
elif not request.param and getattr(sys, 'frozen', False):
|
||||
# Want to test unfrozen tests, but we are frozen
|
||||
pytest.skip("Can't run with sys.frozen = True!")
|
||||
|
||||
def test_readfile(self):
|
||||
"""Read a test file."""
|
||||
content = utils.read_file(os.path.join('utils', 'testfile'))
|
||||
@ -117,6 +119,7 @@ class TestReadFile:
|
||||
assert content.splitlines()[0] == b"Hello World!"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures('freezer')
|
||||
class TestResourceFilename:
|
||||
|
||||
"""Test resource_filename."""
|
||||
@ -133,8 +136,8 @@ class TestResourceFilename:
|
||||
def test_resource_filename(self):
|
||||
"""Read a test file."""
|
||||
filename = utils.resource_filename(os.path.join('utils', 'testfile'))
|
||||
expected = os.path.abspath('./qutebrowser/utils/testfile')
|
||||
assert expected == filename
|
||||
with open(filename, 'r', encoding='utf-8') as f:
|
||||
assert f.read().splitlines()[0] == "Hello World!"
|
||||
|
||||
|
||||
class Patcher:
|
||||
|
Loading…
Reference in New Issue
Block a user