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