Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testsuite: allow sharing code between is_bar and _test_bar methods #12920

Open
nthiery opened this issue May 7, 2012 · 6 comments
Open

Testsuite: allow sharing code between is_bar and _test_bar methods #12920

nthiery opened this issue May 7, 2012 · 6 comments

Comments

@nthiery
Copy link
Contributor

nthiery commented May 7, 2012

is_method / _test_from_is_method: method wrappers to factor out code between is_bar and _test_bar methods

From the documentation:

The typical usecase for those wrappers is as follow: Consider a
category Foo with a subcategory Bar. Foo wants to
provide a method Foo.ParentMethods.is_bar such that, for F
in Foo(), F.is_bar() returns whether F satisfies all
the properties of Bar(). The method is_bar is allowed to
assume that F indeed satisfies all the properties specified by
Foo(). It may decide to upgrade the category of F to
Bar().

Bar itself wants to provide a method
Bar.ParentMethod._test_bar which is supposed to do some
reasonable sanity checks on F to determine whether it
satisfies all the properties of Bar. If yes, F._test_bla()
should return None; otherwise it should raise some (hopefully
meaningful) assertion. Note that Bar() will typically
override is_bar by a trivial method that always returns
True.

The purpose of two decorators is_method and
_test_method_from_is is to factor out the logic between the two
related methods F.is_bla() and F._test_bla(). They take as
input a Python function is_bla(self, proof=False, **options).
This function should proceed as usual for a _test method (see
:class:TestSuite). If proof is True, then the answer
should be provably correct. At the end, is_bla should return
None, or a category that will be used to refine the category
of F.

CC: @sagetrac-sage-combinat

Component: misc

Keywords: days38

Author: Nicolas M. Thiéry

Reviewer: Franco Saliola

Issue created by migration from https://trac.sagemath.org/ticket/12920

@nthiery nthiery added this to the sage-5.11 milestone May 7, 2012
@nthiery

This comment has been minimized.

@nthiery

This comment has been minimized.

@nthiery
Copy link
Contributor Author

nthiery commented May 7, 2012

Changed keywords from none to days38

@nthiery

This comment has been minimized.

@roed314
Copy link
Contributor

roed314 commented Mar 28, 2013

comment:5

Attachment: trac_12920-is_test_methods-nt.patch.gz

@videlec
Copy link
Contributor

videlec commented Jul 9, 2013

comment:6

Needs to rebase on 5-11.beta3 (reject on unittest.py).

The patch may definitely be useful. There are two things that I dislike.

  1. When you add the decorator the code does not correspond anymore to a is_X method (it does not return a boolean but raise an error or return a refined category). In other words, it is unreadable. Moreover, when you want to access the documentation (reusing your example)
sage: F = FiniteUnion([GF(2), GF(3)])
sage: F.is_finite?

you get something that you do not want to see here.

  1. the speed
sage: %timeit F.is_finite()
10000 loops, best of 3: 27.2 us per loop

just to compare

sage: class P:
....:     def is_finite(self):
....:         return True
sage: p = P()
sage: %timeit p.is_finite()
1000000 loops, best of 3: 218 ns per loop

which is how is_finite should be implemented for a finite set.

@jdemeyer jdemeyer modified the milestones: sage-5.11, sage-5.12 Aug 13, 2013
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.1, sage-6.2 Jan 30, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.2, sage-6.3 May 6, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.3, sage-6.4 Aug 10, 2014
@jdemeyer jdemeyer changed the title Decorators for sharing code between is_bar and _test_bar methods. Testsuite: allow sharing code between is_bar and _test_bar methods Jan 24, 2017
@jdemeyer jdemeyer modified the milestones: sage-6.4, sage-7.6 Jan 24, 2017
@mkoeppe mkoeppe removed this from the sage-7.6 milestone Dec 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants