summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2020-11-25 12:13:34 +0100
committerFlorian Bruhin <me@the-compiler.org>2020-11-25 14:07:45 +0100
commit3701aed8fbe8f65ce34a785e4161b85db737a1ab (patch)
treeda031f1d74961c82333e4eceef345329283eef8a
parent8614dbf1cb0b18e37dad11ee5f0da4ae2258b29d (diff)
downloadqutebrowser-3701aed8fbe8f65ce34a785e4161b85db737a1ab.tar.gz
qutebrowser-3701aed8fbe8f65ce34a785e4161b85db737a1ab.zip
tests: Add smoke test for test_mkvenv.py
-rw-r--r--scripts/mkvenv.py46
-rw-r--r--tests/end2end/test_mkvenv.py28
2 files changed, 57 insertions, 17 deletions
diff --git a/scripts/mkvenv.py b/scripts/mkvenv.py
index 19a20b00b..36d4033c7 100644
--- a/scripts/mkvenv.py
+++ b/scripts/mkvenv.py
@@ -38,7 +38,16 @@ from scripts import utils, link_pyqt
REPO_ROOT = pathlib.Path(__file__).parent.parent
-def parse_args() -> argparse.Namespace:
+class Error(Exception):
+
+ """Exception for errors in this script."""
+
+ def __init__(self, msg, code=1):
+ super().__init__(msg)
+ self.code = code
+
+
+def parse_args(argv=None) -> argparse.Namespace:
"""Parse commandline arguments."""
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--keep',
@@ -74,7 +83,7 @@ def parse_args() -> argparse.Namespace:
parser.add_argument('--tox-error',
action='store_true',
help=argparse.SUPPRESS)
- return parser.parse_args()
+ return parser.parse_args(argv)
def pyqt_versions() -> List[str]:
@@ -110,8 +119,7 @@ def run_venv(
stdout=subprocess.PIPE if capture_output else None,
)
except subprocess.CalledProcessError as e:
- utils.print_error("Subprocess failed, exiting")
- sys.exit(e.returncode)
+ raise Error("Subprocess failed, exiting")
def pip_install(venv_dir: pathlib.Path, *args: str) -> None:
@@ -134,9 +142,8 @@ def delete_old_venv(venv_dir: pathlib.Path) -> None:
]
if not any(m.exists() for m in markers):
- utils.print_error('{} does not look like a virtualenv, '
- 'cowardly refusing to remove it.'.format(venv_dir))
- sys.exit(1)
+ raise Error('{} does not look like a virtualenv, cowardly refusing to '
+ 'remove it.'.format(venv_dir))
utils.print_col('$ rm -r {}'.format(venv_dir), 'blue')
shutil.rmtree(str(venv_dir))
@@ -150,8 +157,7 @@ def create_venv(venv_dir: pathlib.Path, use_virtualenv: bool = False) -> None:
subprocess.run([sys.executable, '-m', 'virtualenv', venv_dir],
check=True)
except subprocess.CalledProcessError as e:
- utils.print_error("virtualenv failed, exiting")
- sys.exit(e.returncode)
+ raise Error("virtualenv failed, exiting", e.returncode)
else:
utils.print_col('$ python3 -m venv {}'.format(venv_dir), 'blue')
venv.create(str(venv_dir), with_pip=True)
@@ -318,22 +324,19 @@ def regenerate_docs(venv_dir: pathlib.Path,
run_venv(venv_dir, 'python', str(script_path), *a2h_args)
-def main() -> None:
+def run(args) -> None:
"""Install qutebrowser in a virtualenv.."""
- args = parse_args()
venv_dir = pathlib.Path(args.venv_dir)
wheels_dir = pathlib.Path(args.pyqt_wheels_dir)
utils.change_cwd()
if (args.pyqt_version != 'auto' and
args.pyqt_type not in ['binary', 'source']):
- utils.print_error('The --pyqt-version option is only available when '
- 'installing PyQt from binary or source')
- sys.exit(1)
+ raise Error('The --pyqt-version option is only available when installing PyQt '
+ 'from binary or source')
elif args.pyqt_wheels_dir != 'wheels' and args.pyqt_type != 'wheels':
- utils.print_error('The --pyqt-wheels-dir option is only available '
- 'when installing PyQt from wheels')
- sys.exit(1)
+ raise Error('The --pyqt-wheels-dir option is only available when installing '
+ 'PyQt from wheels')
if not args.keep:
utils.print_title("Creating virtual environment")
@@ -366,5 +369,14 @@ def main() -> None:
regenerate_docs(venv_dir, args.asciidoc)
+def main():
+ args = parse_args()
+ try:
+ run(args)
+ except Error as e:
+ utils.print_error(str(e))
+ sys.exit(e.code)
+
+
if __name__ == '__main__':
main()
diff --git a/tests/end2end/test_mkvenv.py b/tests/end2end/test_mkvenv.py
new file mode 100644
index 000000000..0e42583eb
--- /dev/null
+++ b/tests/end2end/test_mkvenv.py
@@ -0,0 +1,28 @@
+#!/usr/bin/env python3
+# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
+
+# Copyright 2020 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
+
+# This file is part of qutebrowser.
+#
+# qutebrowser is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# qutebrowser is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
+
+
+from scripts import mkvenv
+
+
+def test_smoke(tmp_path):
+ """Simple smoke test of mkvenv.py"""
+ args = mkvenv.parse_args(['--venv-dir', str(tmp_path / 'venv'), '--skip-docs'])
+ mkvenv.run(args)