From be5da7c04bb818ffb654f8e64407a38fb4a27d7e Mon Sep 17 00:00:00 2001 From: Bastian Kleineidam Date: Tue, 26 Mar 2013 21:12:02 +0100 Subject: [PATCH] Run mainline tests only on posix systems where symlinks work. --- tests/__init__.py | 25 +++++++++++++++++++++++++ tests/test_dosage.py | 9 ++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/tests/__init__.py b/tests/__init__.py index 1b171ad88..01dc4e2df 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -15,6 +15,8 @@ # along with this program. If not, see . import os import subprocess +import sys +import pytest basedir = os.path.dirname(__file__) dosage_cmd = os.path.join(os.path.dirname(basedir), "dosage") @@ -37,3 +39,26 @@ def run_checked (cmd, ret_ok=(0,), **kwargs): msg = "Command `%s' returned non-zero exit status %d" % (cmd, retcode) raise OSError(msg) return retcode + + +# Python 3.x renamed the function name attribute +if sys.version_info[0] > 2: + fnameattr = '__name__' +else: + fnameattr = 'func_name' + +def _need_func(testfunc, name, description): + """Decorator skipping test if given testfunc returns False.""" + def check_func(func): + def newfunc(*args, **kwargs): + if not testfunc(name): + raise pytest.skip("%s %r is not available" % (description, name)) + return func(*args, **kwargs) + setattr(newfunc, fnameattr, getattr(func, fnameattr)) + return newfunc + return check_func + + +def needs_os(name): + """Decorator skipping test if given operating system is not available.""" + return _need_func(lambda x: os.name == x, name, 'operating system') diff --git a/tests/test_dosage.py b/tests/test_dosage.py index f999c6fa7..715d15ae4 100644 --- a/tests/test_dosage.py +++ b/tests/test_dosage.py @@ -17,7 +17,7 @@ import unittest import sys import shutil import tempfile -from . import dosage_cmd, mainline_cmd, run_checked +from . import dosage_cmd, mainline_cmd, run_checked, needs_os def run_with_options(options, cmd=dosage_cmd): @@ -39,6 +39,7 @@ class TestDosage (unittest.TestCase): for option in ("-l", "--list", "--singlelist"): run_with_options([option]) + @needs_os('posix') def test_list_comics_mainline(self): for option in ("-l", "--list", "--singlelist"): run_with_options([option], cmd=mainline_cmd) @@ -46,6 +47,7 @@ class TestDosage (unittest.TestCase): def test_version(self): run_with_options(["--version"]) + @needs_os('posix') def test_version_mainline(self): run_with_options(["--version"], cmd=mainline_cmd) @@ -55,6 +57,7 @@ class TestDosage (unittest.TestCase): # module help run_with_options(["-m", "calvinandhobbes"]) + @needs_os('posix') def test_help_mainline(self): for option in ("-h", "--help"): run_with_options([option], cmd=mainline_cmd) @@ -66,6 +69,7 @@ class TestDosage (unittest.TestCase): self.assertRaises(OSError, run_with_options, ['--imadoofus']) self.assertRaises(OSError, run_with_options, ['Garfield']) + @needs_os('posix') def test_error_mainline(self): self.assertRaises(OSError, run_with_options, [], mainline_cmd) self.assertRaises(OSError, run_with_options, ['--imadoofus'], mainline_cmd) @@ -74,17 +78,20 @@ class TestDosage (unittest.TestCase): def test_fetch_html(self): run_with_options(["-n", "2", "-b", self.tmpdir, "-o", "html", "-o", "rss", "calvinandhobbes"]) + @needs_os('posix') def test_fetch_html_mainline(self): run_with_options(["-n", "2", "-b", self.tmpdir, "-o", "html", "-o", "rss", "calvinandhobbes"], cmd=mainline_cmd) def test_fetch_rss(self): run_with_options(["--numstrips", "2", "--baseurl", "bla", "--basepath", self.tmpdir, "--output", "rss", "--output", "html", "--adult", "sexyloser"]) + @needs_os('posix') def test_fetch_rss_mainline(self): run_with_options(["--numstrips", "2", "--baseurl", "bla", "--basepath", self.tmpdir, "--output", "rss", "--output", "html", "--adult", "sexyloser"], cmd=mainline_cmd) def test_fetch_indexed(self): run_with_options(["-n", "2", "-b", self.tmpdir, "calvinandhobbes:2012/02/02"]) + @needs_os('posix') def test_fetch_indexed_mainline(self): run_with_options(["-n", "2", "-b", self.tmpdir, "calvinandhobbes:2012/02/02"], cmd=mainline_cmd)