dulwich-users team mailing list archive
-
dulwich-users team
-
Mailing list archive
-
Message #00321
Re: [PATCH 25/28] tests/utils: Add builder functions to make C extension tests.
On Thu, 2010-12-02 at 16:22 -0800, dborowitz@xxxxxxxxxx wrote:
> diff --git a/dulwich/tests/utils.py b/dulwich/tests/utils.py
> index 8df2a83..2535e3f 100644
> --- a/dulwich/tests/utils.py
> +++ b/dulwich/tests/utils.py
> @@ -25,12 +25,16 @@ import os
> import shutil
> import tempfile
> import time
> +import types
>
> from dulwich.objects import (
> FixedSha,
> Commit,
> )
> from dulwich.repo import Repo
> +from dulwich.tests import (
> + TestSkipped,
> + )
>
>
> def open_repo(name):
> @@ -105,3 +109,41 @@ def make_commit(**attrs):
> 'tree': '0' * 40}
> all_attrs.update(attrs)
> return make_object(Commit, **all_attrs)
> +
> +
> +def functest_builder(method, func):
> + """Generate a test method that tests the given function."""
> +
> + def do_test(self):
> + method(self, func)
> +
> + return do_test
> +
> +
> +def ext_functest_builder(method, func):
> + """Generate a test method that tests the given extension function.
> +
> + This is intended to generate test methods that test both a pure-Python
> + version and an extension version using common test code. The extension test
> + will raise TestSkipped if the extension is not found.
> +
> + Sample usage:
> +
> + class MyTest(TestCase);
> + def _do_some_test(self, func_impl):
> + self.assertEqual('foo', func_impl())
> +
> + test_foo = functest_builder(_do_some_test, foo_py)
> + test_foo_extension = ext_functest_builder(_do_some_test, _foo_c)
> +
> + :param method: The method to run. It must must two parameters, self and the
> + function implementation to test.
> + :param func: The function implementation to pass to method.
> + """
> +
> + def do_test(self):
> + if not isinstance(func, types.BuiltinFunctionType):
> + raise TestSkipped("%s extension not found", func.func_name)
> + method(self, func)
> +
> + return do_test
I'm not crazy about this pattern, the approach that's used in Bazaar for
this kind of thing is nicer imho. I'll see if I can propose an
alternative.
Cheers,
Jelmer
Attachment:
signature.asc
Description: This is a digitally signed message part
Follow ups
References